Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to const trait methods in const functions no longer allowed #114808

Closed
matthieu-m opened this issue Aug 14, 2023 · 5 comments
Closed

Call to const trait methods in const functions no longer allowed #114808

matthieu-m opened this issue Aug 14, 2023 · 5 comments
Assignees
Labels
C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@matthieu-m
Copy link
Contributor

Code

I tried this code:

#![feature(const_trait_impl)]

#[const_trait]
trait Foo {
    fn foo(&self) -> i32;
}

struct X;

impl const Foo for X {
    fn foo(&self) -> i32 { 4 }
}

const fn call_foo<F>(x: &F) -> i32
where
    F: ~const Foo,
{
    x.foo()
}

Version it worked on

It compiled successfully on nightly 2023-07-31, it may succeed on later versions.

Version with regression

It failed to compile on nightly 2023-08-13 with:

error[[E0015]](https://doc.rust-lang.org/nightly/error_codes/E0015.html): cannot call non-const fn `<F as Foo>::foo` in constant functions
  --> src/lib.rs:18:7
   |
18 |     x.foo()
   |       ^^^^^
   |
   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
@matthieu-m matthieu-m added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Aug 14, 2023
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 14, 2023
@lcnr lcnr added requires-nightly This issue requires a nightly compiler in some way. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 14, 2023
@fee1-dead fee1-dead self-assigned this Aug 14, 2023
@fee1-dead fee1-dead added the F-const_trait_impl `#![feature(const_trait_impl)]` label Aug 14, 2023
@fee1-dead
Copy link
Member

See #110395. This issue is known and will be fixed once the effects rewrite is ready. Closing this issue as duplicate.

@fee1-dead fee1-dead closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2023
@fee1-dead fee1-dead removed regression-untriaged Untriaged performance or correctness regression. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 14, 2023
@matthieu-m
Copy link
Contributor Author

I saw #114677 which was quite similar.

Unfortunately, unlike it, adding #![feature(effects)] does not fix the failure in this case.

I'll hold on upgrading nightly for now, good luck with the rewrite!

@fee1-dead
Copy link
Member

Yep, this will be fixed in feature(effects) after #114781 is merged.

@matthieu-m
Copy link
Contributor Author

Yep, this will be fixed in feature(effects) after #114781 is merged.

@fee1-dead

So... the above PR was merged two weeks ago, and yet as of 1.74.0-nightly (2023-08-26 69e97df) the code still fails to compile: see https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4b29f98e3e645d4e5b51fc8ad0320901.

Should this issue be reopened?

@fee1-dead
Copy link
Member

You are supposed to enable the effects feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

4 participants