diff options
| author | bors <bors@rust-lang.org> | 2021-01-17 20:49:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-17 20:49:11 +0000 |
| commit | 4253153db205251f72ea4493687a31e04a2a8ca0 (patch) | |
| tree | e1c25749be58c8ca538627492b6e53f995f7342c /src | |
| parent | 1f0fc02cc8ab4e0d9dd3e06a6d46fcb72b2a026f (diff) | |
| parent | c4376ba24a488bf78003e35427d06e52b8b7479f (diff) | |
| download | rust-4253153db205251f72ea4493687a31e04a2a8ca0.tar.gz rust-4253153db205251f72ea4493687a31e04a2a8ca0.zip | |
Auto merge of #80679 - jackh726:predicate-kind-take2, r=lcnr
Remove PredicateKind and instead only use Binder<PredicateAtom> Originally brought up in https://github.com/rust-lang/rust/pull/76814#discussion_r546858171 r? `@lcnr`
Diffstat (limited to 'src')
10 files changed, 53 insertions, 57 deletions
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 43fb53ba18f..83114a72b8d 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -313,12 +313,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { tcx: TyCtxt<'tcx>, pred: ty::Predicate<'tcx>, ) -> FxHashSet<GenericParamDef> { - let bound_predicate = pred.bound_atom(); + let bound_predicate = pred.kind(); let regions = match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(poly_trait_pred, _) => { + ty::PredicateKind::Trait(poly_trait_pred, _) => { tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred)) } - ty::PredicateAtom::Projection(poly_proj_pred) => { + ty::PredicateKind::Projection(poly_proj_pred) => { tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_proj_pred)) } _ => return FxHashSet::default(), @@ -463,8 +463,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .iter() .filter(|p| { !orig_bounds.contains(p) - || match p.skip_binders() { - ty::PredicateAtom::Trait(pred, _) => pred.def_id() == sized_trait, + || match p.kind().skip_binder() { + ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait, _ => false, } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cafb65bc7f9..3ddb2adbf0a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -465,20 +465,20 @@ impl Clean<WherePredicate> for hir::WherePredicate<'_> { impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> { fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> { - let bound_predicate = self.bound_atom(); + let bound_predicate = self.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)), - ty::PredicateAtom::RegionOutlives(pred) => pred.clean(cx), - ty::PredicateAtom::TypeOutlives(pred) => pred.clean(cx), - ty::PredicateAtom::Projection(pred) => Some(pred.clean(cx)), - - ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => panic!("not user writable"), + ty::PredicateKind::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)), + ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx), + ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx), + ty::PredicateKind::Projection(pred) => Some(pred.clean(cx)), + + ty::PredicateKind::Subtype(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => panic!("not user writable"), } } } @@ -743,19 +743,19 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx .flat_map(|(p, _)| { let mut projection = None; let param_idx = (|| { - let bound_p = p.bound_atom(); + let bound_p = p.kind(); match bound_p.skip_binder() { - ty::PredicateAtom::Trait(pred, _constness) => { + ty::PredicateKind::Trait(pred, _constness) => { if let ty::Param(param) = pred.self_ty().kind() { return Some(param.index); } } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => { if let ty::Param(param) = ty.kind() { return Some(param.index); } } - ty::PredicateAtom::Projection(p) => { + ty::PredicateKind::Projection(p) => { if let ty::Param(param) = p.projection_ty.self_ty().kind() { projection = Some(bound_p.rebind(p)); return Some(param.index); @@ -1684,14 +1684,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> { let mut bounds = bounds .iter() .filter_map(|bound| { - // Note: The substs of opaque types can contain unbound variables, - // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here. - let bound_predicate = bound.bound_atom_with_opt_escaping(cx.tcx); + let bound_predicate = bound.kind(); let trait_ref = match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(tr, _constness) => { + ty::PredicateKind::Trait(tr, _constness) => { bound_predicate.rebind(tr.trait_ref) } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => { if let Some(r) = reg.clean(cx) { regions.push(GenericBound::Outlives(r)); } @@ -1710,8 +1708,8 @@ impl<'tcx> Clean<Type> for Ty<'tcx> { let bounds: Vec<_> = bounds .iter() .filter_map(|bound| { - if let ty::PredicateAtom::Projection(proj) = - bound.bound_atom_with_opt_escaping(cx.tcx).skip_binder() + if let ty::PredicateKind::Projection(proj) = + bound.kind().skip_binder() { if proj.projection_ty.trait_ref(cx.tcx) == trait_ref.skip_binder() diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 16aaa9cfd20..d4d0a8ce24c 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -129,7 +129,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) .predicates .iter() .filter_map(|(pred, _)| { - if let ty::PredicateAtom::Trait(pred, _) = pred.skip_binders() { + if let ty::PredicateKind::Trait(pred, _) = pred.kind().skip_binder() { if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None } } else { None diff --git a/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr b/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr index fee8b06e94c..92208231b17 100644 --- a/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr +++ b/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr @@ -1,4 +1,4 @@ -error: cannot specialize on `ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))` +error: cannot specialize on `Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,)))` --> $DIR/repeated_projection_type.rs:19:1 | LL | / impl<I, V: Id<This = (I,)>> X for V { diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index f9697afe405..a3a38fad9a3 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{Opaque, PredicateAtom::Trait}; +use rustc_middle::ty::{Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { &obligation, ); if let Trait(trait_pred, _) = - obligation.predicate.skip_binders() + obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 6e8102790a5..f7231bba175 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -1697,7 +1697,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::Opaque(def_id, _) = *ret_ty.kind() { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { - if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { + if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { // walk the associated type and check for Self if contains_ty(projection_predicate.ty, self_ty) { return; diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index a435f86bfd8..3b71f1b46e2 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -115,13 +115,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() { - if pred.def_id() == sized_trait { - return None; - } - Some(pred) - } else { - None + match obligation.predicate.kind().no_bound_vars() { + Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => { + Some(pred) + }, + _ => None, } }) .collect::<Vec<_>>(); diff --git a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs index 2501635e7ef..c6ae8b9b598 100644 --- a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs +++ b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{BytePos, Span}; @@ -42,7 +42,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders(); + if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; @@ -60,7 +60,7 @@ fn get_projection_pred<'tcx>( pred: TraitPredicate<'tcx>, ) -> Option<ProjectionPredicate<'tcx>> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() { + if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() { let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred)); if projection_pred.projection_ty.substs == pred.trait_ref.substs { return Some(projection_pred); diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 3e39a47f196..4c707c4b904 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -1470,7 +1470,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() { + if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } diff --git a/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs b/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs index 7cb7d0a26b6..a482017afeb 100644 --- a/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs @@ -19,18 +19,18 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> McfResult { loop { let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { - match predicate.skip_binders() { - ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::Projection(_) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue, - ty::PredicateAtom::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), - ty::PredicateAtom::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), - ty::PredicateAtom::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), - ty::PredicateAtom::Trait(pred, _) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Projection(_) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, + ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), + ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), + ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), + ty::PredicateKind::Trait(pred, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } |
