Skip to content

Commit 6c4d5d9

Browse files
committed
improve normalize cycle error
1 parent d7ecc8c commit 6c4d5d9

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ rustc_queries! {
11171117
query normalize_generic_arg_after_erasing_regions(
11181118
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
11191119
) -> GenericArg<'tcx> {
1120-
desc { "normalizing `{:?}`", goal }
1120+
desc { "normalizing `{}`", goal.value }
11211121
}
11221122

11231123
query implied_outlives_bounds(

src/librustc/ty/normalize_erasing_regions.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,12 @@ impl TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> {
9494
}
9595

9696
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
97-
self.tcx
98-
.normalize_generic_arg_after_erasing_regions(self.param_env.and(ty.into()))
99-
.expect_ty()
97+
let arg = self.param_env.and(ty.into());
98+
self.tcx.normalize_generic_arg_after_erasing_regions(arg).expect_ty()
10099
}
101100

102101
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
103-
self.tcx
104-
.normalize_generic_arg_after_erasing_regions(self.param_env.and(c.into()))
105-
.expect_const()
102+
let arg = self.param_env.and(c.into());
103+
self.tcx.normalize_generic_arg_after_erasing_regions(arg).expect_const()
106104
}
107105
}

src/test/ui/associated-const/defaults-cyclic-fail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// build-fail
2+
//~^ ERROR cycle detected when normalizing `<() as Tr>::A`
23

34
// Cyclic assoc. const defaults don't error unless *used*
45
trait Tr {
56
const A: u8 = Self::B;
6-
//~^ ERROR cycle detected when const-evaluating + checking `Tr::A`
77

88
const B: u8 = Self::A;
99
}

src/test/ui/associated-const/defaults-cyclic-fail.stderr

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
1-
error[E0391]: cycle detected when const-evaluating + checking `Tr::A`
2-
--> $DIR/defaults-cyclic-fail.rs:5:5
1+
error[E0391]: cycle detected when normalizing `<() as Tr>::A`
2+
|
3+
note: ...which requires const-evaluating + checking `Tr::A`...
4+
--> $DIR/defaults-cyclic-fail.rs:6:5
35
|
46
LL | const A: u8 = Self::B;
57
| ^^^^^^^^^^^^^^^^^^^^^^
8+
note: ...which requires const-evaluating + checking `Tr::A`...
9+
--> $DIR/defaults-cyclic-fail.rs:6:5
610
|
11+
LL | const A: u8 = Self::B;
12+
| ^^^^^^^^^^^^^^^^^^^^^^
713
note: ...which requires const-evaluating `Tr::A`...
8-
--> $DIR/defaults-cyclic-fail.rs:5:19
14+
--> $DIR/defaults-cyclic-fail.rs:6:5
915
|
1016
LL | const A: u8 = Self::B;
11-
| ^^^^^^^
17+
| ^^^^^^^^^^^^^^^^^^^^^^
18+
= note: ...which requires normalizing `<() as Tr>::B`...
19+
note: ...which requires const-evaluating + checking `Tr::B`...
20+
--> $DIR/defaults-cyclic-fail.rs:8:5
21+
|
22+
LL | const B: u8 = Self::A;
23+
| ^^^^^^^^^^^^^^^^^^^^^^
1224
note: ...which requires const-evaluating + checking `Tr::B`...
1325
--> $DIR/defaults-cyclic-fail.rs:8:5
1426
|
1527
LL | const B: u8 = Self::A;
1628
| ^^^^^^^^^^^^^^^^^^^^^^
1729
note: ...which requires const-evaluating `Tr::B`...
18-
--> $DIR/defaults-cyclic-fail.rs:8:19
30+
--> $DIR/defaults-cyclic-fail.rs:8:5
1931
|
2032
LL | const B: u8 = Self::A;
21-
| ^^^^^^^
22-
= note: ...which again requires const-evaluating + checking `Tr::A`, completing the cycle
33+
| ^^^^^^^^^^^^^^^^^^^^^^
34+
= note: ...which again requires normalizing `<() as Tr>::A`, completing the cycle
2335
note: cycle used when const-evaluating `main`
24-
--> $DIR/defaults-cyclic-fail.rs:16:16
36+
--> $DIR/defaults-cyclic-fail.rs:14:1
2537
|
26-
LL | assert_eq!(<() as Tr>::A, 0);
27-
| ^^^^^^^^^^^^^
38+
LL | fn main() {
39+
| ^^^^^^^^^
2840

2941
error: aborting due to previous error
3042

src/test/ui/consts/const-size_of-cycle.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ note: ...which requires const-evaluating + checking `std::intrinsics::size_of`..
2525
LL | pub fn size_of<T>() -> usize;
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727
= note: ...which requires computing layout of `Foo`...
28-
= note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: [u8; _] }`...
28+
= note: ...which requires normalizing `[u8; _]`...
2929
= note: ...which again requires const-evaluating + checking `Foo::bytes::{{constant}}#0`, completing the cycle
3030
note: cycle used when processing `Foo`
3131
--> $DIR/const-size_of-cycle.rs:7:1

0 commit comments

Comments
 (0)