-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`PG-const-traitsProject group: Const traitsProject group: Const traitsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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 (6b0f4b5 2024-06-24).
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`PG-const-traitsProject group: Const traitsProject group: Const traitsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.