Skip to content

Commit b312929

Browse files
committed
Avoid revealing in layout_of
1 parent 9597d24 commit b312929

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

compiler/rustc_middle/src/ty/layout.rs

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
324324
param_env: ty::ParamEnv<'tcx>,
325325
) -> Result<SizeSkeleton<'tcx>, &'tcx LayoutError<'tcx>> {
326326
debug_assert!(!ty.has_non_region_infer());
327+
let param_env = param_env.with_reveal_all_normalized(tcx);
327328

328329
// First try computing a static layout.
329330
let err = match tcx.layout_of(param_env.and(ty)) {

compiler/rustc_passes/src/layout_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn ensure_wf<'tcx>(
6666
}
6767

6868
fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
69-
let param_env = tcx.param_env(item_def_id);
69+
let param_env = tcx.param_env_reveal_all_normalized(item_def_id);
7070
let ty = tcx.type_of(item_def_id).instantiate_identity();
7171
let span = tcx.def_span(item_def_id.to_def_id());
7272
if !ensure_wf(tcx, param_env, ty, item_def_id, span) {

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,10 @@ pub fn typeid_for_instance<'tcx>(
11061106
options: TypeIdOptions,
11071107
) -> String {
11081108
let fn_abi = tcx
1109-
.fn_abi_of_instance(tcx.param_env(instance.def_id()).and((*instance, ty::List::empty())))
1109+
.fn_abi_of_instance(
1110+
tcx.param_env_reveal_all_normalized(instance.def_id())
1111+
.and((*instance, ty::List::empty())),
1112+
)
11101113
.unwrap_or_else(|instance| {
11111114
bug!("typeid_for_instance: couldn't get fn_abi of instance {:?}", instance)
11121115
});

compiler/rustc_ty_utils/src/layout.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ fn layout_of<'tcx>(
3535
let (param_env, ty) = query.into_parts();
3636
debug!(?ty);
3737

38-
let param_env = param_env.with_reveal_all_normalized(tcx);
3938
let unnormalized_ty = ty;
4039

4140
// FIXME: We might want to have two different versions of `layout_of`:

tests/ui/recursion/issue-26548-recursion-via-normalize.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//~ ERROR cycle detected when computing layout of `core::option::Option<S>`
1+
//~ ERROR cycle detected when computing layout of `core::option::Option<<S as Mirror>::It>`
22
//~| 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
33
//~| NOTE ...which requires computing layout of `S`...
4-
//~| NOTE ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
5-
//~| NOTE ...which again requires computing layout of `core::option::Option<S>`, completing the cycle
6-
//~| NOTE cycle used when computing layout of `core::option::Option<<S as Mirror>::It>`
4+
//~| NOTE ...which again requires computing layout of `core::option::Option<<S as Mirror>::It>`, completing the cycle
5+
//~| NOTE ...which requires computing layout of `core::option::Option<S>`...
76

87
trait Mirror {
8+
//~^ NOTE: cycle used when checking deathness of variables in top-level module
99
type It: ?Sized;
1010
}
1111
impl<T: ?Sized> Mirror for T {

tests/ui/recursion/issue-26548-recursion-via-normalize.stderr

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
error[E0391]: cycle detected when computing layout of `core::option::Option<S>`
1+
error[E0391]: cycle detected when computing layout of `core::option::Option<<S as Mirror>::It>`
22
|
3+
= note: ...which requires computing layout of `core::option::Option<S>`...
34
= note: ...which requires computing layout of `S`...
4-
= note: ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
5-
= note: ...which again requires computing layout of `core::option::Option<S>`, completing the cycle
6-
= note: cycle used when computing layout of `core::option::Option<<S as Mirror>::It>`
5+
= note: ...which again requires computing layout of `core::option::Option<<S as Mirror>::It>`, completing the cycle
6+
note: cycle used when checking deathness of variables in top-level module
7+
--> $DIR/issue-26548-recursion-via-normalize.rs:7:1
8+
|
9+
LL | / trait Mirror {
10+
LL | |
11+
LL | | type It: ?Sized;
12+
LL | | }
13+
... |
14+
LL | | let _s = S(None);
15+
LL | | }
16+
| |_^
717
= 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
818

919
error: aborting due to previous error

0 commit comments

Comments
 (0)