Skip to content

Commit a7735cd

Browse files
committedSep 13, 2022
fixes/working version
1 parent 2554fa1 commit a7735cd

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed
 

‎compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
585585
uneval: &ty::Unevaluated<'tcx>,
586586
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
587587
let instance = self.resolve(uneval.def, uneval.substs)?;
588-
Ok(self.eval_to_allocation(GlobalId { instance, promoted: None })?.into())
588+
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uneval.promoted })?.into())
589589
}
590590

591591
pub fn mir_const_to_op(

‎compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+31-22
Original file line numberDiff line numberDiff line change
@@ -346,32 +346,41 @@ where
346346
};
347347

348348
// Check the qualifs of the value of `const` items.
349-
if let Some(ct) = constant.literal.const_for_ty() {
350-
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted: _ }) =
351-
ct.kind()
352-
{
353-
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
354-
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
355-
// check performed after the promotion. Verify that with an assertion.
356-
357-
// Don't peek inside trait associated constants.
358-
if cx.tcx.trait_of_item(def.did).is_none() {
359-
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
360-
cx.tcx.at(constant.span).mir_const_qualif_const_arg((did, param_did))
361-
} else {
362-
cx.tcx.at(constant.span).mir_const_qualif(def.did)
363-
};
364-
365-
if !Q::in_qualifs(&qualifs) {
366-
return false;
367-
}
349+
let uneval = match constant.literal {
350+
ConstantKind::Ty(ct) if matches!(ct.kind(), ty::ConstKind::Unevaluated(_)) => {
351+
let ty::ConstKind::Unevaluated(uv) = ct.kind() else { unreachable!() };
368352

369-
// Just in case the type is more specific than
370-
// the definition, e.g., impl associated const
371-
// with type parameters, take it into account.
353+
Some(uv.expand())
354+
}
355+
ConstantKind::Ty(_) => None,
356+
ConstantKind::Unevaluated(uv, _) => Some(uv),
357+
ConstantKind::Val(..) => None,
358+
};
359+
360+
if let Some(ty::Unevaluated { def, substs: _, promoted }) = uneval {
361+
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
362+
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
363+
// check performed after the promotion. Verify that with an assertion.
364+
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
365+
366+
// Don't peek inside trait associated constants.
367+
if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() {
368+
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
369+
cx.tcx.at(constant.span).mir_const_qualif_const_arg((did, param_did))
370+
} else {
371+
cx.tcx.at(constant.span).mir_const_qualif(def.did)
372+
};
373+
374+
if !Q::in_qualifs(&qualifs) {
375+
return false;
372376
}
377+
378+
// Just in case the type is more specific than
379+
// the definition, e.g., impl associated const
380+
// with type parameters, take it into account.
373381
}
374382
}
383+
375384
// Otherwise use the qualifs of the type.
376385
Q::in_any_value_of_ty(cx, constant.literal.ty())
377386
}

‎compiler/rustc_middle/src/mir/type_foldable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ConstantKind<'tcx> {
236236
ConstantKind::Ty(c) => Ok(ConstantKind::Ty(c.try_fold_with(folder)?)),
237237
ConstantKind::Val(v, t) => Ok(ConstantKind::Val(v, t.try_fold_with(folder)?)),
238238
ConstantKind::Unevaluated(uv, t) => {
239-
Ok(ConstantKind::Unevaluated(uv, t.try_fold_with(folder)?))
239+
Ok(ConstantKind::Unevaluated(uv.try_fold_with(folder)?, t.try_fold_with(folder)?))
240240
}
241241
}
242242
}

‎compiler/rustc_middle/src/mir/type_visitable.rs

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ impl<'tcx> TypeSuperVisitable<'tcx> for ConstantKind<'tcx> {
185185
match *self {
186186
ConstantKind::Ty(c) => c.visit_with(visitor),
187187
ConstantKind::Val(_, t) => t.visit_with(visitor),
188+
ConstantKind::Unevaluated(uv, t) => {
189+
uv.visit_with(visitor)?;
190+
t.visit_with(visitor)
191+
}
188192
}
189193
}
190194
}

‎compiler/rustc_monomorphize/src/polymorphize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
313313
}
314314

315315
match constant {
316-
ConstantKind::Ty(_) => constant.super_visit_with(self),
316+
ConstantKind::Ty(ct) => ct.visit_with(self),
317317
ConstantKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted: Some(p) }, _)
318318
// Avoid considering `T` unused when constants are of the form:
319319
// `<Self as Foo<T>>::foo::promoted[p]`

0 commit comments

Comments
 (0)
Please sign in to comment.