diff options
| author | varkor <github@varkor.com> | 2018-05-28 15:23:16 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-06-20 12:23:07 +0100 |
| commit | 80dbe58efc7152cc9925012de0e568f36a9893a8 (patch) | |
| tree | e89f04a4b5be6b90df921ecc4506ab1e604438ea /src/libsyntax | |
| parent | aed530a457dd937fa633dfe52cf07811196d3173 (diff) | |
| download | rust-80dbe58efc7152cc9925012de0e568f36a9893a8.tar.gz rust-80dbe58efc7152cc9925012de0e568f36a9893a8.zip | |
Use ParamBounds in WhereRegionPredicate
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 32 | ||||
| -rw-r--r-- | src/libsyntax/util/node_count.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 18 |
5 files changed, 31 insertions, 35 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b082cde5df7..67679468fe4 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<Lifetime>, + pub bounds: ParamBounds, } /// An equality predicate (unsupported). diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ce79735fff5..66e48512065 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<Lifetime> { + 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 c8d139c7de9..c672b01fb27 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::<Vec<_>>().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 485775765ab..2d92f4b9531 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 4e0c417d4fb..1d535ab6bf0 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) => { |
