Skip to content

Commit

Permalink
Scrub param-env when evaluating constant with no generic args
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 3, 2023
1 parent adda05f commit 8259843
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/ty/consts/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ impl<'tcx> UnevaluatedConst<'tcx> {
args: ty::GenericArgs::identity_for_item(tcx, self.def),
},
)
} else if self.args.is_empty() && !tcx.features().generic_const_exprs {
(param_env.without_caller_bounds(), tcx.erase_regions(self))
} else {
(tcx.erase_regions(param_env).with_reveal_all_normalized(tcx), tcx.erase_regions(self))
}
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/consts/const-size_of-cycle.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0391]: cycle detected when evaluating type-level constant
error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{constant#0}`
--> $DIR/const-size_of-cycle.rs:4:17
|
LL | bytes: [u8; std::mem::size_of::<Foo>()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
= note: ...which requires computing layout of `Foo`...
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
= note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...
note: ...which requires evaluating type-level constant...
--> $DIR/const-size_of-cycle.rs:4:17
|
LL | bytes: [u8; std::mem::size_of::<Foo>()]
Expand All @@ -14,15 +17,12 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
|
LL | bytes: [u8; std::mem::size_of::<Foo>()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing layout of `Foo`...
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
= note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...
= note: ...which again requires evaluating type-level constant, completing the cycle
note: cycle used when checking that `Foo` is well-formed
--> $DIR/const-size_of-cycle.rs:3:1
= note: ...which again requires const-evaluating + checking `Foo::bytes::{constant#0}`, completing the cycle
note: cycle used when evaluating type-level constant
--> $DIR/const-size_of-cycle.rs:4:17
|
LL | struct Foo {
| ^^^^^^^^^^
LL | bytes: [u8; std::mem::size_of::<Foo>()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

error: aborting due to previous error
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/issue-44415.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::intrinsics;

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

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/consts/issue-44415.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0391]: cycle detected when evaluating type-level constant
error[E0391]: cycle detected when const-evaluating + checking `Foo::bytes::{constant#0}`
--> $DIR/issue-44415.rs:6:17
|
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
= note: ...which requires computing layout of `Foo`...
= note: ...which requires computing layout of `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
= note: ...which requires normalizing `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
note: ...which requires evaluating type-level constant...
--> $DIR/issue-44415.rs:6:17
|
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
Expand All @@ -14,15 +17,12 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
|
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing layout of `Foo`...
= note: ...which requires computing layout of `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
= note: ...which requires normalizing `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
= note: ...which again requires evaluating type-level constant, completing the cycle
note: cycle used when checking that `Foo` is well-formed
--> $DIR/issue-44415.rs:5:1
= note: ...which again requires const-evaluating + checking `Foo::bytes::{constant#0}`, completing the cycle
note: cycle used when evaluating type-level constant
--> $DIR/issue-44415.rs:6:17
|
LL | struct Foo {
| ^^^^^^^^^^
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

error: aborting due to previous error
Expand Down

0 comments on commit 8259843

Please sign in to comment.