You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #119627 - oli-obk:const_prop_lint_n̵o̵n̵sense, r=<try>
Remove all ConstPropNonsense
We track all locals and projections on them ourselves within the const propagator and only use the InterpCx to actually do some low level operations or read from constants (via `OpTy` we get for said constants).
r? `@RalfJung`
Copy file name to clipboardExpand all lines: compiler/rustc_const_eval/src/interpret/projection.rs
+21-28Lines changed: 21 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -153,11 +153,7 @@ where
153
153
154
154
// Offset may need adjustment for unsized fields.
155
155
let(meta, offset) = if field_layout.is_unsized(){
156
-
if base.layout().is_sized(){
157
-
// An unsized field of a sized type? Sure...
158
-
// But const-prop actually feeds us such nonsense MIR! (see test `const_prop/issue-86351.rs`)
159
-
throw_inval!(ConstPropNonsense);
160
-
}
156
+
assert!(!base.layout().is_sized());
161
157
let base_meta = base.meta();
162
158
// Re-use parent metadata to determine dynamic field layout.
163
159
// With custom DSTS, this *will* execute user-defined code, but the same
@@ -205,29 +201,26 @@ where
205
201
// see https://github.com/rust-lang/rust/issues/93688#issuecomment-1032929496.)
206
202
// So we just "offset" by 0.
207
203
let layout = base.layout().for_variant(self, variant);
208
-
if layout.abi.is_uninhabited(){
209
-
// `read_discriminant` should have excluded uninhabited variants... but ConstProp calls
210
-
// us on dead code.
211
-
// In the future we might want to allow this to permit code like this:
212
-
// (this is a Rust/MIR pseudocode mix)
213
-
// ```
214
-
// enum Option2 {
215
-
// Some(i32, !),
216
-
// None,
217
-
// }
218
-
//
219
-
// fn panic() -> ! { panic!() }
220
-
//
221
-
// let x: Option2;
222
-
// x.Some.0 = 42;
223
-
// x.Some.1 = panic();
224
-
// SetDiscriminant(x, Some);
225
-
// ```
226
-
// However, for now we don't generate such MIR, and this check here *has* found real
227
-
// bugs (see https://github.com/rust-lang/rust/issues/115145), so we will keep rejecting
228
-
// it.
229
-
throw_inval!(ConstPropNonsense)
230
-
}
204
+
// In the future we might want to allow this to permit code like this:
205
+
// (this is a Rust/MIR pseudocode mix)
206
+
// ```
207
+
// enum Option2 {
208
+
// Some(i32, !),
209
+
// None,
210
+
// }
211
+
//
212
+
// fn panic() -> ! { panic!() }
213
+
//
214
+
// let x: Option2;
215
+
// x.Some.0 = 42;
216
+
// x.Some.1 = panic();
217
+
// SetDiscriminant(x, Some);
218
+
// ```
219
+
// However, for now we don't generate such MIR, and this check here *has* found real
220
+
// bugs (see https://github.com/rust-lang/rust/issues/115145), so we will keep rejecting
221
+
// it.
222
+
assert!(!layout.abi.is_uninhabited());
223
+
231
224
// This cannot be `transmute` as variants *can* have a smaller size than the entire enum.
0 commit comments