Terse diagnostic on lack of ~const bound in inherent associated const functions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
When a trait is used as a bounds to a generic inherent implementation, and that inherent implementation defines a const function, methods from that bounding trait are not being handled as const inside that definition.
I tried this code:
#![feature(const_trait_impl)]
#[const_trait]
trait Foo {
fn bar(&self) -> u16;
}
struct Baz<F: Foo>(F, u16);
impl<F: Foo> Baz<F> {
const fn bat(f: F) -> u16 { f.bar() }
}
I expected to see this happen: The code would compile and use the const bar() method implemented on F.
Instead, this happened: The compiler yields the error:
error[E0277]: the trait bound `F: ~const Foo` is not satisfied
--> file.rs:11:30
|
11 | const fn bat(f: F) -> u16 { f.bar() }
| ^^^^^^^
Meta
This was tested on rustc 1.81.0-nightly (6b0f4b5ec 2024-06-24).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the provided file.rs reproducer with the nightly toolchain version noted in the issue and compare the diagnostic with the expected const behavior. Done means the compiler either accepts the const call using the trait bound or reports the missing ~const Foo requirement with a clear diagnostic consistent with the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100