Skip to content

Commit f870761

Browse files
Make sure to use normalized ty for unevaluated const for default struct value
1 parent ad30cae commit f870761

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

compiler/rustc_mir_build/src/build/expr/into.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
367367
.collect()
368368
}
369369
AdtExprBase::DefaultFields(field_types) => {
370-
itertools::zip_eq(field_names, &**field_types)
371-
.map(|(n, ty)| match fields_map.get(&n) {
370+
itertools::zip_eq(field_names, field_types)
371+
.map(|(n, &ty)| match fields_map.get(&n) {
372372
Some(v) => v.clone(),
373373
None => match variant.fields[n].value {
374374
Some(def) => {
375-
let value = Const::from_unevaluated(this.tcx, def)
376-
.instantiate(this.tcx, args);
377-
this.literal_operand(expr_span, value)
375+
let value = Const::Unevaluated(
376+
UnevaluatedConst::new(def, args),
377+
ty,
378+
);
379+
Operand::Constant(Box::new(ConstOperand {
380+
span: expr_span,
381+
user_ty: None,
382+
const_: value,
383+
}))
378384
}
379385
None => {
380386
let name = variant.fields[n].name;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ check-pass
2+
3+
#![feature(default_field_values)]
4+
5+
struct Value<const VALUE: u8>;
6+
7+
impl<const VALUE: u8> Value<VALUE> {
8+
pub const VALUE: Self = Self;
9+
}
10+
11+
pub struct WithUse {
12+
_use: Value<{ 0 + 0 }> = Value::VALUE
13+
}
14+
15+
const _: WithUse = WithUse { .. };
16+
17+
fn main() {}

0 commit comments

Comments
 (0)