Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrub param-env when evaluating constant with no generic args #117543

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading