Skip to content

Commit ec12977

Browse files
committed
Auto merge of rust-lang#115762 - oli-obk:early_const_prop_lint2, r=<try>
Avoid revealing in layout_of r? `@compiler-errors` I feel like `layout_of` is doing too many things at once, and I don't really know why. It could allow us to if callers could decide whether to reveal opaque types.
2 parents 3ebb562 + 21e8d63 commit ec12977

12 files changed

+28
-28
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ build/
5252
/src/tools/x/target
5353
# Created by default with `src/ci/docker/run.sh`
5454
/obj/
55+
# Created on ICE during build
56+
rustc-ice-*.txt
5557

5658
## Temporary files
5759
*~

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_mir_transform/src/const_prop_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
176176
) -> ConstPropagator<'mir, 'tcx> {
177177
let def_id = body.source.def_id();
178178
let args = &GenericArgs::identity_for_item(tcx, def_id);
179-
let param_env = tcx.param_env_reveal_all_normalized(def_id);
179+
let param_env = tcx.param_env(def_id);
180180

181181
let can_const_prop = CanConstProp::check(tcx, param_env, body);
182182
let mut ecx = InterpCx::new(

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
@@ -36,7 +36,6 @@ fn layout_of<'tcx>(
3636
let (param_env, ty) = query.into_parts();
3737
debug!(?ty);
3838

39-
let param_env = param_env.with_reveal_all_normalized(tcx);
4039
let unnormalized_ty = ty;
4140

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

src/etc/rust_analyzer_settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"compiler/rustc_codegen_gcc/Cargo.toml"
1717
],
1818
"rust-analyzer.rustfmt.overrideCommand": [
19-
"./build/host/rustfmt/bin/rustfmt",
19+
"${workspaceFolder}/build/host/rustfmt/bin/rustfmt",
2020
"--edition=2021"
2121
],
2222
"rust-analyzer.procMacro.server": "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv",

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

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0391]: cycle detected when elaborating drops for `<impl at $DIR/issue-249
44
LL | const BAR: u32 = IMPL_REF_BAR;
55
| ^^^^^^^^^^^^
66
|
7-
note: ...which requires const-evaluating + checking `IMPL_REF_BAR`...
8-
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
9-
|
10-
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^
127
note: ...which requires const-evaluating + checking `IMPL_REF_BAR`...
138
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:27
149
|

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

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0391]: cycle detected when elaborating drops for `FooDefault::BAR`
44
LL | const BAR: u32 = DEFAULT_REF_BAR;
55
| ^^^^^^^^^^^^^^^
66
|
7-
note: ...which requires const-evaluating + checking `DEFAULT_REF_BAR`...
8-
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1
9-
|
10-
LL | const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
127
note: ...which requires const-evaluating + checking `DEFAULT_REF_BAR`...
138
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:30
149
|

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

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0391]: cycle detected when elaborating drops for `<impl at $DIR/issue-249
44
LL | const BAR: u32 = TRAIT_REF_BAR;
55
| ^^^^^^^^^^^^^
66
|
7-
note: ...which requires const-evaluating + checking `TRAIT_REF_BAR`...
8-
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
9-
|
10-
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^
127
note: ...which requires const-evaluating + checking `TRAIT_REF_BAR`...
138
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:28
149
|

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)