diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-16 08:03:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-16 08:03:32 +0100 |
| commit | 050e0cc6eba96d94767890ddc9f18f85e439f11b (patch) | |
| tree | d1f1e4d4b267da04a37681dd40a24f9f4acd91c0 /compiler | |
| parent | f2b91ccbc27cb06369aa2dd934ff219e156408a8 (diff) | |
| parent | f870761cd861ed222c5573cdd5abb99f4b9ba6d8 (diff) | |
| download | rust-050e0cc6eba96d94767890ddc9f18f85e439f11b.tar.gz rust-050e0cc6eba96d94767890ddc9f18f85e439f11b.zip | |
Rollup merge of #134314 - compiler-errors:default-struct-value-const, r=estebank
Make sure to use normalized ty for unevaluated const in default struct value This cleans up the way that we construct the `mir::Const::Unevaluated` for default struct values. We were previously using `from_unevaluated`, which doesn't normalize the type, and is really only used for inline assembly. Other codepaths (such as `ExprKind::NamedConst`) use the type from the body. Also, let's stop using `literal_operand`, which also is really not meant for calls other than for literal comparisons in pattern lowering. Also move all of the tests to a separate subdirectory so they don't need to have the same prefix on all the test files. Fixes #134298 r? estebank or reassign
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/build/expr/into.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index a3d5376dcd4..0ac1ae56d59 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -367,14 +367,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .collect() } AdtExprBase::DefaultFields(field_types) => { - itertools::zip_eq(field_names, &**field_types) - .map(|(n, ty)| match fields_map.get(&n) { + itertools::zip_eq(field_names, field_types) + .map(|(n, &ty)| match fields_map.get(&n) { Some(v) => v.clone(), None => match variant.fields[n].value { Some(def) => { - let value = Const::from_unevaluated(this.tcx, def) - .instantiate(this.tcx, args); - this.literal_operand(expr_span, value) + let value = Const::Unevaluated( + UnevaluatedConst::new(def, args), + ty, + ); + Operand::Constant(Box::new(ConstOperand { + span: expr_span, + user_ty: None, + const_: value, + })) } None => { let name = variant.fields[n].name; |
