Skip to content

Commit 488c25a

Browse files
committed
Auto merge of rust-lang#119821 - oli-obk:reveal_all_const_evals, r=<try>
Always use RevealAll for const eval queries implements what is described in rust-lang#116803 (comment)
2 parents e927184 + e673a9e commit 488c25a

18 files changed

+49
-100
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
226226
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
227227
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
228228
// see comment in eval_to_allocation_raw_provider for what we're doing here
229-
if key.param_env.reveal() == Reveal::All {
230-
let mut key = key;
231-
key.param_env = key.param_env.with_user_facing();
232-
match tcx.eval_to_const_value_raw(key) {
233-
// try again with reveal all as requested
234-
Err(ErrorHandled::TooGeneric(_)) => {}
235-
// deduplicate calls
236-
other => return other,
237-
}
238-
}
229+
assert_eq!(key.param_env.reveal(), Reveal::All);
239230

240231
// We call `const_eval` for zero arg intrinsics, too, in order to cache their value.
241232
// Catch such calls and evaluate them instead of trying to load a constant's MIR.
@@ -272,17 +263,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
272263
// associated constants of generic functions will fail due to not enough monomorphization
273264
// information being available.
274265

275-
// In case we fail in the `UserFacing` variant, we just do the real computation.
276-
if key.param_env.reveal() == Reveal::All {
277-
let mut key = key;
278-
key.param_env = key.param_env.with_user_facing();
279-
match tcx.eval_to_allocation_raw(key) {
280-
// try again with reveal all as requested
281-
Err(ErrorHandled::TooGeneric(_)) => {}
282-
// deduplicate calls
283-
other => return other,
284-
}
285-
}
266+
assert_eq!(key.param_env.reveal(), Reveal::All);
286267
if cfg!(debug_assertions) {
287268
// Make sure we format the instance even if we do not print it.
288269
// This serves as a regression test against an ICE on printing.

compiler/rustc_middle/src/mir/interpret/queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'tcx> TyCtxt<'tcx> {
145145
) -> EvalToConstValueResult<'tcx> {
146146
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
147147
// improve caching of queries.
148-
let inputs = self.erase_regions(param_env.and(cid));
148+
let inputs = self.erase_regions(param_env.with_reveal_all_normalized(self).and(cid));
149149
if let Some(span) = span {
150150
// The query doesn't know where it is being invoked, so we need to fix the span.
151151
self.at(span).eval_to_const_value_raw(inputs).map_err(|e| e.with_span(span))
@@ -164,7 +164,7 @@ impl<'tcx> TyCtxt<'tcx> {
164164
) -> EvalToValTreeResult<'tcx> {
165165
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
166166
// improve caching of queries.
167-
let inputs = self.erase_regions(param_env.and(cid));
167+
let inputs = self.erase_regions(param_env.with_reveal_all_normalized(self).and(cid));
168168
debug!(?inputs);
169169
if let Some(span) = span {
170170
// The query doesn't know where it is being invoked, so we need to fix the span.

tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ note: ...which requires simplifying constant for the type system `IMPL_REF_BAR`.
99
|
1010
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires simplifying constant for the type system `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-
| ^^^^^^^^^^^^^^^^^^^^^^^
1712
note: ...which requires const-evaluating + checking `IMPL_REF_BAR`...
1813
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:27
1914
|

tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ note: ...which requires simplifying constant for the type system `DEFAULT_REF_BA
99
|
1010
LL | const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires simplifying constant for the type system `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-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1712
note: ...which requires const-evaluating + checking `DEFAULT_REF_BAR`...
1813
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:30
1914
|

tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ note: ...which requires simplifying constant for the type system `TRAIT_REF_BAR`
99
|
1010
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires simplifying constant for the type system `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-
| ^^^^^^^^^^^^^^^^^^^^^^^^
1712
note: ...which requires const-evaluating + checking `TRAIT_REF_BAR`...
1813
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:28
1914
|

tests/ui/consts/const-eval/const-eval-query-stack.stderr

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | const X: i32 = 1 / 0;
77
query stack during panic:
88
#0 [eval_to_allocation_raw] const-evaluating + checking `X`
99
#1 [eval_to_const_value_raw] simplifying constant for the type system `X`
10-
#2 [eval_to_const_value_raw] simplifying constant for the type system `X`
11-
#3 [lint_mod] linting top-level module
12-
#4 [analysis] running analysis passes on this crate
10+
#2 [lint_mod] linting top-level module
11+
#3 [analysis] running analysis passes on this crate
1312
end of query stack

tests/ui/consts/const-size_of-cycle.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ LL | bytes: [u8; std::mem::size_of::<Foo>()]
77
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
88
--> $DIR/const-size_of-cycle.rs:4:17
99
|
10-
LL | bytes: [u8; std::mem::size_of::<Foo>()]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
13-
--> $DIR/const-size_of-cycle.rs:4:17
14-
|
1510
LL | bytes: [u8; std::mem::size_of::<Foo>()]
1611
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1712
= note: ...which requires computing layout of `Foo`...

tests/ui/consts/issue-36163.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ note: ...which requires const-evaluating + checking `A`...
2020
LL | const A: isize = Foo::B as isize;
2121
| ^^^^^^^^^^^^^^^
2222
= note: ...which again requires simplifying constant for the type system `Foo::B::{constant#0}`, completing the cycle
23-
note: cycle used when simplifying constant for the type system `Foo::B::{constant#0}`
24-
--> $DIR/issue-36163.rs:4:9
23+
note: cycle used when collecting item types in top-level module
24+
--> $DIR/issue-36163.rs:1:1
2525
|
26-
LL | B = A,
27-
| ^
26+
LL | / const A: isize = Foo::B as isize;
27+
LL | |
28+
LL | | enum Foo {
29+
LL | | B = A,
30+
LL | | }
31+
LL | |
32+
LL | | fn main() {}
33+
| |____________^
2834
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
2935

3036
error: aborting due to 1 previous error

tests/ui/consts/issue-44415.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
77
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
88
--> $DIR/issue-44415.rs:6:17
99
|
10-
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
13-
--> $DIR/issue-44415.rs:6:17
14-
|
1510
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
1611
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1712
= note: ...which requires computing layout of `Foo`...

tests/ui/consts/recursive-zst-static.default.stderr

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
error[E0391]: cycle detected when const-evaluating + checking `FOO`
2-
--> $DIR/recursive-zst-static.rs:10:1
3-
|
4-
LL | static FOO: () = FOO;
5-
| ^^^^^^^^^^^^^^
6-
|
7-
note: ...which requires const-evaluating + checking `FOO`...
82
--> $DIR/recursive-zst-static.rs:10:18
93
|
104
LL | static FOO: () = FOO;
115
| ^^^
12-
= note: ...which again requires const-evaluating + checking `FOO`, completing the cycle
6+
|
7+
= note: ...which immediately requires const-evaluating + checking `FOO` again
138
note: cycle used when linting top-level module
149
--> $DIR/recursive-zst-static.rs:10:1
1510
|

tests/ui/consts/recursive-zst-static.unleash.stderr

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
error[E0391]: cycle detected when const-evaluating + checking `FOO`
2-
--> $DIR/recursive-zst-static.rs:10:1
3-
|
4-
LL | static FOO: () = FOO;
5-
| ^^^^^^^^^^^^^^
6-
|
7-
note: ...which requires const-evaluating + checking `FOO`...
82
--> $DIR/recursive-zst-static.rs:10:18
93
|
104
LL | static FOO: () = FOO;
115
| ^^^
12-
= note: ...which again requires const-evaluating + checking `FOO`, completing the cycle
6+
|
7+
= note: ...which immediately requires const-evaluating + checking `FOO` again
138
note: cycle used when linting top-level module
149
--> $DIR/recursive-zst-static.rs:10:1
1510
|

tests/ui/consts/write-to-static-mut-in-static.stderr

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ LL | pub static mut B: () = unsafe { A = 1; };
55
| ^^^^^ modifying a static's initial value from another static's initializer
66

77
error[E0391]: cycle detected when const-evaluating + checking `C`
8-
--> $DIR/write-to-static-mut-in-static.rs:5:1
9-
|
10-
LL | pub static mut C: u32 = unsafe { C = 1; 0 };
11-
| ^^^^^^^^^^^^^^^^^^^^^
12-
|
13-
note: ...which requires const-evaluating + checking `C`...
148
--> $DIR/write-to-static-mut-in-static.rs:5:34
159
|
1610
LL | pub static mut C: u32 = unsafe { C = 1; 0 };
1711
| ^^^^^
18-
= note: ...which again requires const-evaluating + checking `C`, completing the cycle
12+
|
13+
= note: ...which immediately requires const-evaluating + checking `C` again
1914
note: cycle used when linting top-level module
2015
--> $DIR/write-to-static-mut-in-static.rs:1:1
2116
|

tests/ui/issues/issue-23302-1.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ note: ...which requires const-evaluating + checking `X::A::{constant#0}`...
1010
LL | A = X::A as isize,
1111
| ^^^^^^^^^^^^^
1212
= note: ...which again requires simplifying constant for the type system `X::A::{constant#0}`, completing the cycle
13-
note: cycle used when simplifying constant for the type system `X::A::{constant#0}`
14-
--> $DIR/issue-23302-1.rs:4:9
13+
note: cycle used when collecting item types in top-level module
14+
--> $DIR/issue-23302-1.rs:3:1
1515
|
16-
LL | A = X::A as isize,
17-
| ^^^^^^^^^^^^^
16+
LL | / enum X {
17+
LL | | A = X::A as isize,
18+
LL | | }
19+
LL | |
20+
LL | | fn main() { }
21+
| |_____________^
1822
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
1923

2024
error: aborting due to 1 previous error

tests/ui/issues/issue-23302-2.stderr

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ note: ...which requires const-evaluating + checking `Y::A::{constant#0}`...
1010
LL | A = Y::B as isize,
1111
| ^^^^^^^^^^^^^
1212
= note: ...which again requires simplifying constant for the type system `Y::A::{constant#0}`, completing the cycle
13-
note: cycle used when simplifying constant for the type system `Y::A::{constant#0}`
14-
--> $DIR/issue-23302-2.rs:4:9
13+
note: cycle used when collecting item types in top-level module
14+
--> $DIR/issue-23302-2.rs:3:1
1515
|
16-
LL | A = Y::B as isize,
17-
| ^^^^^^^^^^^^^
16+
LL | / enum Y {
17+
LL | | A = Y::B as isize,
18+
LL | | B,
19+
LL | | }
20+
LL | |
21+
LL | | fn main() { }
22+
| |_____________^
1823
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
1924

2025
error: aborting due to 1 previous error

tests/ui/issues/issue-23302-3.stderr

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ note: ...which requires const-evaluating + checking `B`...
2020
LL | const B: i32 = A;
2121
| ^
2222
= note: ...which again requires simplifying constant for the type system `A`, completing the cycle
23-
note: cycle used when simplifying constant for the type system `A`
23+
note: cycle used when linting top-level module
2424
--> $DIR/issue-23302-3.rs:1:1
2525
|
26-
LL | const A: i32 = B;
27-
| ^^^^^^^^^^^^
26+
LL | / const A: i32 = B;
27+
LL | |
28+
LL | | const B: i32 = A;
29+
LL | |
30+
LL | | fn main() { }
31+
| |_____________^
2832
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
2933

3034
error: aborting due to 1 previous error

tests/ui/recursion/recursive-static-definition.stderr

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
error[E0391]: cycle detected when const-evaluating + checking `FOO`
2-
--> $DIR/recursive-static-definition.rs:1:1
3-
|
4-
LL | pub static FOO: u32 = FOO;
5-
| ^^^^^^^^^^^^^^^^^^^
6-
|
7-
note: ...which requires const-evaluating + checking `FOO`...
82
--> $DIR/recursive-static-definition.rs:1:23
93
|
104
LL | pub static FOO: u32 = FOO;
115
| ^^^
12-
= note: ...which again requires const-evaluating + checking `FOO`, completing the cycle
6+
|
7+
= note: ...which immediately requires const-evaluating + checking `FOO` again
138
note: cycle used when linting top-level module
149
--> $DIR/recursive-static-definition.rs:1:1
1510
|

tests/ui/treat-err-as-bug/err.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ error: the compiler unexpectedly panicked. this is a bug.
88

99
query stack during panic:
1010
#0 [eval_to_allocation_raw] const-evaluating + checking `C`
11-
#1 [eval_to_allocation_raw] const-evaluating + checking `C`
11+
#1 [lint_mod] linting top-level module
1212
end of query stack

tests/ui/type-alias-enum-variants/self-in-enum-definition.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0391]: cycle detected when simplifying constant for the type system `Alph
44
LL | V3 = Self::V1 {} as u8 + 2,
55
| ^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: ...which requires simplifying constant for the type system `Alpha::V3::{constant#0}`...
8-
--> $DIR/self-in-enum-definition.rs:5:10
9-
|
10-
LL | V3 = Self::V1 {} as u8 + 2,
11-
| ^^^^^^^^^^^^^^^^^^^^^
127
note: ...which requires const-evaluating + checking `Alpha::V3::{constant#0}`...
138
--> $DIR/self-in-enum-definition.rs:5:10
149
|

0 commit comments

Comments
 (0)