Skip to content

Commit

Permalink
Make sure to use normalized ty for unevaluated const for default stru…
Browse files Browse the repository at this point in the history
…ct value
  • Loading branch information
compiler-errors committed Dec 14, 2024
1 parent ad30cae commit f870761
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 11 additions & 5 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ check-pass

#![feature(default_field_values)]

struct Value<const VALUE: u8>;

impl<const VALUE: u8> Value<VALUE> {
pub const VALUE: Self = Self;
}

pub struct WithUse {
_use: Value<{ 0 + 0 }> = Value::VALUE
}

const _: WithUse = WithUse { .. };

fn main() {}

0 comments on commit f870761

Please sign in to comment.