Auto merge of #98588 - b-naber:valtrees-cleanup, r=lcnr
Use only ty::Unevaluated<'tcx, ()> in type system r? `@lcnr`
This commit is contained in:
commit
c524c7dd25
59 changed files with 383 additions and 323 deletions
|
@ -770,7 +770,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
|||
ty::ConstKind::Unevaluated(ct) => {
|
||||
debug!(?ct);
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
match self.tcx.const_eval_resolve(param_env, ct, None) {
|
||||
match self.tcx.const_eval_resolve(param_env, ct.expand(), None) {
|
||||
// The `monomorphize` call should have evaluated that constant already.
|
||||
Ok(val) => val,
|
||||
Err(ErrorHandled::Reported(_) | ErrorHandled::Linted) => return,
|
||||
|
@ -783,44 +783,22 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
|||
}
|
||||
_ => return,
|
||||
},
|
||||
};
|
||||
collect_const_value(self.tcx, val, self.output);
|
||||
self.visit_ty(literal.ty(), TyContext::Location(location));
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_const(&mut self, constant: ty::Const<'tcx>, location: Location) {
|
||||
debug!("visiting const {:?} @ {:?}", constant, location);
|
||||
|
||||
let substituted_constant = self.monomorphize(constant);
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
|
||||
match substituted_constant.kind() {
|
||||
ty::ConstKind::Value(val) => {
|
||||
let const_val = self.tcx.valtree_to_const_val((constant.ty(), val));
|
||||
collect_const_value(self.tcx, const_val, self.output)
|
||||
}
|
||||
ty::ConstKind::Unevaluated(unevaluated) => {
|
||||
match self.tcx.const_eval_resolve(param_env, unevaluated, None) {
|
||||
mir::ConstantKind::Unevaluated(uv, _) => {
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
match self.tcx.const_eval_resolve(param_env, uv, None) {
|
||||
// The `monomorphize` call should have evaluated that constant already.
|
||||
Ok(val) => span_bug!(
|
||||
self.body.source_info(location).span,
|
||||
"collection encountered the unevaluated constant {} which evaluated to {:?}",
|
||||
substituted_constant,
|
||||
val
|
||||
),
|
||||
Err(ErrorHandled::Reported(_) | ErrorHandled::Linted) => {}
|
||||
Ok(val) => val,
|
||||
Err(ErrorHandled::Reported(_) | ErrorHandled::Linted) => return,
|
||||
Err(ErrorHandled::TooGeneric) => span_bug!(
|
||||
self.body.source_info(location).span,
|
||||
"collection encountered polymorphic constant: {}",
|
||||
substituted_constant
|
||||
"collection encountered polymorphic constant: {:?}",
|
||||
literal
|
||||
),
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.super_const(constant);
|
||||
};
|
||||
collect_const_value(self.tcx, val, self.output);
|
||||
MirVisitor::visit_ty(self, literal.ty(), TyContext::Location(location));
|
||||
}
|
||||
|
||||
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc_hir::{def::DefKind, def_id::DefId, ConstContext};
|
|||
use rustc_index::bit_set::FiniteBitSet;
|
||||
use rustc_middle::mir::{
|
||||
visit::{TyContext, Visitor},
|
||||
Local, LocalDecl, Location,
|
||||
Constant, ConstantKind, Local, LocalDecl, Location,
|
||||
};
|
||||
use rustc_middle::ty::{
|
||||
self,
|
||||
|
@ -270,8 +270,15 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
self.super_local_decl(local, local_decl);
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, c: Const<'tcx>, _: Location) {
|
||||
c.visit_with(self);
|
||||
fn visit_constant(&mut self, ct: &Constant<'tcx>, location: Location) {
|
||||
match ct.literal {
|
||||
ConstantKind::Ty(c) => {
|
||||
c.visit_with(self);
|
||||
}
|
||||
ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => {
|
||||
Visitor::visit_ty(self, ty, TyContext::Location(location))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext) {
|
||||
|
@ -292,7 +299,26 @@ 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: Some(p)})
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
|
||||
if matches!(self.tcx.def_kind(def.did), DefKind::AnonConst) =>
|
||||
{
|
||||
assert_eq!(promoted, ());
|
||||
|
||||
self.visit_child_body(def.did, substs);
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
_ => c.super_visit_with(self),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mir_const(&mut self, constant: ConstantKind<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
if !constant.has_param_types_or_consts() {
|
||||
return ControlFlow::CONTINUE;
|
||||
}
|
||||
|
||||
match constant {
|
||||
ConstantKind::Ty(ct) => ct.visit_with(self),
|
||||
ConstantKind::Unevaluated(ty::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 =>
|
||||
|
@ -303,13 +329,9 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
|||
self.visit_body(&promoted[p]);
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
ty::ConstKind::Unevaluated(uv)
|
||||
if matches!(self.tcx.def_kind(uv.def.did), DefKind::AnonConst | DefKind::InlineConst) =>
|
||||
{
|
||||
self.visit_child_body(uv.def.did, uv.substs);
|
||||
ControlFlow::CONTINUE
|
||||
ConstantKind::Val(..) | ConstantKind::Unevaluated(..) => {
|
||||
constant.super_visit_with(self)
|
||||
}
|
||||
_ => c.super_visit_with(self),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue