-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.T-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
Consider this program:
trait T {
type X;
const X: Self::X;
}
fn foo<X: T>() {
let _: X::X = X::X;
}
I believe it should compile OK, but currently (Rust 1.20) it fails to compile with a wrong error message:
Error
Compiling example_project v0.1.0 (file:///home/matklad/projects/intellij-rust/exampleProject)
error[E0599]: no associated item named `X` found for type `X` in the current scope
--> src/main.rs:6:19
|
6 | let _: X::X = X::X;
| ^^^^
|
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: candidate #1 is defined in the trait `T`
--> src/main.rs:2:5
|
2 | type X;
| ^^^^^^^
= help: to disambiguate the method call, write `T::X(...)` instead
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `X`, perhaps you need to implement it:
candidate #1: `T`
error: aborting due to previous error
error: Could not compile `example_project`.
To learn more, run the command again with --verbose.
For comparison, the following program builds just fine:
mod X {
pub type X = i32;
pub const X: self::X = 0;
}
fn foo() {
let _: X::X = X::X;
}
kennytm and scottmcm
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.T-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.