Skip to content

Commit 80dbe58

Browse files
committed
Use ParamBounds in WhereRegionPredicate
1 parent aed530a commit 80dbe58

File tree

18 files changed

+92
-109
lines changed

18 files changed

+92
-109
lines changed

src/librustc/hir/intravisit.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ pub trait Visitor<'v> : Sized {
314314
fn visit_trait_ref(&mut self, t: &'v TraitRef) {
315315
walk_trait_ref(self, t)
316316
}
317-
fn visit_ty_param_bound(&mut self, bounds: &'v ParamBound) {
318-
walk_ty_param_bound(self, bounds)
317+
fn visit_param_bound(&mut self, bounds: &'v ParamBound) {
318+
walk_param_bound(self, bounds)
319319
}
320320
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: TraitBoundModifier) {
321321
walk_poly_trait_ref(self, t, m)
@@ -537,13 +537,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
537537
ItemTrait(.., ref generics, ref bounds, ref trait_item_refs) => {
538538
visitor.visit_id(item.id);
539539
visitor.visit_generics(generics);
540-
walk_list!(visitor, visit_ty_param_bound, bounds);
540+
walk_list!(visitor, visit_param_bound, bounds);
541541
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
542542
}
543543
ItemTraitAlias(ref generics, ref bounds) => {
544544
visitor.visit_id(item.id);
545545
visitor.visit_generics(generics);
546-
walk_list!(visitor, visit_ty_param_bound, bounds);
546+
walk_list!(visitor, visit_param_bound, bounds);
547547
}
548548
}
549549
walk_list!(visitor, visit_attribute, &item.attrs);
@@ -731,7 +731,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v
731731
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
732732
}
733733

734-
pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBound) {
734+
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBound) {
735735
match *bound {
736736
TraitTyParamBound(ref typ, modifier) => {
737737
visitor.visit_poly_trait_ref(typ, modifier);
@@ -763,7 +763,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
763763
walk_list!(visitor, visit_attribute, attrs.iter());
764764
}
765765
}
766-
walk_list!(visitor, visit_ty_param_bound, &param.bounds);
766+
walk_list!(visitor, visit_param_bound, &param.bounds);
767767
}
768768

769769
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
@@ -782,14 +782,14 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
782782
ref bound_generic_params,
783783
..}) => {
784784
visitor.visit_ty(bounded_ty);
785-
walk_list!(visitor, visit_ty_param_bound, bounds);
785+
walk_list!(visitor, visit_param_bound, bounds);
786786
walk_list!(visitor, visit_generic_param, bound_generic_params);
787787
}
788788
&WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
789789
ref bounds,
790790
..}) => {
791791
visitor.visit_lifetime(lifetime);
792-
walk_list!(visitor, visit_lifetime, bounds);
792+
walk_list!(visitor, visit_param_bound, bounds);
793793
}
794794
&WherePredicate::EqPredicate(WhereEqPredicate{id,
795795
ref lhs_ty,
@@ -866,7 +866,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
866866
}
867867
TraitItemKind::Type(ref bounds, ref default) => {
868868
visitor.visit_id(trait_item.id);
869-
walk_list!(visitor, visit_ty_param_bound, bounds);
869+
walk_list!(visitor, visit_param_bound, bounds);
870870
walk_list!(visitor, visit_ty, default);
871871
}
872872
}

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ impl<'a> LoweringContext<'a> {
14471447
};
14481448

14491449
for bound in bounds {
1450-
hir::intravisit::walk_ty_param_bound(&mut lifetime_collector, &bound);
1450+
hir::intravisit::walk_param_bound(&mut lifetime_collector, &bound);
14511451
}
14521452

