Open
Description
Consider the following code (both on stable 1.39.0 and nightly)
trait Const {
const A: i32 = Self::B;
const B: i32 = Self::A;
const C: i32 = Self::A;
}
impl <T> Const for T {}
pub fn main() -> () {
dbg!(i32::C);
}
There's a cycle evaluating the constants C -> A -> B -> A -> ...
The dbg!(i32::C)
line is the offending code which causes this cycle to be evaluated.
However, the emitted error message doesn't actually reference the usage dbg!(i32::C)
which caused the evaluation, as below:
Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when const-evaluating `Const::A`
--> src/main.rs:4:24
|
4 | const A: i32 = Self::B;
| ^^^^^^^
|
note: ...which requires const-evaluating `Const::B`...
--> src/main.rs:5:24
|
5 | const B: i32 = Self::A;
| ^^^^^^^
= note: ...which again requires const-evaluating `Const::A`, completing the cycle
note: cycle used when const-evaluating `Const::C`
--> src/main.rs:6:24
|
6 | const C: i32 = Self::A;
| ^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
This error could probably be improved by having an additional note:
showing that the cycle was used when evaluating dbg!(i32::C)
.
cc @oli-obk