Remove glob imports for ObligationCauseCode

This commit is contained in:
Michael Goulet
2024-05-09 20:05:59 -04:00
parent 04c049498d
commit 4bde8a8f4b
24 changed files with 279 additions and 178 deletions

View File

@@ -2,6 +2,7 @@ use crate::infer::InferCtxt;
use crate::traits;
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_infer::traits::ObligationCauseCode;
use rustc_middle::ty::{
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
};
@@ -333,7 +334,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
return self.out;
}
let cause = self.cause(traits::WellFormed(None));
let cause = self.cause(ObligationCauseCode::WellFormed(None));
let param_env = self.param_env;
let mut obligations = Vec::with_capacity(self.out.len());
for mut obligation in self.out {
@@ -485,7 +486,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
&mut traits::SelectionContext::new(self.infcx),
self.param_env,
data,
self.cause(traits::WellFormed(None)),
self.cause(ObligationCauseCode::WellFormed(None)),
self.recursion_depth,
&mut self.out,
);
@@ -498,7 +499,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
fn compute_projection_args(&mut self, args: GenericArgsRef<'tcx>) {
let tcx = self.tcx();
let cause = self.cause(traits::WellFormed(None));
let cause = self.cause(ObligationCauseCode::WellFormed(None));
let param_env = self.param_env;
let depth = self.recursion_depth;
@@ -565,9 +566,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
iter::zip(predicates, origins.into_iter().rev())
.map(|((pred, span), origin_def_id)| {
let code = if span.is_dummy() {
traits::ItemObligation(origin_def_id)
ObligationCauseCode::ItemObligation(origin_def_id)
} else {
traits::BindingObligation(origin_def_id, span)
ObligationCauseCode::BindingObligation(origin_def_id, span)
};
let cause = self.cause(code);
traits::Obligation::with_depth(
@@ -626,7 +627,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.reserve(implicit_bounds.len());
for implicit_bound in implicit_bounds {
let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound));
let cause = self.cause(ObligationCauseCode::ObjectTypeBound(ty, explicit_bound));
let outlives =
ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound));
self.out.push(traits::Obligation::with_depth(
@@ -644,7 +645,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
type Result = ();
fn visit_ty(&mut self, t: <TyCtxt<'tcx> as ty::Interner>::Ty) -> Self::Result {
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
debug!("wf bounds for t={:?} t.kind={:#?}", t, t.kind());
let tcx = self.tcx();
@@ -673,22 +674,22 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
ty::Infer(ty::FloatVar(_)) => {}
ty::Slice(subty) => {
self.require_sized(subty, traits::SliceOrArrayElem);
self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem);
}
ty::Array(subty, _) => {
self.require_sized(subty, traits::SliceOrArrayElem);
self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem);
// Note that we handle the len is implicitly checked while walking `arg`.
}
ty::Pat(subty, _) => {
self.require_sized(subty, traits::MiscObligation);
self.require_sized(subty, ObligationCauseCode::MiscObligation);
}
ty::Tuple(tys) => {
if let Some((_last, rest)) = tys.split_last() {
for &elem in rest {
self.require_sized(elem, traits::TupleElem);
self.require_sized(elem, ObligationCauseCode::TupleElem);
}
}
}
@@ -728,7 +729,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
ty::Ref(r, rty, _) => {
// WfReference
if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
let cause = self.cause(traits::ReferenceOutlivesReferent(t));
let cause = self.cause(ObligationCauseCode::ReferenceOutlivesReferent(t));
self.out.push(traits::Obligation::with_depth(
tcx,
cause,
@@ -825,7 +826,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
if let Some(principal) = data.principal_def_id() {
self.out.push(traits::Obligation::with_depth(
tcx,
self.cause(traits::WellFormed(None)),
self.cause(ObligationCauseCode::WellFormed(None)),
self.recursion_depth,
self.param_env,
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(principal)),
@@ -847,7 +848,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
// See also the comment on `fn obligations`, describing "livelock"
// prevention, which happens before this can be reached.
ty::Infer(_) => {
let cause = self.cause(traits::WellFormed(None));
let cause = self.cause(ObligationCauseCode::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
tcx,
cause,
@@ -863,7 +864,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
t.super_visit_with(self)
}
fn visit_const(&mut self, c: <TyCtxt<'tcx> as ty::Interner>::Const) -> Self::Result {
fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
let tcx = self.tcx();
match c.kind() {
@@ -875,7 +876,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
ty::ClauseKind::ConstEvaluatable(c),
));
let cause = self.cause(traits::WellFormed(None));
let cause = self.cause(ObligationCauseCode::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
tcx,
cause,
@@ -886,7 +887,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
}
}
ty::ConstKind::Infer(_) => {
let cause = self.cause(traits::WellFormed(None));
let cause = self.cause(ObligationCauseCode::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
tcx,
@@ -909,7 +910,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
ty::ClauseKind::ConstEvaluatable(c),
));
let cause = self.cause(traits::WellFormed(None));
let cause = self.cause(ObligationCauseCode::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
tcx,
cause,
@@ -933,7 +934,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
c.super_visit_with(self)
}
fn visit_predicate(&mut self, _p: <TyCtxt<'tcx> as ty::Interner>::Predicate) -> Self::Result {
fn visit_predicate(&mut self, _p: ty::Predicate<'tcx>) -> Self::Result {
bug!("predicate should not be checked for well-formedness");
}
}