Skip to content

Commit 878e928

Browse files
authored
Rollup merge of #71657 - Daniel-Worrall:24949, r=estebank
Add #24949 assoc constant static recursion test Closes #24949 Forced tidy fixes
2 parents 4955c05 + e91c3a1 commit 878e928

6 files changed

+179
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Check for recursion involving references to impl-associated const.
2+
3+
trait Foo {
4+
const BAR: u32;
5+
}
6+
7+
const IMPL_REF_BAR: u32 = GlobalImplRef::BAR; //~ ERROR E0391
8+
9+
struct GlobalImplRef;
10+
11+
impl GlobalImplRef {
12+
const BAR: u32 = IMPL_REF_BAR;
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0391]: cycle detected when const-evaluating + checking `IMPL_REF_BAR`
2+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
3+
|
4+
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: ...which requires const-evaluating + checking `IMPL_REF_BAR`...
8+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
9+
|
10+
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
note: ...which requires const-evaluating `IMPL_REF_BAR`...
13+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
14+
|
15+
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: ...which requires normalizing `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
18+
note: ...which requires const-evaluating + checking `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
19+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
20+
|
21+
LL | const BAR: u32 = IMPL_REF_BAR;
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
note: ...which requires const-evaluating + checking `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
24+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
25+
|
26+
LL | const BAR: u32 = IMPL_REF_BAR;
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
note: ...which requires const-evaluating `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
29+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
30+
|
31+
LL | const BAR: u32 = IMPL_REF_BAR;
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
note: ...which requires processing `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`...
34+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
35+
|
36+
LL | const BAR: u32 = IMPL_REF_BAR;
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
= note: ...which requires normalizing `IMPL_REF_BAR`...
39+
= note: ...which again requires const-evaluating + checking `IMPL_REF_BAR`, completing the cycle
40+
= note: cycle used when running analysis passes on this crate
41+
42+
error: aborting due to previous error
43+
44+
For more information about this error, try `rustc --explain E0391`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check for recursion involving references to trait-associated const default.
2+
3+
trait Foo {
4+
const BAR: u32;
5+
}
6+
7+
trait FooDefault {
8+
const BAR: u32 = DEFAULT_REF_BAR;
9+
}
10+
11+
const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR; //~ ERROR E0391
12+
13+
struct GlobalDefaultRef;
14+
15+
impl FooDefault for GlobalDefaultRef {}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0391]: cycle detected when const-evaluating + checking `DEFAULT_REF_BAR`
2+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1
3+
|
4+
LL | const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: ...which requires const-evaluating + checking `DEFAULT_REF_BAR`...
8+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1
9+
|
10+
LL | const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
note: ...which requires const-evaluating `DEFAULT_REF_BAR`...
13+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1
14+
|
15+
LL | const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: ...which requires normalizing `<GlobalDefaultRef as FooDefault>::BAR`...
18+
note: ...which requires const-evaluating + checking `FooDefault::BAR`...
19+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
20+
|
21+
LL | const BAR: u32 = DEFAULT_REF_BAR;
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
note: ...which requires const-evaluating + checking `FooDefault::BAR`...
24+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
25+
|
26+
LL | const BAR: u32 = DEFAULT_REF_BAR;
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
note: ...which requires const-evaluating `FooDefault::BAR`...
29+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
30+
|
31+
LL | const BAR: u32 = DEFAULT_REF_BAR;
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
note: ...which requires processing `FooDefault::BAR`...
34+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
35+
|
36+
LL | const BAR: u32 = DEFAULT_REF_BAR;
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
= note: ...which requires normalizing `DEFAULT_REF_BAR`...
39+
= note: ...which again requires const-evaluating + checking `DEFAULT_REF_BAR`, completing the cycle
40+
= note: cycle used when running analysis passes on this crate
41+
42+
error: aborting due to previous error
43+
44+
For more information about this error, try `rustc --explain E0391`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Check for recursion involving references to trait-associated const.
2+
3+
trait Foo {
4+
const BAR: u32;
5+
}
6+
7+
const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR; //~ ERROR E0391
8+
9+
struct GlobalTraitRef;
10+
11+
impl Foo for GlobalTraitRef {
12+
const BAR: u32 = TRAIT_REF_BAR;
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0391]: cycle detected when const-evaluating + checking `TRAIT_REF_BAR`
2+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
3+
|
4+
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: ...which requires const-evaluating + checking `TRAIT_REF_BAR`...
8+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
9+
|
10+
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
note: ...which requires const-evaluating `TRAIT_REF_BAR`...
13+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
14+
|
15+
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: ...which requires normalizing `<GlobalTraitRef as Foo>::BAR`...
18+
note: ...which requires const-evaluating + checking `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`...
19+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
20+
|
21+
LL | const BAR: u32 = TRAIT_REF_BAR;
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
note: ...which requires const-evaluating + checking `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`...
24+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
25+
|
26+
LL | const BAR: u32 = TRAIT_REF_BAR;
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
note: ...which requires const-evaluating `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`...
29+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
30+
|
31+
LL | const BAR: u32 = TRAIT_REF_BAR;
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
note: ...which requires processing `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`...
34+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
35+
|
36+
LL | const BAR: u32 = TRAIT_REF_BAR;
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
= note: ...which requires normalizing `TRAIT_REF_BAR`...
39+
= note: ...which again requires const-evaluating + checking `TRAIT_REF_BAR`, completing the cycle
40+
= note: cycle used when running analysis passes on this crate
41+
42+
error: aborting due to previous error
43+
44+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)