introduce mir::Unevaluated

This commit is contained in:
b-naber 2022-09-19 19:46:53 +02:00
parent 3e50038a2d
commit 9f3784df89
32 changed files with 166 additions and 132 deletions

View file

@ -8,6 +8,7 @@
use rustc_hir::{def::DefKind, def_id::DefId, ConstContext};
use rustc_index::bit_set::FiniteBitSet;
use rustc_middle::mir::{
self,
visit::{TyContext, Visitor},
Constant, ConstantKind, Local, LocalDecl, Location,
};
@ -299,11 +300,9 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
self.unused_parameters.clear(param.index);
ControlFlow::CONTINUE
}
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs })
if matches!(self.tcx.def_kind(def.did), DefKind::AnonConst) =>
{
assert_eq!(promoted, ());
self.visit_child_body(def.did, substs);
ControlFlow::CONTINUE
}
@ -318,7 +317,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
match constant {
ConstantKind::Ty(ct) => ct.visit_with(self),
ConstantKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted: Some(p) }, _)
ConstantKind::Unevaluated(mir::Unevaluated { def, substs: _, promoted: Some(p) }, _)
// Avoid considering `T` unused when constants are of the form:
// `<Self as Foo<T>>::foo::promoted[p]`
if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self =>