diff options
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/bounds.rs | 43 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect/item_bounds.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect/predicates_of.rs | 20 |
4 files changed, 34 insertions, 43 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 14e3ceadb10..12f66779522 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -945,8 +945,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let mut trait_bounds = vec![]; let mut projection_bounds = vec![]; - for (clause, span) in bounds.predicates() { - let pred: ty::Predicate<'tcx> = clause.to_predicate(tcx); + for (clause, span) in bounds.clauses() { + let pred: ty::Predicate<'tcx> = clause.as_predicate(); let bound_pred = pred.kind(); match bound_pred.skip_binder() { ty::PredicateKind::Clause(clause) => match clause { diff --git a/compiler/rustc_hir_analysis/src/bounds.rs b/compiler/rustc_hir_analysis/src/bounds.rs index 6bd498e142d..531100e1fe6 100644 --- a/compiler/rustc_hir_analysis/src/bounds.rs +++ b/compiler/rustc_hir_analysis/src/bounds.rs @@ -2,7 +2,6 @@ //! `ty` form from the HIR. use rustc_hir::LangItem; -use rustc_middle::ty::Binder; use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; use rustc_span::Span; @@ -24,62 +23,58 @@ use rustc_span::Span; /// include the self type (e.g., `trait_bounds`) but in others we do not #[derive(Default, PartialEq, Eq, Clone, Debug)] pub struct Bounds<'tcx> { - pub predicates: Vec<(Binder<'tcx, ty::ClauseKind<'tcx>>, Span)>, + pub clauses: Vec<(ty::Clause<'tcx>, Span)>, } impl<'tcx> Bounds<'tcx> { pub fn push_region_bound( &mut self, - _tcx: TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, region: ty::PolyTypeOutlivesPredicate<'tcx>, span: Span, ) { - self.predicates.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)), span)); + self.clauses + .push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span)); } pub fn push_trait_bound( &mut self, - _tcx: TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, span: Span, constness: ty::BoundConstness, polarity: ty::ImplPolarity, ) { - self.predicates.push(( - trait_ref.map_bound(|trait_ref| { - ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, constness, polarity }) - }), + self.clauses.push(( + trait_ref + .map_bound(|trait_ref| { + ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, constness, polarity }) + }) + .to_predicate(tcx), span, )); } pub fn push_projection_bound( &mut self, - _tcx: TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, projection: ty::PolyProjectionPredicate<'tcx>, span: Span, ) { - self.predicates.push((projection.map_bound(|proj| ty::ClauseKind::Projection(proj)), span)); + self.clauses.push(( + projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx), + span, + )); } pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) { let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span)); let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]); // Preferable to put this obligation first, since we report better errors for sized ambiguity. - self.predicates.insert( - 0, - ( - ty::Binder::dummy(ty::ClauseKind::Trait( - trait_ref.without_const().to_predicate(tcx), - )), - span, - ), - ); + self.clauses.insert(0, (trait_ref.to_predicate(tcx), span)); } - pub fn predicates( - &self, - ) -> impl Iterator<Item = (Binder<'tcx, ty::ClauseKind<'tcx>>, Span)> + '_ { - self.predicates.iter().cloned() + pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ { + self.clauses.iter().cloned() } } diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index b3e9acf0a4b..5f35678d95d 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -3,7 +3,6 @@ use crate::astconv::{AstConv, OnlySelfBounds}; use rustc_hir as hir; use rustc_infer::traits::util; use rustc_middle::ty::subst::InternalSubsts; -use rustc_middle::ty::ToPredicate; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::Span; @@ -49,8 +48,8 @@ fn associated_type_bounds<'tcx>( let all_bounds = tcx.arena.alloc_from_iter( bounds - .predicates() - .map(|(clause, span)| (clause.to_predicate(tcx), span)) + .clauses() + .map(|(clause, span)| (clause.as_predicate(), span)) .chain(bounds_from_parent), ); debug!( @@ -80,9 +79,8 @@ fn opaque_type_bounds<'tcx>( icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span); debug!(?bounds); - tcx.arena.alloc_from_iter( - bounds.predicates().map(|(clause, span)| (clause.to_predicate(tcx), span)), - ) + tcx.arena + .alloc_from_iter(bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span))) }) } diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index cd801202aea..3081f0c386a 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -126,8 +126,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen predicates.extend( icx.astconv() .compute_bounds(tcx.types.self_param, self_bounds, OnlySelfBounds(false)) - .predicates() - .map(|(clause, span)| (clause.to_predicate(tcx), span)), + .clauses() + .map(|(clause, span)| (clause.as_predicate(), span)), ); } @@ -176,9 +176,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen param.span, ); trace!(?bounds); - predicates.extend( - bounds.predicates().map(|(clause, span)| (clause.to_predicate(tcx), span)), - ); + predicates + .extend(bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span))); trace!(?predicates); } GenericParamKind::Const { .. } => { @@ -237,9 +236,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen bound_vars, OnlySelfBounds(false), ); - predicates.extend( - bounds.predicates().map(|(clause, span)| (clause.to_predicate(tcx), span)), - ); + predicates + .extend(bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span))); } hir::WherePredicate::RegionPredicate(region_pred) => { @@ -669,8 +667,8 @@ pub(super) fn implied_predicates_with_filter( // Combine the two lists to form the complete set of superbounds: let implied_bounds = &*tcx.arena.alloc_from_iter( superbounds - .predicates() - .map(|(clause, span)| (clause.to_predicate(tcx), span)) + .clauses() + .map(|(clause, span)| (clause.as_predicate(), span)) .chain(where_bounds_that_match), ); debug!(?implied_bounds); @@ -831,7 +829,7 @@ impl<'tcx> ItemCtxt<'tcx> { ); } - bounds.predicates().map(|(clause, span)| (clause.to_predicate(self.tcx), span)).collect() + bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span)).collect() } #[instrument(level = "trace", skip(self))] |
