Skip to content

Commit 66d79c7

Browse files
committed
Auto merge of rust-lang#117543 - compiler-errors:no-args-for-const, r=<try>
Scrub param-env when evaluating constant with no generic args r? `@ghost`
2 parents adda05f + 8259843 commit 66d79c7

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

compiler/rustc_middle/src/ty/consts/kind.rs

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ impl<'tcx> UnevaluatedConst<'tcx> {
5050
args: ty::GenericArgs::identity_for_item(tcx, self.def),
5151
},
5252
)
53+
} else if self.args.is_empty() && !tcx.features().generic_const_exprs {
54+
(param_env.without_caller_bounds(), tcx.erase_regions(self))
5355
} else {
5456
(tcx.erase_regions(param_env).with_reveal_all_normalized(tcx), tcx.erase_regions(self))
5557
}

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
error[E0391]: cycle detected when evaluating type-level constant
1+
error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{constant#0}`
22
--> $DIR/const-size_of-cycle.rs:4:17
33
|
44
LL | bytes: [u8; std::mem::size_of::<Foo>()]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
7+
= note: ...which requires computing layout of `Foo`...
8+
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
9+
= note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...
10+
note: ...which requires evaluating type-level constant...
811
--> $DIR/const-size_of-cycle.rs:4:17
912
|
1013
LL | bytes: [u8; std::mem::size_of::<Foo>()]
@@ -14,15 +17,12 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
1417
|
1518
LL | bytes: [u8; std::mem::size_of::<Foo>()]
1619
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
= note: ...which requires computing layout of `Foo`...
18-
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
19-
= note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...
20-
= note: ...which again requires evaluating type-level constant, completing the cycle
21-
note: cycle used when checking that `Foo` is well-formed
22-
--> $DIR/const-size_of-cycle.rs:3:1
20+
= note: ...which again requires const-evaluating + checking `Foo::bytes::{constant#0}`, completing the cycle
21+
note: cycle used when evaluating type-level constant
22+
--> $DIR/const-size_of-cycle.rs:4:17
2323
|
24-
LL | struct Foo {
25-
| ^^^^^^^^^^
24+
LL | bytes: [u8; std::mem::size_of::<Foo>()]
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
= 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
2727

2828
error: aborting due to previous error

tests/ui/consts/issue-44415.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::intrinsics;
44

55
struct Foo {
66
bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
7-
//~^ ERROR cycle detected when evaluating type-level constant
7+
//~^ ERROR cycle detected when const-evaluating + checking `Foo::bytes::{constant#0}`
88
x: usize,
99
}
1010

tests/ui/consts/issue-44415.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
error[E0391]: cycle detected when evaluating type-level constant
1+
error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{constant#0}`
22
--> $DIR/issue-44415.rs:6:17
33
|
44
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
7+
= note: ...which requires computing layout of `Foo`...
8+
= note: ...which requires computing layout of `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
9+
= note: ...which requires normalizing `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
10+
note: ...which requires evaluating type-level constant...
811
--> $DIR/issue-44415.rs:6:17
912
|
1013
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
@@ -14,15 +17,12 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
1417
|
1518
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
1619
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
= note: ...which requires computing layout of `Foo`...
18-
= note: ...which requires computing layout of `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
19-
= note: ...which requires normalizing `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
20-
= note: ...which again requires evaluating type-level constant, completing the cycle
21-
note: cycle used when checking that `Foo` is well-formed
22-
--> $DIR/issue-44415.rs:5:1
20+
= note: ...which again requires const-evaluating + checking `Foo::bytes::{constant#0}`, completing the cycle
21+
note: cycle used when evaluating type-level constant
22+
--> $DIR/issue-44415.rs:6:17
2323
|
24-
LL | struct Foo {
25-
| ^^^^^^^^^^
24+
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
= 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
2727

2828
error: aborting due to previous error

0 commit comments

Comments
 (0)