14531453
(
@@ -2125,10 +2125,7 @@ impl<'a> LoweringContext<'a> {
21252125
}) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
21262126
span,
21272127
lifetime: self.lower_lifetime(lifetime),
2128-
bounds: bounds
2129-
.iter()
2130-
.map(|bound| self.lower_lifetime(bound))
2131-
.collect(),
2128+
bounds: self.lower_param_bounds(bounds, ImplTraitContext::Disallowed),
21322129
}),
21332130
WherePredicate::EqPredicate(WhereEqPredicate {
21342131
id,

src/librustc/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ pub struct WhereBoundPredicate {
596596
pub struct WhereRegionPredicate {
597597
pub span: Span,
598598
pub lifetime: Lifetime,
599-
pub bounds: HirVec<Lifetime>,
599+
pub bounds: ParamBounds,
600600
}
601601

602602
/// An equality predicate (unsupported), e.g. `T=int`

src/librustc/hir/print.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,12 @@ impl<'a> State<'a> {
21802180
self.s.word(":")?;
21812181

21822182
for (i, bound) in bounds.iter().enumerate() {
2183-
self.print_lifetime(bound)?;
2183+
match bound {
2184+
hir::ParamBound::Outlives(lt) => {
2185+
self.print_lifetime(lt)?;
2186+
}
2187+
_ => bug!(),
2188+
}
21842189

21852190
if i != 0 {
21862191
self.s.word(":")?;

src/librustc/middle/resolve_lifetime.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
726726
this.with(scope, |_old_scope, this| {
727727
this.visit_generics(generics);
728728
for bound in bounds {
729-
this.visit_ty_param_bound(bound);
729+
this.visit_param_bound(bound);
730730
}
731731
});
732732
});
@@ -741,7 +741,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
741741
self.with(scope, |_old_scope, this| {
742742
this.visit_generics(generics);
743743
for bound in bounds {
744-
this.visit_ty_param_bound(bound);
744+
this.visit_param_bound(bound);
745745
}
746746
});
747747
}
@@ -786,7 +786,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
786786
self.with(scope, |_old_scope, this| {
787787
this.visit_generics(generics);
788788
for bound in bounds {
789-
this.visit_ty_param_bound(bound);
789+
this.visit_param_bound(bound);
790790
}
791791
if let Some(ty) = ty {
792792
this.visit_ty(ty);
@@ -882,7 +882,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
882882
match param.kind {
883883
GenericParamKind::Lifetime { .. } => {}
884884
GenericParamKind::Type { ref default, .. } => {
885-
walk_list!(self, visit_ty_param_bound, &param.bounds);
885+
walk_list!(self, visit_param_bound, &param.bounds);
886886
if let Some(ref ty) = default {
887887
self.visit_ty(&ty);
888888
}
@@ -917,13 +917,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
917917
let result = self.with(scope, |old_scope, this| {
918918
this.check_lifetime_params(old_scope, &bound_generic_params);
919919
this.visit_ty(&bounded_ty);
920-
walk_list!(this, visit_ty_param_bound, bounds);
920+
walk_list!(this, visit_param_bound, bounds);
921921
});
922922
self.trait_ref_hack = false;
923923
result
924924
} else {
925925
self.visit_ty(&bounded_ty);
926-
walk_list!(self, visit_ty_param_bound, bounds);
926+
walk_list!(self, visit_param_bound, bounds);
927927
}
928928
}
929929
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
@@ -932,9 +932,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
932932
..
933933
}) => {
934934
self.visit_lifetime(lifetime);
935-
for bound in bounds {
936-
self.visit_lifetime(bound);
937-
}
935+
walk_list!(self, visit_param_bound, bounds);
938936
}
939937
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
940938
ref lhs_ty,

src/librustc_passes/hir_stats.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
203203
hir_visit::walk_impl_item(self, ii)
204204
}
205205

206-
fn visit_ty_param_bound(&mut self, bounds: &'v hir::ParamBound) {
206+
fn visit_param_bound(&mut self, bounds: &'v hir::ParamBound) {
207207
self.record("ParamBound", Id::None, bounds);
208-
hir_visit::walk_ty_param_bound(self, bounds)
208+
hir_visit::walk_param_bound(self, bounds)
209209
}
210210

211211
fn visit_struct_field(&mut self, s: &'v hir::StructField) {
@@ -322,9 +322,9 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
322322
ast_visit::walk_impl_item(self, ii)
323323
}
324324

325-
fn visit_ty_param_bound(&mut self, bounds: &'v ast::ParamBound) {
325+
fn visit_param_bound(&mut self, bounds: &'v ast::ParamBound) {
326326
self.record("ParamBound", Id::None, bounds);
327-
ast_visit::walk_ty_param_bound(self, bounds)
327+
ast_visit::walk_param_bound(self, bounds)
328328
}
329329

330330
fn visit_struct_field(&mut self, s: &'v ast::StructField) {

src/librustc_resolve/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
815815
GenericParamKind::Lifetime { .. } => self.visit_generic_param(param),
816816
GenericParamKind::Type { ref default, .. } => {
817817
for bound in &param.bounds {
818-
self.visit_ty_param_bound(bound);
818+
self.visit_param_bound(bound);
819819
}
820820

821821
if let Some(ref ty) = default {
@@ -2076,7 +2076,7 @@ impl<'a> Resolver<'a> {
20762076
let local_def_id = this.definitions.local_def_id(item.id);
20772077
this.with_self_rib(Def::SelfTy(Some(local_def_id), None), |this| {
20782078
this.visit_generics(generics);
2079-
walk_list!(this, visit_ty_param_bound, bounds);
2079+
walk_list!(this, visit_param_bound, bounds);
20802080

20812081
for trait_item in trait_items {
20822082
this.check_proc_macro_attrs(&trait_item.attrs);
@@ -2119,7 +2119,7 @@ impl<'a> Resolver<'a> {
21192119
let local_def_id = this.definitions.local_def_id(item.id);
21202120
this.with_self_rib(Def::SelfTy(Some(local_def_id), None), |this| {
21212121
this.visit_generics(generics);
2122-
walk_list!(this, visit_ty_param_bound, bounds);
2122+
walk_list!(this, visit_param_bound, bounds);
21232123
});
21242124
});
21252125
}

src/librustc_typeck/collect.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,12 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
15121512
&hir::WherePredicate::RegionPredicate(ref region_pred) => {
15131513
let r1 = AstConv::ast_region_to_region(&icx, &region_pred.lifetime, None);
15141514
for bound in &region_pred.bounds {
1515-
let r2 = AstConv::ast_region_to_region(&icx, bound, None);
1515+
let r2 = match bound {
1516+
hir::ParamBound::Outlives(lt) => {
1517+
AstConv::ast_region_to_region(&icx, lt, None)
1518+
}
1519+
_ => bug!(),
1520+
};
15161521
let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2));
15171522
predicates.push(ty::Predicate::RegionOutlives(pred))
15181523
}

src/librustdoc/clean/auto_trait.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
486486
.iter()
487487
.flat_map(|(name, lifetime)| {
488488
let empty = Vec::new();
489-
let bounds: FxHashSet<Lifetime> = finished
490-
.get(name)
491-
.unwrap_or(&empty)
492-
.iter()
493-
.map(|region| self.get_lifetime(region, names_map))
489+
let bounds: FxHashSet<ParamBound> = finished.get(name).unwrap_or(&empty).iter()
490+
.map(|region| ParamBound::Outlives(self.get_lifetime(region, names_map)))
494491
.collect();
495492

496493
if bounds.is_empty() {
@@ -538,7 +535,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
538535
&self,
539536
ty_to_bounds: FxHashMap<Type, FxHashSet<ParamBound>>,
540537
ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
541-
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<Lifetime>>,
538+
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<ParamBound>>,
542539
) -> Vec<WherePredicate> {
543540
ty_to_bounds
544541
.into_iter()
@@ -615,7 +612,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
615612
.filter(|&(_, ref bounds)| !bounds.is_empty())
616613
.map(|(lifetime, bounds)| {
617614
let mut bounds_vec = bounds.into_iter().collect();
618-
self.sort_where_lifetimes(&mut bounds_vec);
615+
self.sort_where_bounds(&mut bounds_vec);
619616
WherePredicate::RegionPredicate {
620617
lifetime,
621618
bounds: bounds_vec,
@@ -918,14 +915,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
918915
self.unstable_debug_sort(&mut bounds);
919916
}
920917

921-
#[inline]
922-
fn sort_where_lifetimes(&self, mut bounds: &mut Vec<Lifetime>) {
923-
// We should never have identical bounds - and if we do,
924-
// they're visually identical as well. Therefore, using
925-
// an unstable sort is fine.
926-
self.unstable_debug_sort(&mut bounds);
927-
}
928-
929918
// This might look horrendously hacky, but it's actually not that bad.
930919
//
931920
// For performance reasons, we use several different FxHashMaps

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
375375
let trait_ = associated_trait.clean(cx).map(|bound| {
376376
match bound {
377377
clean::TraitBound(polyt, _) => polyt.trait_,
378-
clean::RegionBound(..) => unreachable!(),
378+
clean::Outlives(..) => unreachable!(),
379379
}
380380
});
381381
if trait_.def_id() == tcx.lang_items().deref_trait() {

0 commit comments

Comments
 (0)