From 80dbe58efc7152cc9925012de0e568f36a9893a8 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 28 May 2018 15:23:16 +0100 Subject: [PATCH] Use ParamBounds in WhereRegionPredicate --- src/librustc/hir/intravisit.rs | 18 ++++++------ src/librustc/hir/lowering.rs | 7 ++--- src/librustc/hir/mod.rs | 2 +- src/librustc/hir/print.rs | 7 ++++- src/librustc/middle/resolve_lifetime.rs | 16 +++++----- src/librustc_passes/hir_stats.rs | 8 ++--- src/librustc_resolve/lib.rs | 6 ++-- src/librustc_typeck/collect.rs | 7 ++++- src/librustdoc/clean/auto_trait.rs | 19 +++--------- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 39 ++++++++++--------------- src/librustdoc/clean/simplify.rs | 2 +- src/librustdoc/html/format.rs | 2 +- src/libsyntax/ast.rs | 2 +- src/libsyntax/parse/parser.rs | 10 +++---- src/libsyntax/print/pprust.rs | 32 ++++++++++---------- src/libsyntax/util/node_count.rs | 4 +-- src/libsyntax/visit.rs | 18 ++++++------ 18 files changed, 92 insertions(+), 109 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index d5c9d964eb2a..a550f60fb4b7 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -314,8 +314,8 @@ pub trait Visitor<'v> : Sized { fn visit_trait_ref(&mut self, t: &'v TraitRef) { walk_trait_ref(self, t) } - fn visit_ty_param_bound(&mut self, bounds: &'v ParamBound) { - walk_ty_param_bound(self, bounds) + fn visit_param_bound(&mut self, bounds: &'v ParamBound) { + walk_param_bound(self, bounds) } fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: TraitBoundModifier) { 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) { ItemTrait(.., ref generics, ref bounds, ref trait_item_refs) => { visitor.visit_id(item.id); visitor.visit_generics(generics); - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_trait_item_ref, trait_item_refs); } ItemTraitAlias(ref generics, ref bounds) => { visitor.visit_id(item.id); visitor.visit_generics(generics); - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); } } 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 walk_list!(visitor, visit_attribute, &foreign_item.attrs); } -pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBound) { +pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBound) { match *bound { TraitTyParamBound(ref typ, modifier) => { 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 walk_list!(visitor, visit_attribute, attrs.iter()); } } - walk_list!(visitor, visit_ty_param_bound, ¶m.bounds); + walk_list!(visitor, visit_param_bound, ¶m.bounds); } 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>>( ref bound_generic_params, ..}) => { visitor.visit_ty(bounded_ty); - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_generic_param, bound_generic_params); } &WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime, ref bounds, ..}) => { visitor.visit_lifetime(lifetime); - walk_list!(visitor, visit_lifetime, bounds); + walk_list!(visitor, visit_param_bound, bounds); } &WherePredicate::EqPredicate(WhereEqPredicate{id, ref lhs_ty, @@ -866,7 +866,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai } TraitItemKind::Type(ref bounds, ref default) => { visitor.visit_id(trait_item.id); - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, default); } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 494e6e1ba33b..fed4f150075b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1447,7 +1447,7 @@ impl<'a> LoweringContext<'a> { }; for bound in bounds { - hir::intravisit::walk_ty_param_bound(&mut lifetime_collector, &bound); + hir::intravisit::walk_param_bound(&mut lifetime_collector, &bound); } ( @@ -2125,10 +2125,7 @@ impl<'a> LoweringContext<'a> { }) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate { span, lifetime: self.lower_lifetime(lifetime), - bounds: bounds - .iter() - .map(|bound| self.lower_lifetime(bound)) - .collect(), + bounds: self.lower_param_bounds(bounds, ImplTraitContext::Disallowed), }), WherePredicate::EqPredicate(WhereEqPredicate { id, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 8253a34f3106..8249b306a0c3 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -596,7 +596,7 @@ pub struct WhereBoundPredicate { pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, - pub bounds: HirVec, + pub bounds: ParamBounds, } /// An equality predicate (unsupported), e.g. `T=int` diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 4058db17f2fa..10cecdb2d47a 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -2180,7 +2180,12 @@ impl<'a> State<'a> { self.s.word(":")?; for (i, bound) in bounds.iter().enumerate() { - self.print_lifetime(bound)?; + match bound { + hir::ParamBound::Outlives(lt) => { + self.print_lifetime(lt)?; + } + _ => bug!(), + } if i != 0 { self.s.word(":")?; diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 2963227c2117..fc160b35ae49 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -726,7 +726,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { this.with(scope, |_old_scope, this| { this.visit_generics(generics); for bound in bounds { - this.visit_ty_param_bound(bound); + this.visit_param_bound(bound); } }); }); @@ -741,7 +741,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { self.with(scope, |_old_scope, this| { this.visit_generics(generics); for bound in bounds { - this.visit_ty_param_bound(bound); + this.visit_param_bound(bound); } }); } @@ -786,7 +786,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { self.with(scope, |_old_scope, this| { this.visit_generics(generics); for bound in bounds { - this.visit_ty_param_bound(bound); + this.visit_param_bound(bound); } if let Some(ty) = ty { this.visit_ty(ty); @@ -882,7 +882,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { match param.kind { GenericParamKind::Lifetime { .. } => {} GenericParamKind::Type { ref default, .. } => { - walk_list!(self, visit_ty_param_bound, ¶m.bounds); + walk_list!(self, visit_param_bound, ¶m.bounds); if let Some(ref ty) = default { self.visit_ty(&ty); } @@ -917,13 +917,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { let result = self.with(scope, |old_scope, this| { this.check_lifetime_params(old_scope, &bound_generic_params); this.visit_ty(&bounded_ty); - walk_list!(this, visit_ty_param_bound, bounds); + walk_list!(this, visit_param_bound, bounds); }); self.trait_ref_hack = false; result } else { self.visit_ty(&bounded_ty); - walk_list!(self, visit_ty_param_bound, bounds); + walk_list!(self, visit_param_bound, bounds); } } &hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate { @@ -932,9 +932,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { .. }) => { self.visit_lifetime(lifetime); - for bound in bounds { - self.visit_lifetime(bound); - } + walk_list!(self, visit_param_bound, bounds); } &hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { ref lhs_ty, diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index c58b6a96ee70..879adebf7ea9 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -203,9 +203,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_impl_item(self, ii) } - fn visit_ty_param_bound(&mut self, bounds: &'v hir::ParamBound) { + fn visit_param_bound(&mut self, bounds: &'v hir::ParamBound) { self.record("ParamBound", Id::None, bounds); - hir_visit::walk_ty_param_bound(self, bounds) + hir_visit::walk_param_bound(self, bounds) } fn visit_struct_field(&mut self, s: &'v hir::StructField) { @@ -322,9 +322,9 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { ast_visit::walk_impl_item(self, ii) } - fn visit_ty_param_bound(&mut self, bounds: &'v ast::ParamBound) { + fn visit_param_bound(&mut self, bounds: &'v ast::ParamBound) { self.record("ParamBound", Id::None, bounds); - ast_visit::walk_ty_param_bound(self, bounds) + ast_visit::walk_param_bound(self, bounds) } fn visit_struct_field(&mut self, s: &'v ast::StructField) { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b51ef9044957..731c6e2ef829 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -815,7 +815,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { GenericParamKind::Lifetime { .. } => self.visit_generic_param(param), GenericParamKind::Type { ref default, .. } => { for bound in ¶m.bounds { - self.visit_ty_param_bound(bound); + self.visit_param_bound(bound); } if let Some(ref ty) = default { @@ -2076,7 +2076,7 @@ impl<'a> Resolver<'a> { let local_def_id = this.definitions.local_def_id(item.id); this.with_self_rib(Def::SelfTy(Some(local_def_id), None), |this| { this.visit_generics(generics); - walk_list!(this, visit_ty_param_bound, bounds); + walk_list!(this, visit_param_bound, bounds); for trait_item in trait_items { this.check_proc_macro_attrs(&trait_item.attrs); @@ -2119,7 +2119,7 @@ impl<'a> Resolver<'a> { let local_def_id = this.definitions.local_def_id(item.id); this.with_self_rib(Def::SelfTy(Some(local_def_id), None), |this| { this.visit_generics(generics); - walk_list!(this, visit_ty_param_bound, bounds); + walk_list!(this, visit_param_bound, bounds); }); }); } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index f95f6a26f0b9..c2b52e0de752 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1512,7 +1512,12 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, &hir::WherePredicate::RegionPredicate(ref region_pred) => { let r1 = AstConv::ast_region_to_region(&icx, ®ion_pred.lifetime, None); for bound in ®ion_pred.bounds { - let r2 = AstConv::ast_region_to_region(&icx, bound, None); + let r2 = match bound { + hir::ParamBound::Outlives(lt) => { + AstConv::ast_region_to_region(&icx, lt, None) + } + _ => bug!(), + }; let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2)); predicates.push(ty::Predicate::RegionOutlives(pred)) } diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 2686ad96c6ec..9671007a06b9 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -486,11 +486,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { .iter() .flat_map(|(name, lifetime)| { let empty = Vec::new(); - let bounds: FxHashSet = finished - .get(name) - .unwrap_or(&empty) - .iter() - .map(|region| self.get_lifetime(region, names_map)) + let bounds: FxHashSet = finished.get(name).unwrap_or(&empty).iter() + .map(|region| ParamBound::Outlives(self.get_lifetime(region, names_map))) .collect(); if bounds.is_empty() { @@ -538,7 +535,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { &self, ty_to_bounds: FxHashMap>, ty_to_fn: FxHashMap, Option)>, - lifetime_to_bounds: FxHashMap>, + lifetime_to_bounds: FxHashMap>, ) -> Vec { ty_to_bounds .into_iter() @@ -615,7 +612,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { .filter(|&(_, ref bounds)| !bounds.is_empty()) .map(|(lifetime, bounds)| { let mut bounds_vec = bounds.into_iter().collect(); - self.sort_where_lifetimes(&mut bounds_vec); + self.sort_where_bounds(&mut bounds_vec); WherePredicate::RegionPredicate { lifetime, bounds: bounds_vec, @@ -918,14 +915,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { self.unstable_debug_sort(&mut bounds); } - #[inline] - fn sort_where_lifetimes(&self, mut bounds: &mut Vec) { - // We should never have identical bounds - and if we do, - // they're visually identical as well. Therefore, using - // an unstable sort is fine. - self.unstable_debug_sort(&mut bounds); - } - // This might look horrendously hacky, but it's actually not that bad. // // For performance reasons, we use several different FxHashMaps diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index afe959aaec5a..c85178961c16 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -375,7 +375,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { let trait_ = associated_trait.clean(cx).map(|bound| { match bound { clean::TraitBound(polyt, _) => polyt.trait_, - clean::RegionBound(..) => unreachable!(), + clean::Outlives(..) => unreachable!(), } }); if trait_.def_id() == tcx.lang_items().deref_trait() { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4cc8de91baa6..2f48267579a6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1459,8 +1459,8 @@ impl Clean for [ast::Attribute] { #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] pub enum ParamBound { - RegionBound(Lifetime), - TraitBound(PolyTrait, hir::TraitBoundModifier) + TraitBound(PolyTrait, hir::TraitBoundModifier), + Outlives(Lifetime), } impl ParamBound { @@ -1510,7 +1510,7 @@ impl ParamBound { impl Clean for hir::ParamBound { fn clean(&self, cx: &DocContext) -> ParamBound { match *self { - hir::Outlives(lt) => RegionBound(lt.clean(cx)), + hir::Outlives(lt) => Outlives(lt.clean(cx)), hir::TraitTyParamBound(ref t, modifier) => TraitBound(t.clean(cx), modifier), } } @@ -1624,7 +1624,7 @@ impl<'tcx> Clean>> for Substs<'tcx> { fn clean(&self, cx: &DocContext) -> Option> { let mut v = Vec::new(); v.extend(self.regions().filter_map(|r| r.clean(cx)) - .map(RegionBound)); + .map(Outlives)); v.extend(self.types().map(|t| TraitBound(PolyTrait { trait_: t.clean(cx), generic_params: Vec::new(), @@ -1721,7 +1721,7 @@ impl Clean> for ty::RegionKind { #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] pub enum WherePredicate { BoundPredicate { ty: Type, bounds: Vec }, - RegionPredicate { lifetime: Lifetime, bounds: Vec}, + RegionPredicate { lifetime: Lifetime, bounds: Vec }, EqPredicate { lhs: Type, rhs: Type }, } @@ -1791,7 +1791,7 @@ impl<'tcx> Clean for ty::OutlivesPredicate, ty: let ty::OutlivesPredicate(ref a, ref b) = *self; WherePredicate::RegionPredicate { lifetime: a.clean(cx).unwrap(), - bounds: vec![b.clean(cx).unwrap()] + bounds: vec![ParamBound::Outlives(b.clean(cx).unwrap())] } } } @@ -1802,7 +1802,7 @@ impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region< WherePredicate::BoundPredicate { ty: ty.clean(cx), - bounds: vec![ParamBound::RegionBound(lt.clean(cx).unwrap())] + bounds: vec![ParamBound::Outlives(lt.clean(cx).unwrap())] } } } @@ -1820,9 +1820,7 @@ impl<'tcx> Clean for ty::ProjectionTy<'tcx> { fn clean(&self, cx: &DocContext) -> Type { let trait_ = match self.trait_ref(cx.tcx).clean(cx) { ParamBound::TraitBound(t, _) => t.trait_, - ParamBound::RegionBound(_) => { - panic!("cleaning a trait got a region") - } + ParamBound::Outlives(_) => panic!("cleaning a trait got a lifetime"), }; Type::QPath { name: cx.tcx.associated_item(self.item_def_id).name.clean(cx), @@ -2979,18 +2977,13 @@ impl Clean for hir::Ty { TyTraitObject(ref bounds, ref lifetime) => { match bounds[0].clean(cx).trait_ { ResolvedPath { path, typarams: None, did, is_generic } => { - let mut bounds: Vec<_> = bounds[1..].iter().map(|bound| { + let mut bounds: Vec = bounds[1..].iter().map(|bound| { TraitBound(bound.clean(cx), hir::TraitBoundModifier::None) }).collect(); if !lifetime.is_elided() { - bounds.push(RegionBound(lifetime.clean(cx))); - } - ResolvedPath { - path, - typarams: Some(bounds), - did, - is_generic, + bounds.push(self::Outlives(lifetime.clean(cx))); } + ResolvedPath { path, typarams: Some(bounds), did, is_generic, } } _ => Infer // shouldn't happen } @@ -3087,7 +3080,7 @@ impl<'tcx> Clean for Ty<'tcx> { inline::record_extern_fqn(cx, did, TypeKind::Trait); let mut typarams = vec![]; - reg.clean(cx).map(|b| typarams.push(RegionBound(b))); + reg.clean(cx).map(|b| typarams.push(Outlives(b))); for did in obj.auto_traits() { let empty = cx.tcx.intern_substs(&[]); let path = external_path(cx, &cx.tcx.item_name(did).as_str(), @@ -3144,7 +3137,7 @@ impl<'tcx> Clean for Ty<'tcx> { tr } else if let ty::Predicate::TypeOutlives(pred) = *predicate { // these should turn up at the end - pred.skip_binder().1.clean(cx).map(|r| regions.push(RegionBound(r))); + pred.skip_binder().1.clean(cx).map(|r| regions.push(Outlives(r))); return None; } else { return None; @@ -4455,8 +4448,8 @@ struct RegionDeps<'tcx> { #[derive(Eq, PartialEq, Hash, Debug)] enum SimpleBound { - RegionBound(Lifetime), - TraitBound(Vec, Vec, Vec, hir::TraitBoundModifier) + TraitBound(Vec, Vec, Vec, hir::TraitBoundModifier), + Outlives(Lifetime), } enum AutoTraitResult { @@ -4477,7 +4470,7 @@ impl AutoTraitResult { impl From for SimpleBound { fn from(bound: ParamBound) -> Self { match bound.clone() { - ParamBound::RegionBound(l) => SimpleBound::RegionBound(l), + ParamBound::Outlives(l) => SimpleBound::Outlives(l), ParamBound::TraitBound(t, mod_) => match t.trait_ { Type::ResolvedPath { path, typarams, .. } => { SimpleBound::TraitBound(path.segments, diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 81ad2a5bf51a..c7477645d6a2 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -84,7 +84,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec) -> Vec { !bounds.iter_mut().any(|b| { let trait_ref = match *b { clean::TraitBound(ref mut tr, _) => tr, - clean::RegionBound(..) => return false, + clean::Outlives(..) => return false, }; let (did, path) = match trait_ref.trait_ { clean::ResolvedPath { did, ref mut path, ..} => (did, path), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 4174f656995f..bd9194a8669f 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -270,7 +270,7 @@ impl fmt::Display for clean::PolyTrait { impl fmt::Display for clean::ParamBound { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - clean::RegionBound(ref lt) => { + clean::Outlives(ref lt) => { write!(f, "{}", *lt) } clean::TraitBound(ref ty, modifier) => { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b082cde5df7e..67679468fe42 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -393,7 +393,7 @@ pub struct WhereBoundPredicate { pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, - pub bounds: Vec, + pub bounds: ParamBounds, } /// An equality predicate (unsupported). diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ce79735fff53..66e485120659 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1610,7 +1610,7 @@ impl<'a> Parser<'a> { s.print_mutability(mut_ty.mutbl)?; s.popen()?; s.print_type(&mut_ty.ty)?; - s.print_bounds(" +", &bounds)?; + s.print_type_bounds(" +", &bounds)?; s.pclose() }); err.span_suggestion_with_applicability( @@ -4790,10 +4790,10 @@ impl<'a> Parser<'a> { // Parse bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`. // BOUND = LT_BOUND (e.g. `'a`) - fn parse_lt_param_bounds(&mut self) -> Vec { + fn parse_lt_param_bounds(&mut self) -> ParamBounds { let mut lifetimes = Vec::new(); while self.check_lifetime() { - lifetimes.push(self.expect_lifetime()); + lifetimes.push(ast::ParamBound::Outlives(self.expect_lifetime())); if !self.eat_plus() { break @@ -4868,9 +4868,7 @@ impl<'a> Parser<'a> { let lifetime = self.expect_lifetime(); // Parse lifetime parameter. let bounds = if self.eat(&token::Colon) { - self.parse_lt_param_bounds().iter() - .map(|bound| ast::ParamBound::Outlives(*bound)) - .collect() + self.parse_lt_param_bounds() } else { Vec::new() }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c8d139c7de90..c672b01fb272 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -293,7 +293,7 @@ pub fn ty_to_string(ty: &ast::Ty) -> String { } pub fn bounds_to_string(bounds: &[ast::ParamBound]) -> String { - to_string(|s| s.print_bounds("", bounds)) + to_string(|s| s.print_type_bounds("", bounds)) } pub fn pat_to_string(pat: &ast::Pat) -> String { @@ -1078,10 +1078,10 @@ impl<'a> State<'a> { } ast::TyKind::TraitObject(ref bounds, syntax) => { let prefix = if syntax == ast::TraitObjectSyntax::Dyn { "dyn" } else { "" }; - self.print_bounds(prefix, &bounds[..])?; + self.print_type_bounds(prefix, &bounds[..])?; } ast::TyKind::ImplTrait(ref bounds) => { - self.print_bounds("impl", &bounds[..])?; + self.print_type_bounds("impl", &bounds[..])?; } ast::TyKind::Array(ref ty, ref length) => { self.s.word("[")?; @@ -1184,7 +1184,7 @@ impl<'a> State<'a> { self.word_space("type")?; self.print_ident(ident)?; if let Some(bounds) = bounds { - self.print_bounds(":", bounds)?; + self.print_type_bounds(":", bounds)?; } if let Some(ty) = ty { self.s.space()?; @@ -1373,7 +1373,7 @@ impl<'a> State<'a> { real_bounds.push(b.clone()); } } - self.print_bounds(":", &real_bounds[..])?; + self.print_type_bounds(":", &real_bounds[..])?; self.print_where_clause(&generics.where_clause)?; self.s.word(" ")?; self.bopen()?; @@ -1400,7 +1400,7 @@ impl<'a> State<'a> { } } self.nbsp()?; - self.print_bounds("=", &real_bounds[..])?; + self.print_type_bounds("=", &real_bounds[..])?; self.print_where_clause(&generics.where_clause)?; self.s.word(";")?; } @@ -2809,7 +2809,7 @@ impl<'a> State<'a> { } } - pub fn print_bounds(&mut self, + pub fn print_type_bounds(&mut self, prefix: &str, bounds: &[ast::ParamBound]) -> io::Result<()> { @@ -2851,7 +2851,7 @@ impl<'a> State<'a> { pub fn print_lifetime_bounds(&mut self, lifetime: &ast::Lifetime, - bounds: &[ast::Lifetime]) + bounds: &ast::ParamBounds) -> io::Result<()> { self.print_lifetime(lifetime)?; @@ -2861,7 +2861,10 @@ impl<'a> State<'a> { if i != 0 { self.s.word(" + ")?; } - self.print_lifetime(bound)?; + match bound { + ast::ParamBound::Outlives(lt) => self.print_lifetime(lt)?, + _ => panic!(), + } } } Ok(()) @@ -2881,17 +2884,12 @@ impl<'a> State<'a> { match param.kind { ast::GenericParamKind::Lifetime { ref lifetime } => { s.print_outer_attributes_inline(¶m.attrs)?; - s.print_lifetime_bounds(lifetime, ¶m.bounds.iter().map(|bound| { - match bound { - ast::ParamBound::Outlives(lt) => *lt, - _ => panic!(), - } - }).collect::>().as_slice()) + s.print_lifetime_bounds(lifetime, ¶m.bounds) }, ast::GenericParamKind::Type { ref default } => { s.print_outer_attributes_inline(¶m.attrs)?; s.print_ident(param.ident)?; - s.print_bounds(":", ¶m.bounds)?; + s.print_type_bounds(":", ¶m.bounds)?; match default { Some(ref default) => { s.s.space()?; @@ -2931,7 +2929,7 @@ impl<'a> State<'a> { }) => { self.print_formal_generic_params(bound_generic_params)?; self.print_type(bounded_ty)?; - self.print_bounds(":", bounds)?; + self.print_type_bounds(":", bounds)?; } ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, ref bounds, diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index 485775765abf..2d92f4b9531a 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -95,9 +95,9 @@ impl<'ast> Visitor<'ast> for NodeCounter { self.count += 1; walk_trait_ref(self, t) } - fn visit_ty_param_bound(&mut self, bounds: &ParamBound) { + fn visit_param_bound(&mut self, bounds: &ParamBound) { self.count += 1; - walk_ty_param_bound(self, bounds) + walk_param_bound(self, bounds) } fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) { self.count += 1; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 4e0c417d4fba..1d535ab6bf0c 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -86,8 +86,8 @@ pub trait Visitor<'ast>: Sized { fn visit_trait_item(&mut self, ti: &'ast TraitItem) { walk_trait_item(self, ti) } fn visit_impl_item(&mut self, ii: &'ast ImplItem) { walk_impl_item(self, ii) } fn visit_trait_ref(&mut self, t: &'ast TraitRef) { walk_trait_ref(self, t) } - fn visit_ty_param_bound(&mut self, bounds: &'ast ParamBound) { - walk_ty_param_bound(self, bounds) + fn visit_param_bound(&mut self, bounds: &'ast ParamBound) { + walk_param_bound(self, bounds) } fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) { walk_poly_trait_ref(self, t, m) @@ -276,12 +276,12 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { } ItemKind::Trait(.., ref generics, ref bounds, ref methods) => { visitor.visit_generics(generics); - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_trait_item, methods); } ItemKind::TraitAlias(ref generics, ref bounds) => { visitor.visit_generics(generics); - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); } ItemKind::Mac(ref mac) => visitor.visit_mac(mac), ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id), @@ -341,7 +341,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { } TyKind::TraitObject(ref bounds, ..) | TyKind::ImplTrait(ref bounds) => { - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); } TyKind::Typeof(ref expression) => { visitor.visit_anon_const(expression) @@ -479,7 +479,7 @@ pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) { // Empty! } -pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a ParamBound) { +pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a ParamBound) { match *bound { TraitTyParamBound(ref typ, ref modifier) => { visitor.visit_poly_trait_ref(typ, modifier); @@ -517,14 +517,14 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a ref bound_generic_params, ..}) => { visitor.visit_ty(bounded_ty); - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_generic_param, bound_generic_params); } WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime, ref bounds, ..}) => { visitor.visit_lifetime(lifetime); - walk_list!(visitor, visit_lifetime, bounds); + walk_list!(visitor, visit_param_bound, bounds); } WherePredicate::EqPredicate(WhereEqPredicate{ref lhs_ty, ref rhs_ty, @@ -585,7 +585,7 @@ pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a Trai &sig.decl, trait_item.span, trait_item.id); } TraitItemKind::Type(ref bounds, ref default) => { - walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, default); } TraitItemKind::Macro(ref mac) => {