From 494859e8dde5080534e94aba6d98affb921552f8 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 8 Feb 2018 08:58:13 +0000 Subject: Consolidate PathParameters and AngleBracketedParameterData --- src/libsyntax/parse/parser.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1735951da2f..c205e937611 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -22,6 +22,7 @@ use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; use ast::GenericParam; +use ast::GenericAngleBracketedParam; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind}; use ast::Local; @@ -1971,10 +1972,10 @@ impl<'a> Parser<'a> { let parameters = if self.eat_lt() { // `<'a, T, A = U>` - let (lifetimes, types, bindings) = self.parse_generic_args()?; + let (parameters, bindings) = self.parse_generic_args()?; self.expect_gt()?; let span = lo.to(self.prev_span); - AngleBracketedParameterData { lifetimes, types, bindings, span }.into() + AngleBracketedParameterData { parameters, bindings, span }.into() } else { // `(T, U) -> R` self.bump(); // `(` @@ -4936,16 +4937,16 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings, /// possibly including trailing comma. - fn parse_generic_args(&mut self) -> PResult<'a, (Vec, Vec>, Vec)> { - let mut lifetimes = Vec::new(); - let mut types = Vec::new(); + fn parse_generic_args(&mut self) + -> PResult<'a, (Vec, Vec)> { + let mut parameters = Vec::new(); let mut bindings = Vec::new(); let mut seen_type = false; let mut seen_binding = false; loop { if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { // Parse lifetime argument. - lifetimes.push(self.expect_lifetime()); + parameters.push(GenericAngleBracketedParam::Lifetime(self.expect_lifetime())); if seen_type || seen_binding { self.span_err(self.prev_span, "lifetime parameters must be declared prior to type parameters"); @@ -4965,11 +4966,12 @@ impl<'a> Parser<'a> { seen_binding = true; } else if self.check_type() { // Parse type argument. - types.push(self.parse_ty()?); + let ty_param = self.parse_ty()?; if seen_binding { - self.span_err(types[types.len() - 1].span, + self.span_err(ty_param.span, "type parameters must be declared prior to associated type bindings"); } + parameters.push(GenericAngleBracketedParam::Type(ty_param)); seen_type = true; } else { break @@ -4979,7 +4981,7 @@ impl<'a> Parser<'a> { break } } - Ok((lifetimes, types, bindings)) + Ok((parameters, bindings)) } /// Parses an optional `where` clause and places it in `generics`. -- cgit 1.4.1-3-g733a5 From 1ed60a9173ab5b757adf239269e3aa91d30abf54 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 12 Feb 2018 21:44:05 +0000 Subject: Rename *Parameter to *Param --- src/librustc/hir/lowering.rs | 24 ++++++++++++------------ src/librustc/hir/mod.rs | 8 ++++---- src/librustc/hir/print.rs | 12 ++++++++---- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/ty/mod.rs | 16 ++++++++-------- src/librustc_typeck/astconv.rs | 4 ++-- src/librustc_typeck/collect.rs | 10 +++++----- src/librustdoc/clean/mod.rs | 6 +++--- src/libsyntax/ast.rs | 8 ++++---- src/libsyntax/ext/build.rs | 10 +++++----- src/libsyntax/fold.rs | 14 +++++++------- src/libsyntax/parse/parser.rs | 8 ++++---- src/libsyntax/print/pprust.rs | 8 ++++---- src/libsyntax_ext/deriving/clone.rs | 4 ++-- src/libsyntax_ext/deriving/cmp/eq.rs | 4 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 6 +++--- src/libsyntax_ext/deriving/generic/ty.rs | 10 +++++----- src/libsyntax_ext/env.rs | 4 ++-- 18 files changed, 81 insertions(+), 77 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 8e66ce3fd18..fd914f9f62b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -46,7 +46,7 @@ use hir::HirVec; use hir::map::{DefKey, DefPathData, Definitions}; use hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX}; use hir::def::{Def, PathResolution, PerNS}; -use hir::GenericPathParam; +use hir::PathParam; use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES}; use middle::cstore::CrateStore; use rustc_data_structures::indexed_vec::IndexVec; @@ -1038,16 +1038,16 @@ impl<'a> LoweringContext<'a> { } } - fn lower_param(&mut self, - p: &GenericAngleBracketedParam, - itctx: ImplTraitContext) - -> GenericPathParam { + fn lower_path_param(&mut self, + p: &AngleBracketedParam, + itctx: ImplTraitContext) + -> PathParam { match p { - GenericAngleBracketedParam::Lifetime(lt) => { - GenericPathParam::Lifetime(self.lower_lifetime(<)) + AngleBracketedParam::Lifetime(lt) => { + PathParam::Lifetime(self.lower_lifetime(<)) } - GenericAngleBracketedParam::Type(ty) => { - GenericPathParam::Type(self.lower_ty(&ty, itctx)) + AngleBracketedParam::Type(ty) => { + PathParam::Type(self.lower_ty(&ty, itctx)) } } } @@ -1715,7 +1715,7 @@ impl<'a> LoweringContext<'a> { if !parameters.parenthesized && parameters.lifetimes.is_empty() { path_params.parameters = (0..expected_lifetimes).map(|_| { - GenericPathParam::Lifetime(self.elided_lifetime(path_span)) + PathParam::Lifetime(self.elided_lifetime(path_span)) }).chain(path_params.parameters.into_iter()).collect(); } @@ -1734,7 +1734,7 @@ impl<'a> LoweringContext<'a> { ) -> (hir::PathParameters, bool) { let &AngleBracketedParameterData { ref parameters, ref bindings, .. } = data; (hir::PathParameters { - parameters: parameters.iter().map(|p| self.lower_param(p, itctx)).collect(), + parameters: parameters.iter().map(|p| self.lower_path_param(p, itctx)).collect(), bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(), parenthesized: false, }, @@ -1775,7 +1775,7 @@ impl<'a> LoweringContext<'a> { ( hir::PathParameters { - parameters: hir_vec![GenericPathParam::Type(mk_tup(this, inputs, span))], + parameters: hir_vec![PathParam::Type(mk_tup(this, inputs, span))], bindings: hir_vec![ hir::TypeBinding { id: this.next_id().node_id, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index e69b824e779..455e64351e1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -373,7 +373,7 @@ impl PathSegment { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum GenericPathParam { +pub enum PathParam { Lifetime(Lifetime), Type(P), } @@ -381,7 +381,7 @@ pub enum GenericPathParam { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct PathParameters { /// The generic parameters for this path segment. - pub parameters: HirVec, + pub parameters: HirVec, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo`. pub bindings: HirVec, @@ -417,7 +417,7 @@ impl PathParameters { pub fn lifetimes(&self) -> Vec<&Lifetime> { self.parameters.iter().filter_map(|p| { - if let GenericPathParam::Lifetime(lt) = p { + if let PathParam::Lifetime(lt) = p { Some(lt) } else { None @@ -427,7 +427,7 @@ impl PathParameters { pub fn types(&self) -> Vec<&P> { self.parameters.iter().filter_map(|p| { - if let GenericPathParam::Type(ty) = p { + if let PathParam::Type(ty) = p { Some(ty) } else { None diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 9e3c103b978..6f4a9dd5929 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -25,7 +25,7 @@ use syntax_pos::{self, BytePos, FileName}; use hir; use hir::{PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier, RangeEnd}; -use hir::GenericPathParam; +use hir::PathParam; use std::cell::Cell; use std::io::{self, Write, Read}; @@ -1732,7 +1732,7 @@ impl<'a> State<'a> { }; let elide_lifetimes = path_params.parameters.iter().all(|p| { - if let GenericPathParam::Lifetime(lt) = p { + if let PathParam::Lifetime(lt) = p { if !lt.is_elided() { return false; } @@ -1742,17 +1742,21 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &path_params.parameters, |s, p| { match p { - GenericPathParam::Lifetime(lt) => { + PathParam::Lifetime(lt) => { if !elide_lifetimes { s.print_lifetime(lt) } else { Ok(()) } } - GenericPathParam::Type(ty) => s.print_type(ty), + PathParam::Type(ty) => s.print_type(ty), } })?; + if !path_params.parameters.is_empty() { + empty.set(false); + } + // FIXME(eddyb) This would leak into error messages, e.g.: // "non-exhaustive patterns: `Some::<..>(_)` not covered". if infer_types && false { diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 54e6989d55a..ee139412853 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -180,7 +180,7 @@ impl_stable_hash_for!(struct hir::PathSegment { parameters }); -impl_stable_hash_for!(enum hir::GenericPathParam { +impl_stable_hash_for!(enum hir::PathParam { Lifetime(lt), Type(ty) }); diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index d09be8e5c45..9e0f98772bf 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -886,16 +886,16 @@ pub struct GenericParamCount { } #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub enum GenericParameterDef { +pub enum GenericParam { Lifetime(RegionParameterDef), Type(TypeParameterDef), } -impl GenericParameterDef { +impl GenericParam { pub fn index(&self) -> u32 { match self { - GenericParameterDef::Lifetime(lt) => lt.index, - GenericParameterDef::Type(ty) => ty.index, + GenericParam::Lifetime(lt) => lt.index, + GenericParam::Type(ty) => ty.index, } } } @@ -1011,7 +1011,7 @@ impl<'a, 'gcx, 'tcx> Generics { pub fn lifetimes(&self) -> Vec<&RegionParameterDef> { self.parameters.iter().filter_map(|p| { - if let GenericParameterDef::Lifetime(lt) = p { + if let GenericParam::Lifetime(lt) = p { Some(lt) } else { None @@ -1021,7 +1021,7 @@ impl<'a, 'gcx, 'tcx> Generics { pub fn types(&self) -> Vec<&TypeParameterDef> { self.parameters.iter().filter_map(|p| { - if let GenericParameterDef::Type(ty) = p { + if let GenericParam::Type(ty) = p { Some(ty) } else { None @@ -1030,11 +1030,11 @@ impl<'a, 'gcx, 'tcx> Generics { } pub fn parent_lifetimes(&self) -> u32 { - *self.parent_parameters.get(KindIndex::Lifetime) + *self.parent_params.get(KindIndex::Lifetime) } pub fn parent_types(&self) -> u32 { - *self.parent_parameters.get(KindIndex::Type) + *self.parent_params.get(KindIndex::Type) } pub fn region_param(&'tcx self, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 005d088c478..a9d97df4613 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -973,13 +973,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { segment.with_parameters(|params| { for p in ¶ms.parameters { let (mut span_err, span, kind) = match p { - hir::GenericPathParam::Lifetime(lt) => { + hir::PathParam::Lifetime(lt) => { (struct_span_err!(self.tcx().sess, lt.span, E0110, "lifetime parameters are not allowed on this type"), lt.span, "lifetime") } - hir::GenericPathParam::Type(ty) => { + hir::PathParam::Type(ty) => { (struct_span_err!(self.tcx().sess, ty.span, E0109, "type parameters are not allowed on this type"), ty.span, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 6e323e5913a..70367dd2461 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -973,11 +973,11 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, .map(|param| (param.def_id, param.index)) .collect(); - let parent_parameters = ty::KindIndexed { lt: parent_regions, ty: parent_types }; - let lifetimes: Vec = - regions.into_iter().map(|lt| ty::GenericParameterDef::Lifetime(lt)).collect(); - let types: Vec = - types.into_iter().map(|ty| ty::GenericParameterDef::Type(ty)).collect(); + let parent_params = ty::KindIndexed { lt: parent_regions, ty: parent_types }; + let lifetimes: Vec = + regions.into_iter().map(|lt| ty::GenericParam::Lifetime(lt)).collect(); + let types: Vec = + types.into_iter().map(|ty| ty::GenericParam::Type(ty)).collect(); let parameters = lifetimes.into_iter().chain(types.into_iter()).collect(); tcx.alloc_generics(ty::Generics { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 852a4479199..b886b31a08b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3494,12 +3494,12 @@ impl Clean for hir::PathParameters { } } else { PathParameters::AngleBracketed { - lifetimes: if self.lifetimes.iter().all(|lt| lt.is_elided()) { + lifetimes: if self.lifetimes().iter().all(|lt| lt.is_elided()) { vec![] } else { - self.lifetimes.clean(cx) + self.lifetimes().iter().map(|lp| lp.clean(cx)).collect() }, - types: self.types.clean(cx), + types: self.types().iter().map(|tp| tp.clean(cx)).collect(), bindings: self.bindings.clean(cx), } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 1af4743cfe4..9a05c5c063a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -168,7 +168,7 @@ impl PathParameters { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum GenericAngleBracketedParam { +pub enum AngleBracketedParam { Lifetime(Lifetime), Type(P), } @@ -179,7 +179,7 @@ pub struct AngleBracketedParameterData { /// Overall span pub span: Span, /// The parameters for this path segment. - pub parameters: Vec, + pub parameters: Vec, /// Bindings (equality constraints) on associated types, if present. /// /// E.g., `Foo`. @@ -189,7 +189,7 @@ pub struct AngleBracketedParameterData { impl AngleBracketedParameterData { pub fn lifetimes(&self) -> Vec<&Lifetime> { self.parameters.iter().filter_map(|p| { - if let GenericAngleBracketedParam::Lifetime(lt) = p { + if let AngleBracketedParam::Lifetime(lt) = p { Some(lt) } else { None @@ -199,7 +199,7 @@ impl AngleBracketedParameterData { pub fn types(&self) -> Vec<&P> { self.parameters.iter().filter_map(|p| { - if let GenericAngleBracketedParam::Type(ty) = p { + if let AngleBracketedParam::Type(ty) = p { Some(ty) } else { None diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 02112517827..a59e34580c0 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -31,7 +31,7 @@ pub trait AstBuilder { fn path_all(&self, sp: Span, global: bool, idents: Vec, - parameters: Vec, + parameters: Vec, bindings: Vec) -> ast::Path; @@ -42,7 +42,7 @@ pub trait AstBuilder { fn qpath_all(&self, self_type: P, trait_path: ast::Path, ident: ast::Ident, - parameters: Vec, + parameters: Vec, bindings: Vec) -> (ast::QSelf, ast::Path); @@ -314,7 +314,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, global: bool, mut idents: Vec , - parameters: Vec, + parameters: Vec, bindings: Vec ) -> ast::Path { let last_ident = idents.pop().unwrap(); @@ -356,7 +356,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self_type: P, trait_path: ast::Path, ident: ast::Ident, - parameters: Vec, + parameters: Vec, bindings: Vec) -> (ast::QSelf, ast::Path) { let mut path = trait_path; @@ -424,7 +424,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.path_all(DUMMY_SP, true, self.std_path(&["option", "Option"]), - vec![ ast::GenericAngleBracketedParam::Type(ty) ], + vec![ ast::AngleBracketedParam::Type(ty) ], Vec::new())) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index b935425cdd4..fc70ee9c38f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -132,7 +132,7 @@ pub trait Folder : Sized { noop_fold_exprs(es, self) } - fn fold_param(&mut self, p: GenericAngleBracketedParam) -> GenericAngleBracketedParam { + fn fold_param(&mut self, p: AngleBracketedParam) -> AngleBracketedParam { noop_fold_param(p, self) } @@ -357,15 +357,15 @@ pub fn noop_fold_ty_binding(b: TypeBinding, fld: &mut T) -> TypeBindi } } -pub fn noop_fold_param(p: GenericAngleBracketedParam, +pub fn noop_fold_param(p: AngleBracketedParam, fld: &mut T) - -> GenericAngleBracketedParam { + -> AngleBracketedParam { match p { - GenericAngleBracketedParam::Lifetime(lt) => { - GenericAngleBracketedParam::Lifetime(noop_fold_lifetime(lt, fld)) + AngleBracketedParam::Lifetime(lt) => { + AngleBracketedParam::Lifetime(noop_fold_lifetime(lt, fld)) } - GenericAngleBracketedParam::Type(ty) => { - GenericAngleBracketedParam::Type(noop_fold_ty(ty, fld)) + AngleBracketedParam::Type(ty) => { + AngleBracketedParam::Type(noop_fold_ty(ty, fld)) } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c205e937611..e54c5445fa2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -22,7 +22,7 @@ use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; use ast::GenericParam; -use ast::GenericAngleBracketedParam; +use ast::AngleBracketedParam; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind}; use ast::Local; @@ -4938,7 +4938,7 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings, /// possibly including trailing comma. fn parse_generic_args(&mut self) - -> PResult<'a, (Vec, Vec)> { + -> PResult<'a, (Vec, Vec)> { let mut parameters = Vec::new(); let mut bindings = Vec::new(); let mut seen_type = false; @@ -4946,7 +4946,7 @@ impl<'a> Parser<'a> { loop { if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { // Parse lifetime argument. - parameters.push(GenericAngleBracketedParam::Lifetime(self.expect_lifetime())); + parameters.push(AngleBracketedParam::Lifetime(self.expect_lifetime())); if seen_type || seen_binding { self.span_err(self.prev_span, "lifetime parameters must be declared prior to type parameters"); @@ -4971,7 +4971,7 @@ impl<'a> Parser<'a> { self.span_err(ty_param.span, "type parameters must be declared prior to associated type bindings"); } - parameters.push(GenericAngleBracketedParam::Type(ty_param)); + parameters.push(AngleBracketedParam::Type(ty_param)); seen_type = true; } else { break diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index dc204e3d0ef..282b5dd545a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -13,7 +13,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::{self, Abi}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Attribute, MacDelimiter, GenericAngleBracketedParam}; +use ast::{Attribute, MacDelimiter, AngleBracketedParam}; use util::parser::{self, AssocOp, Fixity}; use attr; use codemap::{self, CodeMap}; @@ -1017,10 +1017,10 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_param(&mut self, param: &GenericAngleBracketedParam) -> io::Result<()> { + pub fn print_param(&mut self, param: &AngleBracketedParam) -> io::Result<()> { match param { - GenericAngleBracketedParam::Lifetime(lt) => self.print_lifetime(lt), - GenericAngleBracketedParam::Type(ty) => self.print_type(ty), + AngleBracketedParam::Lifetime(lt) => self.print_lifetime(lt), + AngleBracketedParam::Type(ty) => self.print_type(ty), } } diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 3a83922bc90..2e0551b32f7 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -13,7 +13,7 @@ use deriving::generic::*; use deriving::generic::ty::*; use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; -use syntax::ast::GenericAngleBracketedParam; +use syntax::ast::AngleBracketedParam; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -124,7 +124,7 @@ fn cs_clone_shallow(name: &str, let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["clone", helper_name]), - vec![GenericAngleBracketedParam::Type(ty)], vec![]); + vec![AngleBracketedParam::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &VariantData) { diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index 61b7e5b482d..51ab9975ed9 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, Expr, MetaItem, GenericAngleBracketedParam}; +use syntax::ast::{self, Expr, MetaItem, AngleBracketedParam}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -62,7 +62,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["cmp", helper_name]), - vec![GenericAngleBracketedParam::Type(ty)], vec![]); + vec![AngleBracketedParam::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &ast::VariantData) { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 7ab0acda408..a7bb7ba025f 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -193,7 +193,7 @@ use std::vec; use rustc_target::spec::abi::Abi; use syntax::ast::{self, BinOpKind, EnumDef, Expr, GenericParam, Generics, Ident, PatKind}; -use syntax::ast::{VariantData, GenericAngleBracketedParam}; +use syntax::ast::{VariantData, AngleBracketedParam}; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -683,9 +683,9 @@ impl<'a> TraitDef<'a> { .collect(); let self_params = self_lifetimes.into_iter() - .map(|lt| GenericAngleBracketedParam::Lifetime(lt)) + .map(|lt| AngleBracketedParam::Lifetime(lt)) .chain(self_ty_params.into_iter().map(|ty| - GenericAngleBracketedParam::Type(ty))) + AngleBracketedParam::Type(ty))) .collect(); // Create the type of `self`. diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 6387f2d8d98..d6ee7759ae6 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -15,7 +15,7 @@ pub use self::PtrTy::*; pub use self::Ty::*; use syntax::ast; -use syntax::ast::{Expr, GenericParam, Generics, Ident, SelfKind, GenericAngleBracketedParam}; +use syntax::ast::{Expr, GenericParam, Generics, Ident, SelfKind, AngleBracketedParam}; use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::codemap::{respan, DUMMY_SP}; @@ -89,8 +89,8 @@ impl<'a> Path<'a> { let tys: Vec> = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect(); let params = lt.into_iter() - .map(|lt| GenericAngleBracketedParam::Lifetime(lt)) - .chain(tys.into_iter().map(|ty| GenericAngleBracketedParam::Type(ty))) + .map(|lt| AngleBracketedParam::Lifetime(lt)) + .chain(tys.into_iter().map(|ty| AngleBracketedParam::Type(ty))) .collect(); match self.kind { @@ -206,9 +206,9 @@ impl<'a> Ty<'a> { .collect(); let params = lifetimes.into_iter() - .map(|lt| GenericAngleBracketedParam::Lifetime(lt)) + .map(|lt| AngleBracketedParam::Lifetime(lt)) .chain(ty_params.into_iter().map(|ty| - GenericAngleBracketedParam::Type(ty))) + AngleBracketedParam::Type(ty))) .collect(); cx.path_all(span, diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index c904cfcfdbf..78721d880fc 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -13,7 +13,7 @@ // interface. // -use syntax::ast::{self, Ident, GenericAngleBracketedParam}; +use syntax::ast::{self, Ident, AngleBracketedParam}; use syntax::ext::base::*; use syntax::ext::base; use syntax::ext::build::AstBuilder; @@ -39,7 +39,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, cx.expr_path(cx.path_all(sp, true, cx.std_path(&["option", "Option", "None"]), - vec![GenericAngleBracketedParam::Type(cx.ty_rptr(sp, + vec![AngleBracketedParam::Type(cx.ty_rptr(sp, cx.ty_ident(sp, Ident::from_str("str")), Some(lt), ast::Mutability::Immutable)], -- cgit 1.4.1-3-g733a5 From 76c0d687453cb1da2e76a1c8e007ac080f8aa0d7 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 23 Feb 2018 17:48:54 +0000 Subject: Rename "parameter" to "arg" --- src/librustc/hir/intravisit.rs | 6 +- src/librustc/hir/lowering.rs | 47 ++++++-------- src/librustc/hir/mod.rs | 30 ++++----- src/librustc/hir/print.rs | 18 +++--- src/librustc/ich/impls_hir.rs | 4 +- src/librustc/middle/resolve_lifetime.rs | 34 +++++----- src/librustc/ty/instance.rs | 1 + src/librustc/ty/mod.rs | 95 ---------------------------- src/librustc_codegen_llvm/base.rs | 1 + src/librustc_driver/pretty.rs | 2 +- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_mir/monomorphize/mod.rs | 1 + src/librustc_passes/ast_validation.rs | 20 +++--- src/librustc_resolve/macros.rs | 4 +- src/librustc_save_analysis/dump_visitor.rs | 10 +-- src/librustc_save_analysis/lib.rs | 4 +- src/librustc_typeck/astconv.rs | 28 ++++---- src/librustc_typeck/check/method/confirm.rs | 9 ++- src/librustc_typeck/check/mod.rs | 6 +- src/librustc_typeck/collect.rs | 7 -- src/librustdoc/clean/auto_trait.rs | 36 +++++------ src/librustdoc/clean/mod.rs | 26 ++++---- src/librustdoc/clean/simplify.rs | 2 +- src/librustdoc/html/format.rs | 10 +-- src/libsyntax/ast.rs | 34 +++++----- src/libsyntax/ext/build.rs | 22 +++---- src/libsyntax/fold.rs | 38 +++++------ src/libsyntax/parse/parser.rs | 30 ++++----- src/libsyntax/print/pprust.rs | 28 ++++---- src/libsyntax/visit.rs | 12 ++-- src/libsyntax_ext/deriving/clone.rs | 4 +- src/libsyntax_ext/deriving/cmp/eq.rs | 4 +- src/libsyntax_ext/deriving/generic/mod.rs | 6 +- src/libsyntax_ext/deriving/generic/ty.rs | 10 +-- src/libsyntax_ext/env.rs | 6 +- 35 files changed, 242 insertions(+), 355 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 9b5b53e891b..fef33939fac 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -648,15 +648,15 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, path_span: Span, segment: &'v PathSegment) { visitor.visit_name(path_span, segment.name); - if let Some(ref parameters) = segment.parameters { - visitor.visit_generic_args(path_span, parameters); + if let Some(ref args) = segment.args { + visitor.visit_generic_args(path_span, args); } } pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, _path_span: Span, generic_args: &'v GenericArgs) { - walk_list!(visitor, visit_generic_arg, &generic_args.parameters); + walk_list!(visitor, visit_generic_arg, &generic_args.args); walk_list!(visitor, visit_assoc_type_binding, &generic_args.bindings); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 4b090e88c40..831a689a349 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -59,6 +59,7 @@ use std::fmt::Debug; use std::iter; use std::mem; use syntax::attr; +use syntax::ast; use syntax::ast::*; use syntax::errors; use syntax::ext::hygiene::{Mark, SyntaxContext}; @@ -1039,14 +1040,14 @@ impl<'a> LoweringContext<'a> { } fn lower_generic_arg(&mut self, - p: &AngleBracketedParam, + p: &ast::GenericArg, itctx: ImplTraitContext) - -> GenericArg { + -> hir::GenericArg { match p { - AngleBracketedParam::Lifetime(lt) => { + ast::GenericArg::Lifetime(lt) => { GenericArg::Lifetime(self.lower_lifetime(<)) } - AngleBracketedParam::Type(ty) => { + ast::GenericArg::Type(ty) => { GenericArg::Type(self.lower_ty(&ty, itctx)) } } @@ -1684,8 +1685,7 @@ impl<'a> LoweringContext<'a> { parenthesized_generic_args: ParenthesizedGenericArgs, itctx: ImplTraitContext, ) -> hir::PathSegment { - let (mut generic_args, infer_types) = - if let Some(ref generic_args) = segment.parameters { + let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args { let msg = "parenthesized parameters may only be used with a trait"; match **generic_args { GenericArgs::AngleBracketed(ref data) => { @@ -1715,13 +1715,16 @@ impl<'a> LoweringContext<'a> { }; if !generic_args.parenthesized && generic_args.lifetimes().count() == 0 { - generic_args.parameters = (0..expected_lifetimes).map(|_| { - GenericArg::Lifetime(self.elided_lifetime(path_span)) - }).chain(generic_args.parameters.into_iter()).collect(); + generic_args.args = + self.elided_path_lifetimes(path_span, expected_lifetimes) + .into_iter() + .map(|lt| GenericArg::Lifetime(lt)) + .chain(generic_args.args.into_iter()) + .collect(); } hir::PathSegment::new( - self.lower_ident(segment.identifier), + self.lower_ident(segment.ident), generic_args, infer_types ) @@ -1729,13 +1732,13 @@ impl<'a> LoweringContext<'a> { fn lower_angle_bracketed_parameter_data( &mut self, - data: &AngleBracketedParameterData, + data: &AngleBracketedArgs, param_mode: ParamMode, itctx: ImplTraitContext, ) -> (hir::GenericArgs, bool) { - let &AngleBracketedParameterData { ref parameters, ref bindings, .. } = data; + let &AngleBracketedArgs { ref args, ref bindings, .. } = data; (hir::GenericArgs { - parameters: parameters.iter().map(|p| self.lower_generic_arg(p, itctx)).collect(), + args: args.iter().map(|p| self.lower_generic_arg(p, itctx)).collect(), bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(), parenthesized: false, }, @@ -1755,23 +1758,11 @@ impl<'a> LoweringContext<'a> { AnonymousLifetimeMode::PassThrough, |this| { const DISALLOWED: ImplTraitContext = ImplTraitContext::Disallowed; - let &ParenthesizedParameterData { - ref inputs, - ref output, - span, - } = data; - let inputs = inputs - .iter() - .map(|ty| this.lower_ty(ty, DISALLOWED)) - .collect(); + let &ParenthesizedParameterData { ref inputs, ref output, span } = data; + let inputs = inputs.iter().map(|ty| this.lower_ty(ty, DISALLOWED)).collect(); let mk_tup = |this: &mut Self, tys, span| { let LoweredNodeId { node_id, hir_id } = this.next_id(); - P(hir::Ty { - node: hir::TyTup(tys), - id: node_id, - hir_id, - span, - }) + P(hir::Ty { node: hir::TyTup(tys), id: node_id, hir_id, span }) }; ( diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 38a894df3cd..729ac17ae09 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -327,7 +327,7 @@ pub struct PathSegment { /// this is more than just simple syntactic sugar; the use of /// parens affects the region binding rules, so we preserve the /// distinction. - pub parameters: Option>, + pub args: Option>, /// Whether to infer remaining type parameters, if any. /// This only applies to expression and pattern paths, and @@ -342,30 +342,30 @@ impl PathSegment { PathSegment { name, infer_types: true, - parameters: None + args: None, } } - pub fn new(name: Name, parameters: GenericArgs, infer_types: bool) -> Self { + pub fn new(name: Name, args: GenericArgs, infer_types: bool) -> Self { PathSegment { name, infer_types, - parameters: if parameters.is_empty() { + args: if args.is_empty() { None } else { - Some(P(parameters)) + Some(P(args)) } } } // FIXME: hack required because you can't create a static // GenericArgs, so you can't just return a &GenericArgs. - pub fn with_parameters(&self, f: F) -> R + pub fn with_args(&self, f: F) -> R where F: FnOnce(&GenericArgs) -> R { let dummy = GenericArgs::none(); - f(if let Some(ref params) = self.parameters { - ¶ms + f(if let Some(ref args) = self.args { + &args } else { &dummy }) @@ -380,12 +380,12 @@ pub enum GenericArg { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct GenericArgs { - /// The generic parameters for this path segment. - pub parameters: HirVec, + /// The generic arguments for this path segment. + pub args: HirVec, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo`. pub bindings: HirVec, - /// Were parameters written in parenthesized form `Fn(T) -> U`? + /// Were arguments written in parenthesized form `Fn(T) -> U`? /// This is required mostly for pretty-printing and diagnostics, /// but also for changing lifetime elision rules to be "function-like". pub parenthesized: bool, @@ -394,14 +394,14 @@ pub struct GenericArgs { impl GenericArgs { pub fn none() -> Self { Self { - parameters: HirVec::new(), + args: HirVec::new(), bindings: HirVec::new(), parenthesized: false, } } pub fn is_empty(&self) -> bool { - self.parameters.is_empty() && self.bindings.is_empty() && !self.parenthesized + self.args.is_empty() && self.bindings.is_empty() && !self.parenthesized } pub fn inputs(&self) -> &[P] { @@ -416,7 +416,7 @@ impl GenericArgs { } pub fn lifetimes(&self) -> impl DoubleEndedIterator { - self.parameters.iter().filter_map(|p| { + self.args.iter().filter_map(|p| { if let GenericArg::Lifetime(lt) = p { Some(lt) } else { @@ -426,7 +426,7 @@ impl GenericArgs { } pub fn types(&self) -> impl DoubleEndedIterator> { - self.parameters.iter().filter_map(|p| { + self.args.iter().filter_map(|p| { if let GenericArg::Type(ty) = p { Some(ty) } else { diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index f7e98591c11..c12d258b6c7 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1269,11 +1269,11 @@ impl<'a> State<'a> { self.s.word(".")?; self.print_name(segment.name)?; - segment.with_parameters(|parameters| { - if !parameters.parameters.is_empty() || - !parameters.bindings.is_empty() + segment.with_args(|args| { + if !args.args.is_empty() || + !args.bindings.is_empty() { - self.print_generic_args(¶meters, segment.infer_types, true) + self.print_generic_args(&args, segment.infer_types, true) } else { Ok(()) } @@ -1641,7 +1641,7 @@ impl<'a> State<'a> { if segment.name != keywords::CrateRoot.name() && segment.name != keywords::DollarCrate.name() { self.print_name(segment.name)?; - segment.with_parameters(|parameters| { + segment.with_args(|parameters| { self.print_generic_args(parameters, segment.infer_types, colons_before_params) @@ -1673,7 +1673,7 @@ impl<'a> State<'a> { if segment.name != keywords::CrateRoot.name() && segment.name != keywords::DollarCrate.name() { self.print_name(segment.name)?; - segment.with_parameters(|parameters| { + segment.with_args(|parameters| { self.print_generic_args(parameters, segment.infer_types, colons_before_params) @@ -1685,7 +1685,7 @@ impl<'a> State<'a> { self.s.word("::")?; let item_segment = path.segments.last().unwrap(); self.print_name(item_segment.name)?; - item_segment.with_parameters(|parameters| { + item_segment.with_args(|parameters| { self.print_generic_args(parameters, item_segment.infer_types, colons_before_params) @@ -1697,7 +1697,7 @@ impl<'a> State<'a> { self.s.word(">")?; self.s.word("::")?; self.print_name(item_segment.name)?; - item_segment.with_parameters(|parameters| { + item_segment.with_args(|parameters| { self.print_generic_args(parameters, item_segment.infer_types, colons_before_params) @@ -1734,7 +1734,7 @@ impl<'a> State<'a> { let elide_lifetimes = generic_args.lifetimes().all(|lt| lt.is_elided()); if !elide_lifetimes { start_or_comma(self)?; - self.commasep(Inconsistent, &generic_args.parameters, |s, p| { + self.commasep(Inconsistent, &generic_args.args, |s, p| { match p { GenericArg::Lifetime(lt) => s.print_lifetime(lt), GenericArg::Type(ty) => s.print_type(ty), diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 6f655628678..871e399b4f2 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -177,7 +177,7 @@ impl_stable_hash_for!(struct hir::Path { impl_stable_hash_for!(struct hir::PathSegment { name, infer_types, - parameters + args }); impl_stable_hash_for!(enum hir::GenericArg { @@ -186,7 +186,7 @@ impl_stable_hash_for!(enum hir::GenericArg { }); impl_stable_hash_for!(struct hir::GenericArgs { - parameters, + args, bindings, parenthesized }); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 69818068e9c..39dfa77ea67 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -28,7 +28,6 @@ use rustc_data_structures::sync::Lrc; use session::Session; use std::cell::Cell; use std::mem::replace; -use std::slice; use syntax::ast; use syntax::attr; use syntax::ptr::P; @@ -155,11 +154,10 @@ impl Region { } } - fn subst(self, params: Vec<&hir::Lifetime>, map: &NamedRegionMap) -> Option { + fn subst<'a, L>(self, mut params: L, map: &NamedRegionMap) -> Option + where L: Iterator { if let Region::EarlyBound(index, _, _) = self { - params - .get(index as usize) - .and_then(|lifetime| map.defs.get(&lifetime.id).cloned()) + params.nth(index as usize).and_then(|lifetime| map.defs.get(&lifetime.id).cloned()) } else { Some(self) } @@ -603,7 +601,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { // resolved the same as the `'_` in `&'_ Foo`. // // cc #48468 - self.resolve_elided_lifetimes(slice::from_ref(lifetime), false) + self.resolve_elided_lifetimes(vec![lifetime], false) } LifetimeName::Fresh(_) | LifetimeName::Static | LifetimeName::Name(_) => { // If the user wrote an explicit name, use that. @@ -833,8 +831,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) { for (i, segment) in path.segments.iter().enumerate() { let depth = path.segments.len() - i - 1; - if let Some(ref parameters) = segment.parameters { - self.visit_segment_parameters(path.def, depth, parameters); + if let Some(ref args) = segment.args { + self.visit_segment_args(path.def, depth, args); } } } @@ -1599,24 +1597,24 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } } - fn visit_segment_parameters( + fn visit_segment_args( &mut self, def: Def, depth: usize, - params: &'tcx hir::GenericArgs, + args: &'tcx hir::GenericArgs, ) { - if params.parenthesized { + if args.parenthesized { let was_in_fn_syntax = self.is_in_fn_syntax; self.is_in_fn_syntax = true; - self.visit_fn_like_elision(params.inputs(), Some(¶ms.bindings[0].ty)); + self.visit_fn_like_elision(args.inputs(), Some(&args.bindings[0].ty)); self.is_in_fn_syntax = was_in_fn_syntax; return; } - if params.lifetimes().all(|l| l.is_elided()) { - self.resolve_elided_lifetimes(params.lifetimes().collect(), true); + if args.lifetimes().all(|l| l.is_elided()) { + self.resolve_elided_lifetimes(args.lifetimes().collect(), true); } else { - for l in params.lifetimes() { + for l in args.lifetimes() { self.visit_lifetime(l); } } @@ -1688,13 +1686,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } else { Some(Region::Static) }, - Set1::One(r) => r.subst(params.lifetimes().collect(), map), + Set1::One(r) => r.subst(args.lifetimes(), map), Set1::Many => None, }) .collect() }); - for (i, ty) in params.types().enumerate() { + for (i, ty) in args.types().enumerate() { if let Some(<) = object_lifetime_defaults.get(i) { let scope = Scope::ObjectLifetimeDefault { lifetime: lt, @@ -1706,7 +1704,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } } - for b in ¶ms.bindings { + for b in &args.bindings { self.visit_assoc_type_binding(b); } } diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 66edbeff749..8b1c31deb13 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -10,6 +10,7 @@ use hir::def_id::DefId; use ty::{self, Ty, TypeFoldable, Substs, TyCtxt}; +use ty::subst::Kind; use traits; use rustc_target::spec::abi::Abi; use util::ppaux; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 447267adfcd..4f5f0c9d740 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -885,73 +885,6 @@ pub struct GenericParamCount { pub types: usize, } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub enum GenericParam { - Lifetime(RegionParameterDef), - Type(TypeParameterDef), -} - -impl GenericParam { - pub fn index(&self) -> u32 { - match self { - GenericParam::Lifetime(lt) => lt.index, - GenericParam::Type(ty) => ty.index, - } - } -} - -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub enum KindIndex { - Lifetime, - Type, -} - -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub struct KindIndexed { - pub lt: L, - pub ty: T, -} - -impl KindIndexed { - pub fn get(&self, idx: KindIndex) -> &T { - match idx { - KindIndex::Lifetime => &self.lt, - KindIndex::Type => &self.ty, - } - } - - pub fn iter(&self) -> KindIndexIterator { - KindIndexIterator { - index: self, - next: Some(KindIndex::Lifetime), - } - } -} - -#[derive(Clone, Debug)] -pub struct KindIndexIterator<'a, T: 'a> { - pub index: &'a KindIndexed, - pub next: Option, -} - -impl<'a, T> Iterator for KindIndexIterator<'a, T> { - type Item = &'a T; - - fn next(&mut self) -> Option { - match self.next { - Some(KindIndex::Lifetime) => { - self.next = Some(KindIndex::Type); - Some(&self.index.lt) - } - Some(KindIndex::Type) => { - self.next = None; - Some(&self.index.ty) - }, - None => None, - } - } -} - /// Information about the formal type/lifetime parameters associated /// with an item or method. Analogous to hir::Generics. /// @@ -1009,34 +942,6 @@ impl<'a, 'gcx, 'tcx> Generics { } } - pub fn lifetimes(&self) -> impl DoubleEndedIterator { - self.parameters.iter().filter_map(|p| { - if let GenericParam::Lifetime(lt) = p { - Some(lt) - } else { - None - } - }) - } - - pub fn types(&self) -> impl DoubleEndedIterator { - self.parameters.iter().filter_map(|p| { - if let GenericParam::Type(ty) = p { - Some(ty) - } else { - None - } - }) - } - - pub fn parent_lifetimes(&self) -> u32 { - *self.parent_params.get(KindIndex::Lifetime) - } - - pub fn parent_types(&self) -> u32 { - *self.parent_params.get(KindIndex::Type) - } - pub fn region_param(&'tcx self, param: &EarlyBoundRegion, tcx: TyCtxt<'a, 'gcx, 'tcx>) diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 322924535d1..7c8ba63c15e 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -40,6 +40,7 @@ use rustc::middle::weak_lang_items; use rustc::mir::mono::{Linkage, Visibility, Stats}; use rustc::middle::cstore::{EncodedMetadata}; use rustc::ty::{self, Ty, TyCtxt}; +use rustc::ty::subst::Kind; use rustc::ty::layout::{self, Align, TyLayout, LayoutOf}; use rustc::ty::query::Providers; use rustc::dep_graph::{DepNode, DepConstructor}; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 834bd0c32ed..7468f01de70 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -677,7 +677,7 @@ impl<'a> ReplaceBodyWithLoop<'a> { ast::TyKind::Paren(ref subty) => involves_impl_trait(subty), ast::TyKind::Tup(ref tys) => any_involves_impl_trait(tys.iter()), ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| { - match seg.parameters.as_ref().map(|p| &**p) { + match seg.args.as_ref().map(|p| &**p) { None => false, Some(&ast::GenericArgs::AngleBracketed(ref data)) => any_involves_impl_trait(data.types().into_iter()) || diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 7cef8a75aa6..2c58bd8e79b 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -295,7 +295,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { ); let label_msg = match pat.node { PatKind::Path(hir::QPath::Resolved(None, ref path)) - if path.segments.len() == 1 && path.segments[0].parameters.is_none() => { + if path.segments.len() == 1 && path.segments[0].args.is_none() => { format!("interpreted as a {} pattern, not new variable", path.def.kind_name()) } _ => format!("pattern `{}` not covered", pattern_string), diff --git a/src/librustc_mir/monomorphize/mod.rs b/src/librustc_mir/monomorphize/mod.rs index bf544e5120c..3afe9991c68 100644 --- a/src/librustc_mir/monomorphize/mod.rs +++ b/src/librustc_mir/monomorphize/mod.rs @@ -13,6 +13,7 @@ use rustc::middle::lang_items::DropInPlaceFnLangItem; use rustc::traits; use rustc::ty::adjustment::CustomCoerceUnsized; use rustc::ty::{self, Ty, TyCtxt}; +use rustc::ty::subst::Kind; pub use rustc::ty::Instance; pub use self::item::{MonoItem, MonoItemExt}; diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 39e0a539258..63c8bd3d1f7 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -230,9 +230,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> { // } // foo!(bar::baz); use_tree.prefix.segments.iter().find(|segment| { - segment.parameters.is_some() + segment.args.is_some() }).map(|segment| { - self.err_handler().span_err(segment.parameters.as_ref().unwrap().span(), + self.err_handler().span_err(segment.args.as_ref().unwrap().span(), "generic arguments in import path"); }); @@ -398,8 +398,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> { fn visit_vis(&mut self, vis: &'a Visibility) { match vis.node { VisibilityKind::Restricted { ref path, .. } => { - path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| { - self.err_handler().span_err(segment.parameters.as_ref().unwrap().span(), + path.segments.iter().find(|segment| segment.args.is_some()).map(|segment| { + self.err_handler().span_err(segment.args.as_ref().unwrap().span(), "generic arguments in visibility path"); }); } @@ -521,10 +521,10 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> { visit::walk_ty(self, t); } } - fn visit_path_parameters(&mut self, _: Span, path_parameters: &'a PathParameters) { - match *path_parameters { - PathParameters::AngleBracketed(ref params) => { - for type_ in ¶ms.types { + fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) { + match *generic_args { + GenericArgs::AngleBracketed(ref params) => { + for type_ in params.types() { self.visit_ty(type_); } for type_binding in ¶ms.bindings { @@ -533,7 +533,7 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> { self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty)); } } - PathParameters::Parenthesized(ref params) => { + GenericArgs::Parenthesized(ref params) => { for type_ in ¶ms.inputs { self.visit_ty(type_); } @@ -590,7 +590,7 @@ impl<'a> Visitor<'a> for ImplTraitProjectionVisitor<'a> { // // To implement this, we disallow `impl Trait` from `qself` // (for cases like `::Foo>`) - // but we allow `impl Trait` in `PathParameters` + // but we allow `impl Trait` in `GenericArgs` // iff there are no more PathSegments. if let Some(ref qself) = *qself { // `impl Trait` in `qself` is always illegal diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index de7a3dc5cee..649e8858b09 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -437,8 +437,8 @@ impl<'a> Resolver<'a> { let def = self.resolve_macro_to_def_inner(scope, path, kind, force); if def != Err(Determinacy::Undetermined) { // Do not report duplicated errors on every undetermined resolution. - path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| { - self.session.span_err(segment.parameters.as_ref().unwrap().span(), + path.segments.iter().find(|segment| segment.args.is_some()).map(|segment| { + self.session.span_err(segment.args.as_ref().unwrap().span(), "generic arguments in macro path"); }); } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 6d13548b9ad..fa055d246f3 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -818,10 +818,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { } self.dump_path_ref(id, path); - // Type parameters + // Type arguments for seg in &path.segments { - if let Some(ref params) = seg.parameters { - match **params { + if let Some(ref args) = seg.args { + match **args { ast::GenericArgs::AngleBracketed(ref data) => for t in data.types() { self.visit_ty(t); }, @@ -905,8 +905,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { } // Explicit types in the turbo-fish. - if let Some(ref params) = seg.parameters { - if let ast::GenericArgs::AngleBracketed(ref data) = **params { + if let Some(ref args) = seg.args { + if let ast::GenericArgs::AngleBracketed(ref data) = **args { for t in data.types() { self.visit_ty(t); } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index c1022c09de3..4f03698d9b1 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -692,8 +692,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { if path.segments.len() != 1 { return false; } - if let Some(ref params) = path.segments[0].parameters { - if let ast::GenericArgs::Parenthesized(_) = **params { + if let Some(ref args) = path.segments[0].args { + if let ast::GenericArgs::Parenthesized(_) = **args { return true; } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 656045c970f..be4c423e959 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -177,11 +177,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { { let (substs, assoc_bindings) = - item_segment.with_parameters(|parameters| { + item_segment.with_args(|args| { self.create_substs_for_ast_path( span, def_id, - parameters, + args, item_segment.infer_types, None) }); @@ -199,7 +199,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { fn create_substs_for_ast_path(&self, span: Span, def_id: DefId, - parameters: &hir::GenericArgs, + args: &hir::GenericArgs, infer_types: bool, self_ty: Option>) -> (&'tcx Substs<'tcx>, Vec>) @@ -207,15 +207,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let tcx = self.tcx(); debug!("create_substs_for_ast_path(def_id={:?}, self_ty={:?}, \ - parameters={:?})", - def_id, self_ty, parameters); + args={:?})", + def_id, self_ty, args); // If the type is parameterized by this region, then replace this // region with the current anon region binding (in other words, // whatever & would get replaced with). let decl_generics = tcx.generics_of(def_id); - let ty_provided = parameters.types().len(); - let lt_provided = parameters.lifetimes().len(); + let ty_provided = args.types().count(); + let lt_provided = args.lifetimes().count(); let mut lt_accepted = 0; let mut ty_params = ParamRange { required: 0, accepted: 0 }; @@ -269,7 +269,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { match param.kind { GenericParamDefKind::Lifetime => { let i = param.index as usize - own_self; - if let Some(lifetime) = parameters.lifetimes().get(i) { + if let Some(lifetime) = args.lifetimes().nth(i) { self.ast_region_to_region(lifetime, Some(param)).into() } else { tcx.types.re_static.into() @@ -286,7 +286,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let i = i - (lt_accepted + own_self); if i < ty_provided { // A provided type parameter. - self.ast_ty_to_ty(¶meters.types()[i]).into() + self.ast_ty_to_ty(&args.types().nth(i).unwrap()).into() } else if infer_types { // No type parameters were provided, we can infer all. if !default_needs_object_self(param) { @@ -330,7 +330,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { } }); - let assoc_bindings = parameters.bindings.iter().map(|binding| { + let assoc_bindings = args.bindings.iter().map(|binding| { ConvertedBinding { item_name: binding.name, ty: self.ast_ty_to_ty(&binding.ty), @@ -451,7 +451,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { let trait_def = self.tcx().trait_def(trait_def_id); if !self.tcx().features().unboxed_closures && - trait_segment.with_parameters(|p| p.parenthesized) != trait_def.paren_sugar { + trait_segment.with_args(|p| p.parenthesized) != trait_def.paren_sugar { // For now, require that parenthetical notation be used only with `Fn()` etc. let msg = if trait_def.paren_sugar { "the precise format of `Fn`-family traits' type parameters is subject to change. \ @@ -463,7 +463,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { span, GateIssue::Language, msg); } - trait_segment.with_parameters(|parameters| { + trait_segment.with_args(|parameters| { self.create_substs_for_ast_path(span, trait_def_id, parameters, @@ -970,8 +970,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) { for segment in segments { - segment.with_parameters(|params| { - for p in ¶ms.parameters { + segment.with_args(|params| { + for p in ¶ms.args { let (mut span_err, span, kind) = match p { hir::GenericArg::Lifetime(lt) => { (struct_span_err!(self.tcx().sess, lt.span, E0110, diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 3274c449daa..bb5bdd4dc77 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -59,7 +59,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { "confirm(unadjusted_self_ty={:?}, pick={:?}, generic_args={:?})", unadjusted_self_ty, pick, - segment.parameters, + segment.args, ); let mut confirm_cx = ConfirmContext::new(self, span, self_expr, call_expr); @@ -321,7 +321,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { // Create subst for early-bound lifetime parameters, combining // parameters from the type and those from the method. assert_eq!(method_generics.parent_count, parent_substs.len()); - let provided = &segment.parameters; + let provided = &segment.args; let own_counts = method_generics.own_counts(); Substs::for_item(self.tcx, pick.item.def_id, |param, _| { let i = param.index as usize; @@ -331,7 +331,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { match param.kind { GenericParamDefKind::Lifetime => { if let Some(lifetime) = provided.as_ref().and_then(|p| { - p.lifetimes().get(i - parent_substs.len()) + p.lifetimes().nth(i - parent_substs.len()) }) { return AstConv::ast_region_to_region( self.fcx, lifetime, Some(param)).into(); @@ -339,7 +339,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { } GenericParamDefKind::Type {..} => { if let Some(ast_ty) = provided.as_ref().and_then(|p| { - p.types().get(i - parent_substs.len() - own_counts.lifetimes) + p.types().nth(i - parent_substs.len() - own_counts.lifetimes) }) { return self.to_ty(ast_ty).into(); } @@ -347,7 +347,6 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { } self.var_for_def(self.span, param) } - self.type_var_for_def(self.span, def, cur_substs) }) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ef61c99ae01..5af3d2fc42c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4834,7 +4834,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { match param.kind { GenericParamDefKind::Lifetime => { let lifetimes = segment.map_or(vec![], |(s, _)| { - s.parameters.as_ref().map_or(vec![], |p| p.lifetimes()) + s.args.as_ref().map_or(vec![], |p| p.lifetimes().collect()) }); if let Some(lifetime) = lifetimes.get(i) { @@ -4845,7 +4845,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } GenericParamDefKind::Type {..} => { let (types, infer_types) = segment.map_or((vec![], true), |(s, _)| { - (s.parameters.as_ref().map_or(vec![], |p| |p| p.types()), s.infer_types) + (s.args.as_ref().map_or(vec![], |p| p.types().collect()), s.infer_types) }); // Skip over the lifetimes in the same segment. @@ -4962,7 +4962,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { supress_mismatch_error: bool) { let (lifetimes, types, infer_types, bindings) = segment.map_or( (vec![], vec![], true, &[][..]), - |(s, _)| s.parameters.as_ref().map_or( + |(s, _)| s.args.as_ref().map_or( (vec![], vec![], s.infer_types, &[][..]), |p| (p.lifetimes().collect(), p.types().collect(), s.infer_types, &p.bindings[..]))); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 70367dd2461..58e804fc13f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -973,13 +973,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, .map(|param| (param.def_id, param.index)) .collect(); - let parent_params = ty::KindIndexed { lt: parent_regions, ty: parent_types }; - let lifetimes: Vec = - regions.into_iter().map(|lt| ty::GenericParam::Lifetime(lt)).collect(); - let types: Vec = - types.into_iter().map(|ty| ty::GenericParam::Type(ty)).collect(); - let parameters = lifetimes.into_iter().chain(types.into_iter()).collect(); - tcx.alloc_generics(ty::Generics { parent: parent_def_id, parent_count, diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index da749fca2a9..4418c107223 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -244,9 +244,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { None } - fn generics_to_path_params(&self, generics: ty::Generics) -> hir::PathParameters { - let mut lifetimes = vec![]; - let mut types = vec![]; + fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs { + let mut args = vec![]; for param in generics.params.iter() { match param.kind { @@ -257,21 +256,20 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { hir::LifetimeName::Name(param.name.as_symbol()) }; - lifetimes.push(hir::Lifetime { + args.push(hir::GenericArg::Lifetime(hir::Lifetime { id: ast::DUMMY_NODE_ID, span: DUMMY_SP, name, - }); + })); } ty::GenericParamDefKind::Type {..} => { - types.push(P(self.ty_param_to_ty(param.clone()))); + args.push(hir::GenericArg::Type(P(self.ty_param_to_ty(param.clone())))); } } } - hir::PathParameters { - lifetimes: HirVec::from_vec(lifetimes), - types: HirVec::from_vec(types), + hir::GenericArgs { + args: HirVec::from_vec(args), bindings: HirVec::new(), parenthesized: false, } @@ -555,9 +553,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { let mut new_path = path.clone(); let last_segment = new_path.segments.pop().unwrap(); - let (old_input, old_output) = match last_segment.params { - PathParameters::AngleBracketed { types, .. } => (types, None), - PathParameters::Parenthesized { inputs, output, .. } => { + let (old_input, old_output) = match last_segment.args { + GenericArgs::AngleBracketed { types, .. } => (types, None), + GenericArgs::Parenthesized { inputs, output, .. } => { (inputs, output) } }; @@ -569,14 +567,14 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { ); } - let new_params = PathParameters::Parenthesized { + let new_params = GenericArgs::Parenthesized { inputs: old_input, output, }; new_path.segments.push(PathSegment { name: last_segment.name, - params: new_params, + args: new_params, }); Type::ResolvedPath { @@ -793,13 +791,13 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // FIXME: Remove this scope when NLL lands { - let params = - &mut new_trait_path.segments.last_mut().unwrap().params; + let args = + &mut new_trait_path.segments.last_mut().unwrap().args; - match params { + match args { // Convert somethiung like ' = u8' // to 'T: Iterator' - &mut PathParameters::AngleBracketed { + &mut GenericArgs::AngleBracketed { ref mut bindings, .. } => { @@ -808,7 +806,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { ty: rhs, }); } - &mut PathParameters::Parenthesized { .. } => { + &mut GenericArgs::Parenthesized { .. } => { existing_predicates.push( WherePredicate::EqPredicate { lhs: lhs.clone(), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f454136026f..793a8a7f110 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1607,7 +1607,7 @@ fn external_path(cx: &DocContext, name: &str, trait_did: Option, has_self def: Def::Err, segments: vec![PathSegment { name: name.to_string(), - params: external_generic_args(cx, trait_did, has_self, bindings, substs) + args: external_generic_args(cx, trait_did, has_self, bindings, substs) }], } } @@ -2656,7 +2656,7 @@ impl Type { match *self { ResolvedPath { ref path, .. } => { path.segments.last().and_then(|seg| { - if let GenericArgs::AngleBracketed { ref types, .. } = seg.params { + if let GenericArgs::AngleBracketed { ref types, .. } = seg.args { Some(&**types) } else { None @@ -2851,7 +2851,7 @@ impl Clean for hir::Ty { let provided_params = &path.segments.last().unwrap(); let mut ty_substs = FxHashMap(); let mut lt_substs = FxHashMap(); - provided_params.with_parameters(|provided_params| { + provided_params.with_args(|provided_params| { let mut indices = GenericParamCount { lifetimes: 0, types: 0 @@ -2859,8 +2859,8 @@ impl Clean for hir::Ty { for param in generics.params.iter() { match param { hir::GenericParam::Lifetime(lt_param) => { - if let Some(lt) = provided_params.lifetimes - .get(indices.lifetimes).cloned() { + if let Some(lt) = provided_params.lifetimes() + .nth(indices.lifetimes).cloned() { if !lt.is_elided() { let lt_def_id = cx.tcx.hir.local_def_id(lt_param.lifetime.id); @@ -2872,8 +2872,8 @@ impl Clean for hir::Ty { hir::GenericParam::Type(ty_param) => { let ty_param_def = Def::TyParam(cx.tcx.hir.local_def_id(ty_param.id)); - if let Some(ty) = provided_params.types - .get(indices.types).cloned() { + if let Some(ty) = provided_params.types() + .nth(indices.types).cloned() { ty_substs.insert(ty_param_def, ty.into_inner().clean(cx)); } else if let Some(default) = ty_param.default.clone() { ty_substs.insert(ty_param_def, @@ -3447,7 +3447,7 @@ impl Path { def: Def::Err, segments: vec![PathSegment { name, - params: GenericArgs::AngleBracketed { + args: GenericArgs::AngleBracketed { lifetimes: Vec::new(), types: Vec::new(), bindings: Vec::new(), @@ -3471,7 +3471,7 @@ impl Clean for hir::Path { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eg, Debug, Hash)] +#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] pub enum GenericArgs { AngleBracketed { lifetimes: Vec, @@ -3509,14 +3509,14 @@ impl Clean for hir::GenericArgs { #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] pub struct PathSegment { pub name: String, - pub params: GenericArgs, + pub args: GenericArgs, } impl Clean for hir::PathSegment { fn clean(&self, cx: &DocContext) -> PathSegment { PathSegment { name: self.name.clean(cx), - params: self.with_parameters(|parameters| parameters.clean(cx)) + args: self.with_args(|args| args.clean(cx)) } } } @@ -3550,7 +3550,7 @@ fn strip_path(path: &Path) -> Path { let segments = path.segments.iter().map(|s| { PathSegment { name: s.name.clone(), - params: PathParameters::AngleBracketed { + args: GenericArgs::AngleBracketed { lifetimes: Vec::new(), types: Vec::new(), bindings: Vec::new(), @@ -4365,7 +4365,7 @@ where F: Fn(DefId) -> Def { def: def_ctor(def_id), segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment { name: ast::Name::intern(&s), - parameters: None, + args: None, infer_types: false, }).collect()) } diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 1dd57465996..ac1952a4bab 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -97,7 +97,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec) -> Vec { return false } let last = path.segments.last_mut().unwrap(); - match last.params { + match last.args { PP::AngleBracketed { ref mut bindings, .. } => { bindings.push(clean::TypeBinding { name: name.clone(), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index de5c0eeffc9..d2d068e5209 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -369,9 +369,9 @@ impl fmt::Display for clean::PathSegment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(&self.name)?; if f.alternate() { - write!(f, "{:#}", self.params) + write!(f, "{:#}", self.args) } else { - write!(f, "{}", self.params) + write!(f, "{}", self.args) } } } @@ -447,7 +447,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, } } if w.alternate() { - write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?; + write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.args)?; } else { let path = if use_absolute { match href(did) { @@ -461,7 +461,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, } else { format!("{}", HRef::new(did, &last.name)) }; - write!(w, "{}{}", path, last.params)?; + write!(w, "{}{}", path, last.args)?; } Ok(()) } @@ -757,7 +757,7 @@ fn fmt_impl(i: &clean::Impl, clean::ResolvedPath { typarams: None, ref path, is_generic: false, .. } => { let last = path.segments.last().unwrap(); fmt::Display::fmt(&last.name, f)?; - fmt::Display::fmt(&last.params, f)?; + fmt::Display::fmt(&last.args, f)?; } _ => unreachable!(), } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7bcaf9bbd52..7ff00123624 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -135,27 +135,27 @@ pub struct PathSegment { /// `Some` means that parameter list is supplied (`Path`) /// but it can be empty (`Path<>`). /// `P` is used as a size optimization for the common case with no parameters. - pub parameters: Option>, + pub args: Option>, } impl PathSegment { pub fn from_ident(ident: Ident) -> Self { - PathSegment { ident, parameters: None } + PathSegment { ident, args: None } } pub fn crate_root(span: Span) -> Self { PathSegment::from_ident(Ident::new(keywords::CrateRoot.name(), span)) } } -/// Parameters of a path segment. +/// Arguments of a path segment. /// /// E.g. `` as in `Foo` or `(A, B)` as in `Foo(A, B)` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum GenericArgs { /// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>` - AngleBracketed(AngleBracketedParameterData), + AngleBracketed(AngleBracketedArgs), /// The `(A,B)` and `C` in `Foo(A,B) -> C` - Parenthesized(ParenthesizedParameterData), + Parenthesized(ParenthesizedArgData), } impl GenericArgs { @@ -168,28 +168,28 @@ impl GenericArgs { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum AngleBracketedParam { +pub enum GenericArg { Lifetime(Lifetime), Type(P), } /// A path like `Foo<'a, T>` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Default)] -pub struct AngleBracketedParameterData { +pub struct AngleBracketedArgs { /// Overall span pub span: Span, - /// The parameters for this path segment. - pub parameters: Vec, + /// The arguments for this path segment. + pub args: Vec, /// Bindings (equality constraints) on associated types, if present. /// /// E.g., `Foo`. pub bindings: Vec, } -impl AngleBracketedParameterData { +impl AngleBracketedArgs { pub fn lifetimes(&self) -> impl DoubleEndedIterator { - self.parameters.iter().filter_map(|p| { - if let AngleBracketedParam::Lifetime(lt) = p { + self.args.iter().filter_map(|p| { + if let GenericArg::Lifetime(lt) = p { Some(lt) } else { None @@ -198,8 +198,8 @@ impl AngleBracketedParameterData { } pub fn types(&self) -> impl DoubleEndedIterator> { - self.parameters.iter().filter_map(|p| { - if let AngleBracketedParam::Type(ty) = p { + self.args.iter().filter_map(|p| { + if let GenericArg::Type(ty) = p { Some(ty) } else { None @@ -208,13 +208,13 @@ impl AngleBracketedParameterData { } } -impl Into>> for AngleBracketedParameterData { +impl Into>> for AngleBracketedArgs { fn into(self) -> Option> { Some(P(GenericArgs::AngleBracketed(self))) } } -impl Into>> for ParenthesizedParameterData { +impl Into>> for ParenthesizedArgData { fn into(self) -> Option> { Some(P(GenericArgs::Parenthesized(self))) } @@ -222,7 +222,7 @@ impl Into>> for ParenthesizedParameterData { /// A path like `Foo(A,B) -> C` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub struct ParenthesizedParameterData { +pub struct ParenthesizedArgData { /// Overall span pub span: Span, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a59e34580c0..05a345fb2a1 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -31,7 +31,7 @@ pub trait AstBuilder { fn path_all(&self, sp: Span, global: bool, idents: Vec, - parameters: Vec, + parameters: Vec, bindings: Vec) -> ast::Path; @@ -42,7 +42,7 @@ pub trait AstBuilder { fn qpath_all(&self, self_type: P, trait_path: ast::Path, ident: ast::Ident, - parameters: Vec, + parameters: Vec, bindings: Vec) -> (ast::QSelf, ast::Path); @@ -314,7 +314,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, global: bool, mut idents: Vec , - parameters: Vec, + args: Vec, bindings: Vec ) -> ast::Path { let last_ident = idents.pop().unwrap(); @@ -323,12 +323,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { segments.extend(idents.into_iter().map(|ident| { ast::PathSegment::from_ident(ident.with_span_pos(span)) })); - let parameters = if !parameters.is_empty() !bindings.is_empty() { - ast::AngleBracketedParameterData { parameters, bindings, span }.into() + let args = if !args.is_empty() || !bindings.is_empty() { + ast::AngleBracketedArgs { args, bindings, span }.into() } else { None }; - segments.push(ast::PathSegment { ident: last_ident.with_span_pos(span), parameters }); + segments.push(ast::PathSegment { ident: last_ident.with_span_pos(span), args }); let mut path = ast::Path { span, segments }; if global { if let Some(seg) = path.make_root() { @@ -356,16 +356,16 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self_type: P, trait_path: ast::Path, ident: ast::Ident, - parameters: Vec, + args: Vec, bindings: Vec) -> (ast::QSelf, ast::Path) { let mut path = trait_path; - let parameters = if !parameters.is_empty() || !bindings.is_empty() { - ast::AngleBracketedParameterData { parameters, bindings, span: ident.span }.into() + let args = if !args.is_empty() || !bindings.is_empty() { + ast::AngleBracketedArgs { args, bindings, span: ident.span }.into() } else { None }; - path.segments.push(ast::PathSegment { ident, parameters }); + path.segments.push(ast::PathSegment { ident, args }); (ast::QSelf { ty: self_type, @@ -424,7 +424,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.path_all(DUMMY_SP, true, self.std_path(&["option", "Option"]), - vec![ ast::AngleBracketedParam::Type(ty) ], + vec![ ast::GenericArg::Type(ty) ], Vec::new())) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index decb7e56132..dc23ed19d1b 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -132,11 +132,11 @@ pub trait Folder : Sized { noop_fold_exprs(es, self) } - fn fold_param(&mut self, p: AngleBracketedParam) -> AngleBracketedParam { + fn fold_param(&mut self, p: GenericArg) -> GenericArg { match p { - AngleBracketedParam::Lifetime(lt) => - AngleBracketedParam::Lifetime(self.fold_lifetime(lt)), - AngleBracketedParam::Type(ty) => AngleBracketedParam::Type(self.fold_ty(ty)), + GenericArg::Lifetime(lt) => + GenericArg::Lifetime(self.fold_lifetime(lt)), + GenericArg::Type(ty) => GenericArg::Type(self.fold_ty(ty)), } } @@ -184,14 +184,14 @@ pub trait Folder : Sized { noop_fold_generic_args(p, self) } - fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedParameterData) - -> AngleBracketedParameterData + fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedArgs) + -> AngleBracketedArgs { noop_fold_angle_bracketed_parameter_data(p, self) } - fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedParameterData) - -> ParenthesizedParameterData + fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedArgData) + -> ParenthesizedArgData { noop_fold_parenthesized_parameter_data(p, self) } @@ -441,9 +441,9 @@ pub fn noop_fold_usize(i: usize, _: &mut T) -> usize { pub fn noop_fold_path(Path { segments, span }: Path, fld: &mut T) -> Path { Path { - segments: segments.move_map(|PathSegment {ident, parameters}| PathSegment { + segments: segments.move_map(|PathSegment {ident, args}| PathSegment { ident: fld.fold_ident(ident), - parameters: parameters.map(|ps| ps.map(|ps| fld.fold_generic_args(ps))), + args: args.map(|ps| ps.map(|ps| fld.fold_generic_args(ps))), }), span: fld.new_span(span) } @@ -473,22 +473,22 @@ pub fn noop_fold_generic_args(generic_args: GenericArgs, fld: &mut T) } } -pub fn noop_fold_angle_bracketed_parameter_data(data: AngleBracketedParameterData, +pub fn noop_fold_angle_bracketed_parameter_data(data: AngleBracketedArgs, fld: &mut T) - -> AngleBracketedParameterData + -> AngleBracketedArgs { - let AngleBracketedParameterData { parameters, bindings, span } = data; - AngleBracketedParameterData { parameters: parameters.move_map(|p| fld.fold_param(p)), + let AngleBracketedArgs { args, bindings, span } = data; + AngleBracketedArgs { args: args.move_map(|p| fld.fold_param(p)), bindings: bindings.move_map(|b| fld.fold_ty_binding(b)), span: fld.new_span(span) } } -pub fn noop_fold_parenthesized_parameter_data(data: ParenthesizedParameterData, +pub fn noop_fold_parenthesized_parameter_data(data: ParenthesizedArgData, fld: &mut T) - -> ParenthesizedParameterData + -> ParenthesizedArgData { - let ParenthesizedParameterData { inputs, output, span } = data; - ParenthesizedParameterData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)), + let ParenthesizedArgData { inputs, output, span } = data; + ParenthesizedArgData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)), output: output.map(|ty| fld.fold_ty(ty)), span: fld.new_span(span) } } @@ -1191,7 +1191,7 @@ pub fn noop_fold_expr(Expr {id, node, span, attrs}: Expr, folder: &mu ExprKind::MethodCall( PathSegment { ident: folder.fold_ident(seg.ident), - parameters: seg.parameters.map(|ps| { + args: seg.args.map(|ps| { ps.map(|ps| folder.fold_generic_args(ps)) }), }, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e54c5445fa2..a51b3bc0ae4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -9,7 +9,7 @@ // except according to those terms. use rustc_target::spec::abi::{self, Abi}; -use ast::{AngleBracketedParameterData, ParenthesizedParameterData, AttrStyle, BareFnTy}; +use ast::{AngleBracketedArgs, ParenthesizedArgData, AttrStyle, BareFnTy}; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::Unsafety; use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind}; @@ -22,7 +22,7 @@ use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; use ast::GenericParam; -use ast::AngleBracketedParam; +use ast::GenericArg; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind}; use ast::Local; @@ -1895,7 +1895,7 @@ impl<'a> Parser<'a> { -> PResult<'a, ast::Path> { maybe_whole!(self, NtPath, |path| { if style == PathStyle::Mod && - path.segments.iter().any(|segment| segment.parameters.is_some()) { + path.segments.iter().any(|segment| segment.args.is_some()) { self.diagnostic().span_err(path.span, "unexpected generic arguments in path"); } path @@ -1970,12 +1970,12 @@ impl<'a> Parser<'a> { .span_label(self.prev_span, "try removing `::`").emit(); } - let parameters = if self.eat_lt() { + let args = if self.eat_lt() { // `<'a, T, A = U>` - let (parameters, bindings) = self.parse_generic_args()?; + let (args, bindings) = self.parse_generic_args()?; self.expect_gt()?; let span = lo.to(self.prev_span); - AngleBracketedParameterData { parameters, bindings, span }.into() + AngleBracketedArgs { args, bindings, span }.into() } else { // `(T, U) -> R` self.bump(); // `(` @@ -1991,10 +1991,10 @@ impl<'a> Parser<'a> { None }; let span = lo.to(self.prev_span); - ParenthesizedParameterData { inputs, output, span }.into() + ParenthesizedArgData { inputs, output, span }.into() }; - PathSegment { ident, parameters } + PathSegment { ident, args } } else { // Generic arguments are not found. PathSegment::from_ident(ident) @@ -2544,8 +2544,8 @@ impl<'a> Parser<'a> { } _ => { // Field access `expr.f` - if let Some(parameters) = segment.parameters { - self.span_err(parameters.span(), + if let Some(args) = segment.args { + self.span_err(args.span(), "field expressions may not have generic arguments"); } @@ -4938,15 +4938,15 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings, /// possibly including trailing comma. fn parse_generic_args(&mut self) - -> PResult<'a, (Vec, Vec)> { - let mut parameters = Vec::new(); + -> PResult<'a, (Vec, Vec)> { + let mut args = Vec::new(); let mut bindings = Vec::new(); let mut seen_type = false; let mut seen_binding = false; loop { if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { // Parse lifetime argument. - parameters.push(AngleBracketedParam::Lifetime(self.expect_lifetime())); + args.push(GenericArg::Lifetime(self.expect_lifetime())); if seen_type || seen_binding { self.span_err(self.prev_span, "lifetime parameters must be declared prior to type parameters"); @@ -4971,7 +4971,7 @@ impl<'a> Parser<'a> { self.span_err(ty_param.span, "type parameters must be declared prior to associated type bindings"); } - parameters.push(AngleBracketedParam::Type(ty_param)); + args.push(GenericArg::Type(ty_param)); seen_type = true; } else { break @@ -4981,7 +4981,7 @@ impl<'a> Parser<'a> { break } } - Ok((parameters, bindings)) + Ok((args, bindings)) } /// Parses an optional `where` clause and places it in `generics`. diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 287fe0b636f..3b487430c52 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -13,7 +13,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::{self, Abi}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Attribute, MacDelimiter, AngleBracketedParam}; +use ast::{Attribute, MacDelimiter, GenericArg}; use util::parser::{self, AssocOp, Fixity}; use attr; use codemap::{self, CodeMap}; @@ -1017,10 +1017,10 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_param(&mut self, param: &AngleBracketedParam) -> io::Result<()> { + pub fn print_param(&mut self, param: &GenericArg) -> io::Result<()> { match param { - AngleBracketedParam::Lifetime(lt) => self.print_lifetime(lt), - AngleBracketedParam::Type(ty) => self.print_type(ty), + GenericArg::Lifetime(lt) => self.print_lifetime(lt), + GenericArg::Type(ty) => self.print_type(ty), } } @@ -1991,8 +1991,8 @@ impl<'a> State<'a> { self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX)?; self.s.word(".")?; self.print_ident(segment.ident)?; - if let Some(ref parameters) = segment.parameters { - self.print_generic_args(parameters, true)?; + if let Some(ref args) = segment.args { + self.print_generic_args(args, true)?; } self.print_call_post(base_args) } @@ -2435,8 +2435,8 @@ impl<'a> State<'a> { if segment.ident.name != keywords::CrateRoot.name() && segment.ident.name != keywords::DollarCrate.name() { self.print_ident(segment.ident)?; - if let Some(ref parameters) = segment.parameters { - self.print_generic_args(parameters, colons_before_params)?; + if let Some(ref args) = segment.args { + self.print_generic_args(args, colons_before_params)?; } } else if segment.ident.name == keywords::DollarCrate.name() { self.print_dollar_crate(segment.ident.span.ctxt())?; @@ -2462,14 +2462,14 @@ impl<'a> State<'a> { self.s.word("::")?; let item_segment = path.segments.last().unwrap(); self.print_ident(item_segment.ident)?; - match item_segment.parameters { - Some(ref parameters) => self.print_generic_args(parameters, colons_before_params), + match item_segment.args { + Some(ref args) => self.print_generic_args(args, colons_before_params), None => Ok(()), } } fn print_generic_args(&mut self, - parameters: &ast::GenericArgs, + args: &ast::GenericArgs, colons_before_params: bool) -> io::Result<()> { @@ -2477,13 +2477,13 @@ impl<'a> State<'a> { self.s.word("::")? } - match *parameters { + match *args { ast::GenericArgs::AngleBracketed(ref data) => { self.s.word("<")?; - self.commasep(Inconsistent, &data.parameters, |s, p| s.print_param(p))?; + self.commasep(Inconsistent, &data.args, |s, p| s.print_param(p))?; - let mut comma = data.parameters.len() != 0; + let mut comma = data.args.len() != 0; for binding in data.bindings.iter() { if comma { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 6dc61f3058a..906f1941cd6 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -131,10 +131,10 @@ pub trait Visitor<'ast>: Sized { fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) { walk_generic_args(self, path_span, generic_args) } - fn visit_angle_bracketed_param(&mut self, param: &'ast AngleBracketedParam) { + fn visit_angle_bracketed_param(&mut self, param: &'ast GenericArg) { match param { - AngleBracketedParam::Lifetime(lt) => self.visit_lifetime(lt), - AngleBracketedParam::Type(ty) => self.visit_ty(ty), + GenericArg::Lifetime(lt) => self.visit_lifetime(lt), + GenericArg::Type(ty) => self.visit_ty(ty), } } fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) { @@ -381,8 +381,8 @@ pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, path_span: Span, segment: &'a PathSegment) { visitor.visit_ident(segment.ident); - if let Some(ref parameters) = segment.parameters { - visitor.visit_generic_args(path_span, parameters); + if let Some(ref args) = segment.args { + visitor.visit_generic_args(path_span, args); } } @@ -393,7 +393,7 @@ pub fn walk_generic_args<'a, V>(visitor: &mut V, { match *generic_args { GenericArgs::AngleBracketed(ref data) => { - walk_list!(visitor, visit_angle_bracketed_param, &data.parameters); + walk_list!(visitor, visit_angle_bracketed_param, &data.args); walk_list!(visitor, visit_assoc_type_binding, &data.bindings); } GenericArgs::Parenthesized(ref data) => { diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 2e0551b32f7..504c3f8e913 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -13,7 +13,7 @@ use deriving::generic::*; use deriving::generic::ty::*; use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; -use syntax::ast::AngleBracketedParam; +use syntax::ast::GenericArg; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -124,7 +124,7 @@ fn cs_clone_shallow(name: &str, let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["clone", helper_name]), - vec![AngleBracketedParam::Type(ty)], vec![]); + vec![GenericArg::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &VariantData) { diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index 51ab9975ed9..00ab39032ac 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, Expr, MetaItem, AngleBracketedParam}; +use syntax::ast::{self, Expr, MetaItem, GenericArg}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -62,7 +62,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["cmp", helper_name]), - vec![AngleBracketedParam::Type(ty)], vec![]); + vec![GenericArg::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &ast::VariantData) { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index a7bb7ba025f..299c53f3101 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -193,7 +193,7 @@ use std::vec; use rustc_target::spec::abi::Abi; use syntax::ast::{self, BinOpKind, EnumDef, Expr, GenericParam, Generics, Ident, PatKind}; -use syntax::ast::{VariantData, AngleBracketedParam}; +use syntax::ast::{VariantData, GenericArg}; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -683,9 +683,9 @@ impl<'a> TraitDef<'a> { .collect(); let self_params = self_lifetimes.into_iter() - .map(|lt| AngleBracketedParam::Lifetime(lt)) + .map(|lt| GenericArg::Lifetime(lt)) .chain(self_ty_params.into_iter().map(|ty| - AngleBracketedParam::Type(ty))) + GenericArg::Type(ty))) .collect(); // Create the type of `self`. diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index d6ee7759ae6..7e6dd5fad25 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -15,7 +15,7 @@ pub use self::PtrTy::*; pub use self::Ty::*; use syntax::ast; -use syntax::ast::{Expr, GenericParam, Generics, Ident, SelfKind, AngleBracketedParam}; +use syntax::ast::{Expr, GenericParam, Generics, Ident, SelfKind, GenericArg}; use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::codemap::{respan, DUMMY_SP}; @@ -89,8 +89,8 @@ impl<'a> Path<'a> { let tys: Vec> = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect(); let params = lt.into_iter() - .map(|lt| AngleBracketedParam::Lifetime(lt)) - .chain(tys.into_iter().map(|ty| AngleBracketedParam::Type(ty))) + .map(|lt| GenericArg::Lifetime(lt)) + .chain(tys.into_iter().map(|ty| GenericArg::Type(ty))) .collect(); match self.kind { @@ -206,9 +206,9 @@ impl<'a> Ty<'a> { .collect(); let params = lifetimes.into_iter() - .map(|lt| AngleBracketedParam::Lifetime(lt)) + .map(|lt| GenericArg::Lifetime(lt)) .chain(ty_params.into_iter().map(|ty| - AngleBracketedParam::Type(ty))) + GenericArg::Type(ty))) .collect(); cx.path_all(span, diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index 78721d880fc..5c3080260cc 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -13,7 +13,7 @@ // interface. // -use syntax::ast::{self, Ident, AngleBracketedParam}; +use syntax::ast::{self, Ident, GenericArg}; use syntax::ext::base::*; use syntax::ext::base; use syntax::ext::build::AstBuilder; @@ -39,10 +39,10 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, cx.expr_path(cx.path_all(sp, true, cx.std_path(&["option", "Option", "None"]), - vec![AngleBracketedParam::Type(cx.ty_rptr(sp, + vec![GenericArg::Type(cx.ty_rptr(sp, cx.ty_ident(sp, Ident::from_str("str")), Some(lt), - ast::Mutability::Immutable)], + ast::Mutability::Immutable))], Vec::new())) } Ok(s) => { -- cgit 1.4.1-3-g733a5 From d643946550fa349729184a4f70abc01e21ceddc0 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 25 May 2018 18:41:03 +0100 Subject: Rename ast::GenericParam and ast::GenericArg It's so confusing to have everything having the same name, at least while refactoring. --- src/librustc/hir/lowering.rs | 22 +++++++++++----------- src/librustc/hir/map/def_collector.rs | 6 +++--- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 2 +- src/librustc_passes/ast_validation.rs | 18 +++++++++--------- src/librustc_resolve/lib.rs | 10 +++++----- src/librustc_save_analysis/dump_visitor.rs | 4 ++-- src/librustc_save_analysis/lib.rs | 4 ++-- src/librustc_save_analysis/sig.rs | 6 +++--- src/libsyntax/ast.rs | 28 ++++++++++++++-------------- src/libsyntax/ext/build.rs | 10 +++++----- src/libsyntax/fold.rs | 22 +++++++++++----------- src/libsyntax/parse/parser.rs | 23 +++++++++++------------ src/libsyntax/print/pprust.rs | 20 ++++++++++---------- src/libsyntax/util/node_count.rs | 2 +- src/libsyntax/visit.rs | 14 +++++++------- src/libsyntax_ext/deriving/clone.rs | 4 ++-- src/libsyntax_ext/deriving/cmp/eq.rs | 4 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 20 ++++++++++---------- src/libsyntax_ext/deriving/generic/ty.rs | 20 ++++++++++---------- src/libsyntax_ext/deriving/mod.rs | 2 +- src/libsyntax_ext/env.rs | 4 ++-- 22 files changed, 123 insertions(+), 124 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d00792be4eb..4660352b28b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -810,7 +810,7 @@ impl<'a> LoweringContext<'a> { { let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs( generics.params.iter().filter_map(|p| match p { - GenericParam::Lifetime(ld) => Some(ld), + GenericParamAST::Lifetime(ld) => Some(ld), _ => None, }), |this| { @@ -1040,14 +1040,14 @@ impl<'a> LoweringContext<'a> { } fn lower_generic_arg(&mut self, - p: &ast::GenericArg, + p: &ast::GenericArgAST, itctx: ImplTraitContext) -> hir::GenericArg { match p { - ast::GenericArg::Lifetime(lt) => { + ast::GenericArgAST::Lifetime(lt) => { GenericArg::Lifetime(self.lower_lifetime(<)) } - ast::GenericArg::Type(ty) => { + ast::GenericArgAST::Type(ty) => { GenericArg::Type(self.lower_ty(&ty, itctx)) } } @@ -1069,7 +1069,7 @@ impl<'a> LoweringContext<'a> { } TyKind::BareFn(ref f) => self.with_in_scope_lifetime_defs( f.generic_params.iter().filter_map(|p| match p { - GenericParam::Lifetime(ld) => Some(ld), + GenericParamAST::Lifetime(ld) => Some(ld), _ => None, }), |this| { @@ -1980,17 +1980,17 @@ impl<'a> LoweringContext<'a> { fn lower_generic_params( &mut self, - params: &Vec, + params: &Vec, add_bounds: &NodeMap>, itctx: ImplTraitContext, ) -> hir::HirVec { params .iter() .map(|param| match *param { - GenericParam::Lifetime(ref lifetime_def) => { + GenericParamAST::Lifetime(ref lifetime_def) => { hir::GenericParam::Lifetime(self.lower_lifetime_def(lifetime_def)) } - GenericParam::Type(ref ty_param) => hir::GenericParam::Type(self.lower_ty_param( + GenericParamAST::Type(ref ty_param) => hir::GenericParam::Type(self.lower_ty_param( ty_param, add_bounds.get(&ty_param.id).map_or(&[][..], |x| &x), itctx, @@ -2030,7 +2030,7 @@ impl<'a> LoweringContext<'a> { self.resolver.definitions().as_local_node_id(def_id) { for param in &g.params { - if let GenericParam::Type(ref ty_param) = *param { + if let GenericParamAST::Type(ref ty_param) = *param { if node_id == ty_param.id { add_bounds .entry(ty_param.id) @@ -2078,7 +2078,7 @@ impl<'a> LoweringContext<'a> { }) => { self.with_in_scope_lifetime_defs( bound_generic_params.iter().filter_map(|p| match p { - GenericParam::Lifetime(ld) => Some(ld), + GenericParamAST::Lifetime(ld) => Some(ld), _ => None, }), |this| { @@ -2397,7 +2397,7 @@ impl<'a> LoweringContext<'a> { let new_impl_items = self.with_in_scope_lifetime_defs( ast_generics.params.iter().filter_map(|p| match p { - GenericParam::Lifetime(ld) => Some(ld), + GenericParamAST::Lifetime(ld) => Some(ld), _ => None, }), |this| { diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index 48d959b4f8e..7ab6e17ac35 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -170,9 +170,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { } } - fn visit_generic_param(&mut self, param: &'a GenericParam) { + fn visit_generic_param(&mut self, param: &'a GenericParamAST) { match *param { - GenericParam::Lifetime(ref lifetime_def) => { + GenericParamAST::Lifetime(ref lifetime_def) => { self.create_def( lifetime_def.lifetime.id, DefPathData::LifetimeDef(lifetime_def.lifetime.ident.name.as_interned_str()), @@ -180,7 +180,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { lifetime_def.lifetime.ident.span ); } - GenericParam::Type(ref ty_param) => { + GenericParamAST::Type(ref ty_param) => { self.create_def( ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_interned_str()), diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 824930a7eb0..7236eebdb6f 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -990,7 +990,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { run_lints!(self, check_expr_post, early_passes, e); } - fn visit_generic_param(&mut self, param: &'a ast::GenericParam) { + fn visit_generic_param(&mut self, param: &'a ast::GenericParamAST) { run_lints!(self, check_generic_param, early_passes, param); ast_visit::walk_generic_param(self, param); } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 9338e235c53..3d31a651b2f 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -254,7 +254,7 @@ pub trait EarlyLintPass: LintPass { fn check_expr(&mut self, _: &EarlyContext, _: &ast::Expr) { } fn check_expr_post(&mut self, _: &EarlyContext, _: &ast::Expr) { } fn check_ty(&mut self, _: &EarlyContext, _: &ast::Ty) { } - fn check_generic_param(&mut self, _: &EarlyContext, _: &ast::GenericParam) { } + fn check_generic_param(&mut self, _: &EarlyContext, _: &ast::GenericParamAST) { } fn check_generics(&mut self, _: &EarlyContext, _: &ast::Generics) { } fn check_where_predicate(&mut self, _: &EarlyContext, _: &ast::WherePredicate) { } fn check_poly_trait_ref(&mut self, _: &EarlyContext, _: &ast::PolyTraitRef, diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 211a45bc3c5..b50407c82d1 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -138,12 +138,12 @@ impl<'a> AstValidator<'a> { } } - fn check_late_bound_lifetime_defs(&self, params: &Vec) { + fn check_late_bound_lifetime_defs(&self, params: &Vec) { // Check: Only lifetime parameters let non_lifetime_param_spans : Vec<_> = params.iter() .filter_map(|param| match *param { - GenericParam::Lifetime(_) => None, - GenericParam::Type(ref t) => Some(t.ident.span), + GenericParamAST::Lifetime(_) => None, + GenericParamAST::Type(ref t) => Some(t.ident.span), }).collect(); if !non_lifetime_param_spans.is_empty() { self.err_handler().span_err(non_lifetime_param_spans, @@ -153,14 +153,14 @@ impl<'a> AstValidator<'a> { // Check: No bounds on lifetime parameters for param in params.iter() { match *param { - GenericParam::Lifetime(ref l) => { + GenericParamAST::Lifetime(ref l) => { if !l.bounds.is_empty() { let spans: Vec<_> = l.bounds.iter().map(|b| b.ident.span).collect(); self.err_handler().span_err(spans, "lifetime bounds cannot be used in this context"); } } - GenericParam::Type(_) => {} + GenericParamAST::Type(_) => {} } } } @@ -335,7 +335,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } ItemKind::TraitAlias(Generics { ref params, .. }, ..) => { for param in params { - if let GenericParam::Type(TyParam { + if let GenericParamAST::Type(TyParam { ident, ref bounds, ref default, @@ -414,17 +414,17 @@ impl<'a> Visitor<'a> for AstValidator<'a> { let mut seen_default = None; for param in &g.params { match (param, seen_non_lifetime_param) { - (&GenericParam::Lifetime(ref ld), true) => { + (&GenericParamAST::Lifetime(ref ld), true) => { self.err_handler() .span_err(ld.lifetime.ident.span, "lifetime parameters must be leading"); }, - (&GenericParam::Lifetime(_), false) => {} + (&GenericParamAST::Lifetime(_), false) => {} _ => { seen_non_lifetime_param = true; } } - if let GenericParam::Type(ref ty_param @ TyParam { default: Some(_), .. }) = *param { + if let GenericParamAST::Type(ref ty_param @ TyParam { default: Some(_), .. }) = *param { seen_default = Some(ty_param.ident.span); } else if let Some(span) = seen_default { self.err_handler() diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a2b2096ccaa..d70a7e2b827 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -56,7 +56,7 @@ use syntax::util::lev_distance::find_best_match_for_name; use syntax::visit::{self, FnKind, Visitor}; use syntax::attr; use syntax::ast::{Arm, BindingMode, Block, Crate, Expr, ExprKind}; -use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, GenericParam, Generics}; +use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, GenericParamAST, Generics}; use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind}; use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path}; use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind}; @@ -798,14 +798,14 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { // them one by one as they are processed and become available. let mut default_ban_rib = Rib::new(ForwardTyParamBanRibKind); default_ban_rib.bindings.extend(generics.params.iter() - .filter_map(|p| if let GenericParam::Type(ref tp) = *p { Some(tp) } else { None }) + .filter_map(|p| if let GenericParamAST::Type(ref tp) = *p { Some(tp) } else { None }) .skip_while(|p| p.default.is_none()) .map(|p| (Ident::with_empty_ctxt(p.ident.name), Def::Err))); for param in &generics.params { match *param { - GenericParam::Lifetime(_) => self.visit_generic_param(param), - GenericParam::Type(ref ty_param) => { + GenericParamAST::Lifetime(_) => self.visit_generic_param(param), + GenericParamAST::Type(ref ty_param) => { for bound in &ty_param.bounds { self.visit_ty_param_bound(bound); } @@ -2198,7 +2198,7 @@ impl<'a> Resolver<'a> { let mut function_type_rib = Rib::new(rib_kind); let mut seen_bindings = FxHashMap(); for param in &generics.params { - if let GenericParam::Type(ref type_parameter) = *param { + if let GenericParamAST::Type(ref type_parameter) = *param { let ident = type_parameter.ident.modern(); debug!("with_type_parameter_rib: {}", type_parameter.id); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 055d58f0b1f..303406dac76 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -370,7 +370,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { id: NodeId, ) { for param in &generics.params { - if let ast::GenericParam::Type(ref ty_param) = *param { + if let ast::GenericParamAST::Type(ref ty_param) = *param { let param_ss = ty_param.ident.span; let name = escape(self.span.snippet(param_ss)); // Append $id to name to make sure each one is unique @@ -1479,7 +1479,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc fn visit_generics(&mut self, generics: &'l ast::Generics) { for param in &generics.params { - if let ast::GenericParam::Type(ref ty_param) = *param { + if let ast::GenericParamAST::Type(ref ty_param) = *param { for bound in ty_param.bounds.iter() { if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 8a44f271055..a634e979363 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -935,8 +935,8 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String { .params .iter() .map(|param| match *param { - ast::GenericParam::Lifetime(ref l) => l.lifetime.ident.name.to_string(), - ast::GenericParam::Type(ref t) => t.ident.to_string(), + ast::GenericParamAST::Lifetime(ref l) => l.lifetime.ident.name.to_string(), + ast::GenericParamAST::Type(ref t) => t.ident.to_string(), }) .collect::>() .join(", ")); diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index e3545e8f1a9..f5384683506 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -224,7 +224,7 @@ impl Sig for ast::Ty { text.push_str(&f.generic_params .iter() .filter_map(|p| match *p { - ast::GenericParam::Lifetime(ref l) => { + ast::GenericParamAST::Lifetime(ref l) => { Some(l.lifetime.ident.to_string()) } _ => None, @@ -618,7 +618,7 @@ impl Sig for ast::Generics { let mut defs = vec![]; for param in &self.params { match *param { - ast::GenericParam::Lifetime(ref l) => { + ast::GenericParamAST::Lifetime(ref l) => { let mut l_text = l.lifetime.ident.to_string(); defs.push(SigElement { id: id_from_node_id(l.lifetime.id, scx), @@ -639,7 +639,7 @@ impl Sig for ast::Generics { text.push_str(&l_text); text.push(','); } - ast::GenericParam::Type(ref t) => { + ast::GenericParamAST::Type(ref t) => { let mut t_text = t.ident.to_string(); defs.push(SigElement { id: id_from_node_id(t.id, scx), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 5ae520050e5..17df8dd7027 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -168,7 +168,7 @@ impl GenericArgs { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum GenericArg { +pub enum GenericArgAST { Lifetime(Lifetime), Type(P), } @@ -179,7 +179,7 @@ pub struct AngleBracketedArgs { /// Overall span pub span: Span, /// The arguments for this path segment. - pub args: Vec, + pub args: Vec, /// Bindings (equality constraints) on associated types, if present. /// /// E.g., `Foo`. @@ -189,7 +189,7 @@ pub struct AngleBracketedArgs { impl AngleBracketedArgs { pub fn lifetimes(&self) -> impl DoubleEndedIterator { self.args.iter().filter_map(|arg| { - if let GenericArg::Lifetime(lt) = arg { + if let GenericArgAST::Lifetime(lt) = arg { Some(lt) } else { None @@ -199,7 +199,7 @@ impl AngleBracketedArgs { pub fn types(&self) -> impl DoubleEndedIterator> { self.args.iter().filter_map(|arg| { - if let GenericArg::Type(ty) = arg { + if let GenericArgAST::Type(ty) = arg { Some(ty) } else { None @@ -338,22 +338,22 @@ pub struct TyParam { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum GenericParam { +pub enum GenericParamAST { Lifetime(LifetimeDef), Type(TyParam), } -impl GenericParam { +impl GenericParamAST { pub fn is_lifetime_param(&self) -> bool { match *self { - GenericParam::Lifetime(_) => true, + GenericParamAST::Lifetime(_) => true, _ => false, } } pub fn is_type_param(&self) -> bool { match *self { - GenericParam::Type(_) => true, + GenericParamAST::Type(_) => true, _ => false, } } @@ -363,7 +363,7 @@ impl GenericParam { /// a function, enum, trait, etc. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Generics { - pub params: Vec, + pub params: Vec, pub where_clause: WhereClause, pub span: Span, } @@ -383,7 +383,7 @@ impl Generics { pub fn span_for_name(&self, name: &str) -> Option { for param in &self.params { - if let GenericParam::Type(ref t) = *param { + if let GenericParamAST::Type(ref t) = *param { if t.ident.name == name { return Some(t.ident.span); } @@ -444,7 +444,7 @@ impl WherePredicate { pub struct WhereBoundPredicate { pub span: Span, /// Any generics from a `for` binding - pub bound_generic_params: Vec, + pub bound_generic_params: Vec, /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) @@ -1576,7 +1576,7 @@ impl fmt::Debug for Ty { pub struct BareFnTy { pub unsafety: Unsafety, pub abi: Abi, - pub generic_params: Vec, + pub generic_params: Vec, pub decl: P } @@ -1955,7 +1955,7 @@ pub struct TraitRef { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct PolyTraitRef { /// The `'a` in `<'a> Foo<&'a T>` - pub bound_generic_params: Vec, + pub bound_generic_params: Vec, /// The `Foo<&'a T>` in `<'a> Foo<&'a T>` pub trait_ref: TraitRef, @@ -1964,7 +1964,7 @@ pub struct PolyTraitRef { } impl PolyTraitRef { - pub fn new(generic_params: Vec, path: Path, span: Span) -> Self { + pub fn new(generic_params: Vec, path: Path, span: Span) -> Self { PolyTraitRef { bound_generic_params: generic_params, trait_ref: TraitRef { path: path, ref_id: DUMMY_NODE_ID }, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c544adb5c1c..1c74a2bd5be 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -31,7 +31,7 @@ pub trait AstBuilder { fn path_all(&self, sp: Span, global: bool, idents: Vec, - args: Vec, + args: Vec, bindings: Vec) -> ast::Path; @@ -42,7 +42,7 @@ pub trait AstBuilder { fn qpath_all(&self, self_type: P, trait_path: ast::Path, ident: ast::Ident, - args: Vec, + args: Vec, bindings: Vec) -> (ast::QSelf, ast::Path); @@ -314,7 +314,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, global: bool, mut idents: Vec , - args: Vec, + args: Vec, bindings: Vec ) -> ast::Path { let last_ident = idents.pop().unwrap(); @@ -356,7 +356,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self_type: P, trait_path: ast::Path, ident: ast::Ident, - args: Vec, + args: Vec, bindings: Vec) -> (ast::QSelf, ast::Path) { let mut path = trait_path; @@ -424,7 +424,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.path_all(DUMMY_SP, true, self.std_path(&["option", "Option"]), - vec![ast::GenericArg::Type(ty)], + vec![ast::GenericArgAST::Type(ty)], Vec::new())) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index f74fe1feb40..1e09c7b2206 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -132,10 +132,10 @@ pub trait Folder : Sized { noop_fold_exprs(es, self) } - fn fold_generic_arg(&mut self, arg: GenericArg) -> GenericArg { + fn fold_generic_arg(&mut self, arg: GenericArgAST) -> GenericArgAST { match arg { - GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.fold_lifetime(lt)), - GenericArg::Type(ty) => GenericArg::Type(self.fold_ty(ty)), + GenericArgAST::Lifetime(lt) => GenericArgAST::Lifetime(self.fold_lifetime(lt)), + GenericArgAST::Type(ty) => GenericArgAST::Type(self.fold_ty(ty)), } } @@ -244,11 +244,11 @@ pub trait Folder : Sized { noop_fold_ty_param(tp, self) } - fn fold_generic_param(&mut self, param: GenericParam) -> GenericParam { + fn fold_generic_param(&mut self, param: GenericParamAST) -> GenericParamAST { noop_fold_generic_param(param, self) } - fn fold_generic_params(&mut self, params: Vec) -> Vec { + fn fold_generic_params(&mut self, params: Vec) -> Vec { noop_fold_generic_params(params, self) } @@ -702,11 +702,11 @@ pub fn noop_fold_ty_param(tp: TyParam, fld: &mut T) -> TyParam { } } -pub fn noop_fold_generic_param(param: GenericParam, fld: &mut T) -> GenericParam { +pub fn noop_fold_generic_param(param: GenericParamAST, fld: &mut T) -> GenericParamAST { match param { - GenericParam::Lifetime(l) => { + GenericParamAST::Lifetime(l) => { let attrs: Vec<_> = l.attrs.into(); - GenericParam::Lifetime(LifetimeDef { + GenericParamAST::Lifetime(LifetimeDef { attrs: attrs.into_iter() .flat_map(|x| fld.fold_attribute(x).into_iter()) .collect::>() @@ -718,14 +718,14 @@ pub fn noop_fold_generic_param(param: GenericParam, fld: &mut T) -> G bounds: l.bounds.move_map(|l| noop_fold_lifetime(l, fld)), }) } - GenericParam::Type(t) => GenericParam::Type(fld.fold_ty_param(t)), + GenericParamAST::Type(t) => GenericParamAST::Type(fld.fold_ty_param(t)), } } pub fn noop_fold_generic_params( - params: Vec, + params: Vec, fld: &mut T -) -> Vec { +) -> Vec { params.move_map(|p| fld.fold_generic_param(p)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a51b3bc0ae4..be4a4b8b11f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -21,8 +21,8 @@ use ast::EnumDef; use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; -use ast::GenericParam; -use ast::GenericArg; +use ast::GenericParamAST; +use ast::GenericArgAST; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind}; use ast::Local; @@ -1246,8 +1246,7 @@ impl<'a> Parser<'a> { } /// parse a TyKind::BareFn type: - fn parse_ty_bare_fn(&mut self, generic_params: Vec) - -> PResult<'a, TyKind> { + fn parse_ty_bare_fn(&mut self, generic_params: Vec) -> PResult<'a, TyKind> { /* [unsafe] [extern "ABI"] fn (S) -> T @@ -1566,7 +1565,7 @@ impl<'a> Parser<'a> { Ok(P(ty)) } - fn parse_remaining_bounds(&mut self, generic_params: Vec, path: ast::Path, + fn parse_remaining_bounds(&mut self, generic_params: Vec, path: ast::Path, lo: Span, parse_plus: bool) -> PResult<'a, TyKind> { let poly_trait_ref = PolyTraitRef::new(generic_params, path, lo.to(self.prev_span)); let mut bounds = vec![TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)]; @@ -4864,7 +4863,7 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type parameters, possibly including /// trailing comma and erroneous trailing attributes. - crate fn parse_generic_params(&mut self) -> PResult<'a, Vec> { + crate fn parse_generic_params(&mut self) -> PResult<'a, Vec> { let mut params = Vec::new(); let mut seen_ty_param = false; loop { @@ -4877,7 +4876,7 @@ impl<'a> Parser<'a> { } else { Vec::new() }; - params.push(ast::GenericParam::Lifetime(LifetimeDef { + params.push(ast::GenericParamAST::Lifetime(LifetimeDef { attrs: attrs.into(), lifetime, bounds, @@ -4888,7 +4887,7 @@ impl<'a> Parser<'a> { } } else if self.check_ident() { // Parse type parameter. - params.push(ast::GenericParam::Type(self.parse_ty_param(attrs)?)); + params.push(ast::GenericParamAST::Type(self.parse_ty_param(attrs)?)); seen_ty_param = true; } else { // Check for trailing attributes and stop parsing. @@ -4938,7 +4937,7 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings, /// possibly including trailing comma. fn parse_generic_args(&mut self) - -> PResult<'a, (Vec, Vec)> { + -> PResult<'a, (Vec, Vec)> { let mut args = Vec::new(); let mut bindings = Vec::new(); let mut seen_type = false; @@ -4946,7 +4945,7 @@ impl<'a> Parser<'a> { loop { if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { // Parse lifetime argument. - args.push(GenericArg::Lifetime(self.expect_lifetime())); + args.push(GenericArgAST::Lifetime(self.expect_lifetime())); if seen_type || seen_binding { self.span_err(self.prev_span, "lifetime parameters must be declared prior to type parameters"); @@ -4971,7 +4970,7 @@ impl<'a> Parser<'a> { self.span_err(ty_param.span, "type parameters must be declared prior to associated type bindings"); } - args.push(GenericArg::Type(ty_param)); + args.push(GenericArgAST::Type(ty_param)); seen_type = true; } else { break @@ -5693,7 +5692,7 @@ impl<'a> Parser<'a> { Ok((keywords::Invalid.ident(), item_kind, Some(attrs))) } - fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { + fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { if self.eat_keyword(keywords::For) { self.expect_lt()?; let params = self.parse_generic_params()?; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 3e0e533bc08..a7a85a4c71f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -13,7 +13,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::{self, Abi}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Attribute, MacDelimiter, GenericArg}; +use ast::{Attribute, MacDelimiter, GenericArgAST}; use util::parser::{self, AssocOp, Fixity}; use attr; use codemap::{self, CodeMap}; @@ -344,7 +344,7 @@ pub fn trait_item_to_string(i: &ast::TraitItem) -> String { to_string(|s| s.print_trait_item(i)) } -pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String { +pub fn generic_params_to_string(generic_params: &[ast::GenericParamAST]) -> String { to_string(|s| s.print_generic_params(generic_params)) } @@ -1017,10 +1017,10 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_generic_arg(&mut self, generic_arg: &GenericArg) -> io::Result<()> { + pub fn print_generic_arg(&mut self, generic_arg: &GenericArgAST) -> io::Result<()> { match generic_arg { - GenericArg::Lifetime(lt) => self.print_lifetime(lt), - GenericArg::Type(ty) => self.print_type(ty), + GenericArgAST::Lifetime(lt) => self.print_lifetime(lt), + GenericArgAST::Type(ty) => self.print_type(ty), } } @@ -1443,7 +1443,7 @@ impl<'a> State<'a> { fn print_formal_generic_params( &mut self, - generic_params: &[ast::GenericParam] + generic_params: &[ast::GenericParamAST] ) -> io::Result<()> { if !generic_params.is_empty() { self.s.word("for")?; @@ -2869,7 +2869,7 @@ impl<'a> State<'a> { pub fn print_generic_params( &mut self, - generic_params: &[ast::GenericParam] + generic_params: &[ast::GenericParamAST] ) -> io::Result<()> { if generic_params.is_empty() { return Ok(()); @@ -2879,11 +2879,11 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &generic_params, |s, param| { match *param { - ast::GenericParam::Lifetime(ref lifetime_def) => { + ast::GenericParamAST::Lifetime(ref lifetime_def) => { s.print_outer_attributes_inline(&lifetime_def.attrs)?; s.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds) }, - ast::GenericParam::Type(ref ty_param) => s.print_ty_param(ty_param), + ast::GenericParamAST::Type(ref ty_param) => s.print_ty_param(ty_param), } })?; @@ -3047,7 +3047,7 @@ impl<'a> State<'a> { unsafety: ast::Unsafety, decl: &ast::FnDecl, name: Option, - generic_params: &Vec) + generic_params: &Vec) -> io::Result<()> { self.ibox(INDENT_UNIT)?; if !generic_params.is_empty() { diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index 95ae9f9bcf8..caddd0513d1 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -71,7 +71,7 @@ impl<'ast> Visitor<'ast> for NodeCounter { self.count += 1; walk_ty(self, t) } - fn visit_generic_param(&mut self, param: &GenericParam) { + fn visit_generic_param(&mut self, param: &GenericParamAST) { self.count += 1; walk_generic_param(self, param) } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 5ac33701baf..8a4fde21e63 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -73,7 +73,7 @@ pub trait Visitor<'ast>: Sized { fn visit_expr(&mut self, ex: &'ast Expr) { walk_expr(self, ex) } fn visit_expr_post(&mut self, _ex: &'ast Expr) { } fn visit_ty(&mut self, t: &'ast Ty) { walk_ty(self, t) } - fn visit_generic_param(&mut self, param: &'ast GenericParam) { walk_generic_param(self, param) } + fn visit_generic_param(&mut self, param: &'ast GenericParamAST) { walk_generic_param(self, param) } fn visit_generics(&mut self, g: &'ast Generics) { walk_generics(self, g) } fn visit_where_predicate(&mut self, p: &'ast WherePredicate) { walk_where_predicate(self, p) @@ -131,10 +131,10 @@ pub trait Visitor<'ast>: Sized { fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) { walk_generic_args(self, path_span, generic_args) } - fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) { + fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArgAST) { match generic_arg { - GenericArg::Lifetime(lt) => self.visit_lifetime(lt), - GenericArg::Type(ty) => self.visit_ty(ty), + GenericArgAST::Lifetime(lt) => self.visit_lifetime(lt), + GenericArgAST::Type(ty) => self.visit_ty(ty), } } fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) { @@ -488,14 +488,14 @@ pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a TyPar } } -pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) { +pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParamAST) { match *param { - GenericParam::Lifetime(ref l) => { + GenericParamAST::Lifetime(ref l) => { visitor.visit_ident(l.lifetime.ident); walk_list!(visitor, visit_lifetime, &l.bounds); walk_list!(visitor, visit_attribute, &*l.attrs); } - GenericParam::Type(ref t) => { + GenericParamAST::Type(ref t) => { visitor.visit_ident(t.ident); walk_list!(visitor, visit_ty_param_bound, &t.bounds); walk_list!(visitor, visit_ty, &t.default); diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 504c3f8e913..40d49b49960 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -13,7 +13,7 @@ use deriving::generic::*; use deriving::generic::ty::*; use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; -use syntax::ast::GenericArg; +use syntax::ast::GenericArgAST; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -124,7 +124,7 @@ fn cs_clone_shallow(name: &str, let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["clone", helper_name]), - vec![GenericArg::Type(ty)], vec![]); + vec![GenericArgAST::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &VariantData) { diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index 00ab39032ac..e9bcf70e90c 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, Expr, MetaItem, GenericArg}; +use syntax::ast::{self, Expr, MetaItem, GenericArgAST}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -62,7 +62,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["cmp", helper_name]), - vec![GenericArg::Type(ty)], vec![]); + vec![GenericArgAST::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &ast::VariantData) { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 299c53f3101..f85091b0e71 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -192,8 +192,8 @@ use std::collections::HashSet; use std::vec; use rustc_target::spec::abi::Abi; -use syntax::ast::{self, BinOpKind, EnumDef, Expr, GenericParam, Generics, Ident, PatKind}; -use syntax::ast::{VariantData, GenericArg}; +use syntax::ast::{self, BinOpKind, EnumDef, Expr, GenericParamAST, Generics, Ident, PatKind}; +use syntax::ast::{VariantData, GenericArgAST}; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -548,8 +548,8 @@ impl<'a> TraitDef<'a> { // Create the generic parameters params.extend(generics.params.iter().map(|param| { match *param { - ref l @ GenericParam::Lifetime(_) => l.clone(), - GenericParam::Type(ref ty_param) => { + ref l @ GenericParamAST::Lifetime(_) => l.clone(), + GenericParamAST::Type(ref ty_param) => { // I don't think this can be moved out of the loop, since // a TyParamBound requires an ast id let mut bounds: Vec<_> = @@ -568,7 +568,7 @@ impl<'a> TraitDef<'a> { bounds.push((*declared_bound).clone()); } - GenericParam::Type(cx.typaram(self.span, ty_param.ident, vec![], bounds, None)) + GenericParamAST::Type(cx.typaram(self.span, ty_param.ident, vec![], bounds, None)) } } })); @@ -607,7 +607,7 @@ impl<'a> TraitDef<'a> { let mut ty_params = params.iter() .filter_map(|param| match *param { - ast::GenericParam::Type(ref t) => Some(t), + ast::GenericParamAST::Type(ref t) => Some(t), _ => None, }) .peekable(); @@ -668,7 +668,7 @@ impl<'a> TraitDef<'a> { let self_ty_params: Vec> = generics.params .iter() .filter_map(|param| match *param { - GenericParam::Type(ref ty_param) + GenericParamAST::Type(ref ty_param) => Some(cx.ty_ident(self.span, ty_param.ident)), _ => None, }) @@ -677,15 +677,15 @@ impl<'a> TraitDef<'a> { let self_lifetimes: Vec = generics.params .iter() .filter_map(|param| match *param { - GenericParam::Lifetime(ref ld) => Some(ld.lifetime), + GenericParamAST::Lifetime(ref ld) => Some(ld.lifetime), _ => None, }) .collect(); let self_params = self_lifetimes.into_iter() - .map(|lt| GenericArg::Lifetime(lt)) + .map(|lt| GenericArgAST::Lifetime(lt)) .chain(self_ty_params.into_iter().map(|ty| - GenericArg::Type(ty))) + GenericArgAST::Type(ty))) .collect(); // Create the type of `self`. diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 7e6dd5fad25..92046262ed2 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -15,7 +15,7 @@ pub use self::PtrTy::*; pub use self::Ty::*; use syntax::ast; -use syntax::ast::{Expr, GenericParam, Generics, Ident, SelfKind, GenericArg}; +use syntax::ast::{Expr, GenericParamAST, Generics, Ident, SelfKind, GenericArgAST}; use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::codemap::{respan, DUMMY_SP}; @@ -89,8 +89,8 @@ impl<'a> Path<'a> { let tys: Vec> = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect(); let params = lt.into_iter() - .map(|lt| GenericArg::Lifetime(lt)) - .chain(tys.into_iter().map(|ty| GenericArg::Type(ty))) + .map(|lt| GenericArgAST::Lifetime(lt)) + .chain(tys.into_iter().map(|ty| GenericArgAST::Type(ty))) .collect(); match self.kind { @@ -192,7 +192,7 @@ impl<'a> Ty<'a> { let ty_params: Vec> = self_generics.params .iter() .filter_map(|param| match *param { - GenericParam::Type(ref ty_param) => Some(cx.ty_ident(span, ty_param.ident)), + GenericParamAST::Type(ref ty_param) => Some(cx.ty_ident(span, ty_param.ident)), _ => None, }) .collect(); @@ -200,15 +200,15 @@ impl<'a> Ty<'a> { let lifetimes: Vec = self_generics.params .iter() .filter_map(|param| match *param { - GenericParam::Lifetime(ref ld) => Some(ld.lifetime), + GenericParamAST::Lifetime(ref ld) => Some(ld.lifetime), _ => None, }) .collect(); let params = lifetimes.into_iter() - .map(|lt| GenericArg::Lifetime(lt)) + .map(|lt| GenericArgAST::Lifetime(lt)) .chain(ty_params.into_iter().map(|ty| - GenericArg::Type(ty))) + GenericArgAST::Type(ty))) .collect(); cx.path_all(span, @@ -242,7 +242,7 @@ fn mk_ty_param(cx: &ExtCtxt, cx.typaram(span, cx.ident_of(name), attrs.to_owned(), bounds, None) } -fn mk_generics(params: Vec, span: Span) -> Generics { +fn mk_generics(params: Vec, span: Span) -> Generics { Generics { params, where_clause: ast::WhereClause { @@ -280,13 +280,13 @@ impl<'a> LifetimeBounds<'a> { let bounds = bounds.iter() .map(|b| cx.lifetime(span, Ident::from_str(b))) .collect(); - GenericParam::Lifetime(cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds)) + GenericParamAST::Lifetime(cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds)) }) .chain(self.bounds .iter() .map(|t| { let (name, ref bounds) = *t; - GenericParam::Type(mk_ty_param( + GenericParamAST::Type(mk_ty_param( cx, span, name, &[], &bounds, self_ty, self_generics )) }) diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index a5b348a661a..9bc19bb5ede 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -135,7 +135,7 @@ fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String { ast::ItemKind::Struct(_, ast::Generics { ref params, .. }) | ast::ItemKind::Enum(_, ast::Generics { ref params, .. }) => { for param in params.iter() { - if let ast::GenericParam::Type(ref ty) = *param{ + if let ast::GenericParamAST::Type(ref ty) = *param { typaram.push_str(&ty.ident.as_str()); } } diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index 5c3080260cc..a3254788d45 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -13,7 +13,7 @@ // interface. // -use syntax::ast::{self, Ident, GenericArg}; +use syntax::ast::{self, Ident, GenericArgAST}; use syntax::ext::base::*; use syntax::ext::base; use syntax::ext::build::AstBuilder; @@ -39,7 +39,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, cx.expr_path(cx.path_all(sp, true, cx.std_path(&["option", "Option", "None"]), - vec![GenericArg::Type(cx.ty_rptr(sp, + vec![GenericArgAST::Type(cx.ty_rptr(sp, cx.ty_ident(sp, Ident::from_str("str")), Some(lt), ast::Mutability::Immutable))], -- cgit 1.4.1-3-g733a5 From 2c6ff2469a94e37b9605a43bc861de66830a94d4 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 26 May 2018 19:16:21 +0100 Subject: Refactor ast::GenericParam as a struct --- src/librustc/hir/lowering.rs | 103 +++++++++++++++-------------- src/librustc/hir/map/def_collector.rs | 29 +++----- src/librustc_passes/ast_validation.rs | 88 +++++++++++------------- src/librustc_resolve/lib.rs | 73 ++++++++++++-------- src/librustc_save_analysis/dump_visitor.rs | 76 +++++++++++---------- src/librustc_save_analysis/lib.rs | 6 +- src/librustc_save_analysis/sig.rs | 53 ++++++--------- src/libsyntax/ast.rs | 47 ++++++------- src/libsyntax/ext/build.rs | 27 +++++--- src/libsyntax/fold.rs | 27 ++------ src/libsyntax/parse/parser.rs | 50 +++++++------- src/libsyntax/print/pprust.rs | 36 +++++----- src/libsyntax/visit.rs | 18 ++--- src/libsyntax_ext/deriving/generic/mod.rs | 28 ++++---- src/libsyntax_ext/deriving/generic/ty.rs | 23 +++---- src/libsyntax_ext/deriving/mod.rs | 9 ++- 16 files changed, 338 insertions(+), 355 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index ae7d8bd8403..68ceb39d575 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -759,20 +759,20 @@ impl<'a> LoweringContext<'a> { hir_name } - // Evaluates `f` with the lifetimes in `lt_defs` in-scope. + // Evaluates `f` with the lifetimes in `params` in-scope. // This is used to track which lifetimes have already been defined, and // which are new in-band lifetimes that need to have a definition created // for them. fn with_in_scope_lifetime_defs<'l, T, F>( &mut self, - lt_defs: impl Iterator, + params: impl Iterator, f: F, ) -> T where F: FnOnce(&mut LoweringContext) -> T, { let old_len = self.in_scope_lifetimes.len(); - let lt_def_names = lt_defs.map(|lt_def| lt_def.lifetime.ident.name); + let lt_def_names = params.map(|param| param.ident.name); self.in_scope_lifetimes.extend(lt_def_names); let res = f(self); @@ -781,8 +781,8 @@ impl<'a> LoweringContext<'a> { res } - // Same as the method above, but accepts `hir::LifetimeDef`s - // instead of `ast::LifetimeDef`s. + // Same as the method above, but accepts `hir::GenericParam`s + // instead of `ast::GenericParam`s. // This should only be used with generics that have already had their // in-band lifetimes added. In practice, this means that this function is // only used when lowering a child item of a trait or impl. @@ -817,8 +817,8 @@ impl<'a> LoweringContext<'a> { F: FnOnce(&mut LoweringContext) -> T, { let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs( - generics.params.iter().filter_map(|p| match p { - GenericParamAST::Lifetime(ld) => Some(ld), + generics.params.iter().filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { .. } => Some(param), _ => None, }), |this| { @@ -1076,8 +1076,8 @@ impl<'a> LoweringContext<'a> { hir::TyRptr(lifetime, self.lower_mt(mt, itctx)) } TyKind::BareFn(ref f) => self.with_in_scope_lifetime_defs( - f.generic_params.iter().filter_map(|p| match p { - GenericParamAST::Lifetime(ld) => Some(ld), + f.generic_params.iter().filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { .. } => Some(param), _ => None, }), |this| { @@ -1940,21 +1940,19 @@ impl<'a> LoweringContext<'a> { add_bounds: &NodeMap>, itctx: ImplTraitContext) -> hir::GenericParam { - match param { - GenericParamAST::Lifetime(ref lifetime_def) => { + match param.kind { + GenericParamKindAST::Lifetime { ref bounds, ref lifetime, .. } => { let was_collecting_in_band = self.is_collecting_in_band_lifetimes; self.is_collecting_in_band_lifetimes = false; - let lifetime = self.lower_lifetime(&lifetime_def.lifetime); + let lifetime = self.lower_lifetime(lifetime); let param = hir::GenericParam { id: lifetime.id, span: lifetime.span, - pure_wrt_drop: attr::contains_name(&lifetime_def.attrs, "may_dangle"), + pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), kind: hir::GenericParamKind::Lifetime { name: lifetime.name, - bounds: lifetime_def.bounds - .iter() - .map(|lt| self.lower_lifetime(lt)).collect(), + bounds: bounds.iter().map(|lt| self.lower_lifetime(lt)).collect(), in_band: false, lifetime_deprecated: lifetime, } @@ -1964,8 +1962,8 @@ impl<'a> LoweringContext<'a> { param } - GenericParamAST::Type(ref ty_param) => { - let mut name = self.lower_ident(ty_param.ident); + GenericParamKindAST::Type { ref bounds, ref default } => { + let mut name = self.lower_ident(param.ident); // Don't expose `Self` (recovered "keyword used as ident" parse error). // `rustc::ty` expects `Self` to be only used for a trait's `Self`. @@ -1974,8 +1972,8 @@ impl<'a> LoweringContext<'a> { name = Symbol::gensym("Self"); } - let mut bounds = self.lower_bounds(&ty_param.bounds, itctx); - let add_bounds = add_bounds.get(&ty_param.id).map_or(&[][..], |x| &x); + let mut bounds = self.lower_bounds(bounds, itctx); + let add_bounds = add_bounds.get(¶m.id).map_or(&[][..], |x| &x); if !add_bounds.is_empty() { bounds = bounds .into_iter() @@ -1984,22 +1982,20 @@ impl<'a> LoweringContext<'a> { } hir::GenericParam { - id: self.lower_node_id(ty_param.id).node_id, - span: ty_param.ident.span, - pure_wrt_drop: attr::contains_name(&ty_param.attrs, "may_dangle"), + id: self.lower_node_id(param.id).node_id, + span: param.ident.span, + pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), kind: hir::GenericParamKind::Type { name, bounds, - default: ty_param.default.as_ref() - .map(|x| { - self.lower_ty(x, ImplTraitContext::Disallowed) - }), - synthetic: ty_param.attrs - .iter() - .filter(|attr| attr.check_name("rustc_synthetic")) - .map(|_| hir::SyntheticTyParamKind::ImplTrait) - .nth(0), - attrs: self.lower_attrs(&ty_param.attrs), + default: default.as_ref().map(|x| { + self.lower_ty(x, ImplTraitContext::Disallowed) + }), + synthetic: param.attrs.iter() + .filter(|attr| attr.check_name("rustc_synthetic")) + .map(|_| hir::SyntheticTyParamKind::ImplTrait) + .nth(0), + attrs: self.lower_attrs(¶m.attrs), } } } @@ -2015,13 +2011,18 @@ impl<'a> LoweringContext<'a> { params.iter().map(|param| self.lower_generic_param(param, add_bounds, itctx)).collect() } - fn lower_generics(&mut self, g: &Generics, itctx: ImplTraitContext) -> hir::Generics { + fn lower_generics( + &mut self, + generics: &Generics, + itctx: ImplTraitContext) + -> hir::Generics + { // Collect `?Trait` bounds in where clause and move them to parameter definitions. // FIXME: This could probably be done with less rightward drift. Also looks like two control // paths where report_error is called are also the only paths that advance to after // the match statement, so the error reporting could probably just be moved there. let mut add_bounds = NodeMap(); - for pred in &g.where_clause.predicates { + for pred in &generics.where_clause.predicates { if let WherePredicate::BoundPredicate(ref bound_pred) = *pred { 'next_bound: for bound in &bound_pred.bounds { if let TraitTyParamBound(_, TraitBoundModifier::Maybe) = *bound { @@ -2045,15 +2046,17 @@ impl<'a> LoweringContext<'a> { if let Some(node_id) = self.resolver.definitions().as_local_node_id(def_id) { - for param in &g.params { - if let GenericParamAST::Type(ref ty_param) = *param { - if node_id == ty_param.id { - add_bounds - .entry(ty_param.id) - .or_insert(Vec::new()) - .push(bound.clone()); - continue 'next_bound; + for param in &generics.params { + match param.kind { + GenericParamKindAST::Type { .. } => { + if node_id == param.id { + add_bounds.entry(param.id) + .or_insert(Vec::new()) + .push(bound.clone()); + continue 'next_bound; + } } + _ => {} } } } @@ -2068,9 +2071,9 @@ impl<'a> LoweringContext<'a> { } hir::Generics { - params: self.lower_generic_params(&g.params, &add_bounds, itctx), - where_clause: self.lower_where_clause(&g.where_clause), - span: g.span, + params: self.lower_generic_params(&generics.params, &add_bounds, itctx), + where_clause: self.lower_where_clause(&generics.where_clause), + span: generics.span, } } @@ -2093,8 +2096,8 @@ impl<'a> LoweringContext<'a> { span, }) => { self.with_in_scope_lifetime_defs( - bound_generic_params.iter().filter_map(|p| match p { - GenericParamAST::Lifetime(ld) => Some(ld), + bound_generic_params.iter().filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { .. } => Some(param), _ => None, }), |this| { @@ -2412,8 +2415,8 @@ impl<'a> LoweringContext<'a> { ); let new_impl_items = self.with_in_scope_lifetime_defs( - ast_generics.params.iter().filter_map(|p| match p { - GenericParamAST::Lifetime(ld) => Some(ld), + ast_generics.params.iter().filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { .. } => Some(param), _ => None, }), |this| { diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index 7ab6e17ac35..6015063aa82 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -171,24 +171,17 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { } fn visit_generic_param(&mut self, param: &'a GenericParamAST) { - match *param { - GenericParamAST::Lifetime(ref lifetime_def) => { - self.create_def( - lifetime_def.lifetime.id, - DefPathData::LifetimeDef(lifetime_def.lifetime.ident.name.as_interned_str()), - REGULAR_SPACE, - lifetime_def.lifetime.ident.span - ); - } - GenericParamAST::Type(ref ty_param) => { - self.create_def( - ty_param.id, - DefPathData::TypeParam(ty_param.ident.name.as_interned_str()), - REGULAR_SPACE, - ty_param.ident.span - ); - } - } + let name = param.ident.name.as_interned_str(); + let def_path_data = match param.kind { + GenericParamKindAST::Lifetime { .. } => DefPathData::LifetimeDef(name), + GenericParamKindAST::Type { .. } => DefPathData::TypeParam(name), + }; + self.create_def( + param.id, + def_path_data, + REGULAR_SPACE, + param.ident.span + ); visit::walk_generic_param(self, param); } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index b50407c82d1..d7ebd40f49b 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -139,29 +139,23 @@ impl<'a> AstValidator<'a> { } fn check_late_bound_lifetime_defs(&self, params: &Vec) { - // Check: Only lifetime parameters - let non_lifetime_param_spans : Vec<_> = params.iter() - .filter_map(|param| match *param { - GenericParamAST::Lifetime(_) => None, - GenericParamAST::Type(ref t) => Some(t.ident.span), - }).collect(); - if !non_lifetime_param_spans.is_empty() { - self.err_handler().span_err(non_lifetime_param_spans, - "only lifetime parameters can be used in this context"); - } - - // Check: No bounds on lifetime parameters - for param in params.iter() { - match *param { - GenericParamAST::Lifetime(ref l) => { - if !l.bounds.is_empty() { - let spans: Vec<_> = l.bounds.iter().map(|b| b.ident.span).collect(); + // Check only lifetime parameters are present and that the lifetime + // parameters that are present have no bounds. + let non_lifetime_param_spans: Vec<_> = params.iter() + .filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { ref bounds, .. } => { + if !bounds.is_empty() { + let spans: Vec<_> = bounds.iter().map(|b| b.ident.span).collect(); self.err_handler().span_err(spans, "lifetime bounds cannot be used in this context"); } + None } - GenericParamAST::Type(_) => {} - } + _ => Some(param.ident.span), + }).collect(); + if !non_lifetime_param_spans.is_empty() { + self.err_handler().span_err(non_lifetime_param_spans, + "only lifetime parameters can be used in this context"); } } } @@ -335,22 +329,21 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } ItemKind::TraitAlias(Generics { ref params, .. }, ..) => { for param in params { - if let GenericParamAST::Type(TyParam { - ident, - ref bounds, - ref default, - .. - }) = *param - { - if !bounds.is_empty() { - self.err_handler().span_err(ident.span, - "type parameters on the left side of a \ - trait alias cannot be bounded"); - } - if !default.is_none() { - self.err_handler().span_err(ident.span, - "type parameters on the left side of a \ - trait alias cannot have defaults"); + match param.kind { + GenericParamKindAST::Lifetime { .. } => {} + GenericParamKindAST::Type { ref bounds, ref default, .. } => { + if !bounds.is_empty() { + self.err_handler().span_err(param.ident.span, + "type parameters on the left side \ + of a trait alias cannot be \ + bounded"); + } + if !default.is_none() { + self.err_handler().span_err(param.ident.span, + "type parameters on the left side \ + of a trait alias cannot have \ + defaults"); + } } } } @@ -413,24 +406,23 @@ impl<'a> Visitor<'a> for AstValidator<'a> { let mut seen_non_lifetime_param = false; let mut seen_default = None; for param in &g.params { - match (param, seen_non_lifetime_param) { - (&GenericParamAST::Lifetime(ref ld), true) => { + match (¶m.kind, seen_non_lifetime_param) { + (GenericParamKindAST::Lifetime { .. }, true) => { self.err_handler() - .span_err(ld.lifetime.ident.span, "lifetime parameters must be leading"); + .span_err(param.ident.span, "lifetime parameters must be leading"); }, - (&GenericParamAST::Lifetime(_), false) => {} - _ => { + (GenericParamKindAST::Lifetime { .. }, false) => {} + (GenericParamKindAST::Type { ref default, .. }, _) => { seen_non_lifetime_param = true; + if default.is_some() { + seen_default = Some(param.ident.span); + } else if let Some(span) = seen_default { + self.err_handler() + .span_err(span, "type parameters with a default must be trailing"); + break; + } } } - - if let GenericParamAST::Type(ref ty_param @ TyParam { default: Some(_), .. }) = *param { - seen_default = Some(ty_param.ident.span); - } else if let Some(span) = seen_default { - self.err_handler() - .span_err(span, "type parameters with a default must be trailing"); - break - } } for predicate in &g.where_clause.predicates { if let WherePredicate::EqPredicate(ref predicate) = *predicate { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index d70a7e2b827..37264eb3382 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -56,7 +56,7 @@ use syntax::util::lev_distance::find_best_match_for_name; use syntax::visit::{self, FnKind, Visitor}; use syntax::attr; use syntax::ast::{Arm, BindingMode, Block, Crate, Expr, ExprKind}; -use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, GenericParamAST, Generics}; +use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, GenericParamKindAST, Generics}; use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind}; use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path}; use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind}; @@ -797,31 +797,43 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { // put all the parameters on the ban list and then remove // them one by one as they are processed and become available. let mut default_ban_rib = Rib::new(ForwardTyParamBanRibKind); + let mut found_default = false; default_ban_rib.bindings.extend(generics.params.iter() - .filter_map(|p| if let GenericParamAST::Type(ref tp) = *p { Some(tp) } else { None }) - .skip_while(|p| p.default.is_none()) - .map(|p| (Ident::with_empty_ctxt(p.ident.name), Def::Err))); + .filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { .. } => None, + GenericParamKindAST::Type { ref default, .. } => { + if default.is_some() { + found_default = true; + } + if found_default { + return Some((Ident::with_empty_ctxt(param.ident.name), Def::Err)); + } + None + } + })); for param in &generics.params { - match *param { - GenericParamAST::Lifetime(_) => self.visit_generic_param(param), - GenericParamAST::Type(ref ty_param) => { - for bound in &ty_param.bounds { + match param.kind { + GenericParamKindAST::Lifetime { .. } => self.visit_generic_param(param), + GenericParamKindAST::Type { ref bounds, ref default, .. } => { + for bound in bounds { self.visit_ty_param_bound(bound); } - if let Some(ref ty) = ty_param.default { + if let Some(ref ty) = default { self.ribs[TypeNS].push(default_ban_rib); self.visit_ty(ty); default_ban_rib = self.ribs[TypeNS].pop().unwrap(); } // Allow all following defaults to refer to this type parameter. - default_ban_rib.bindings.remove(&Ident::with_empty_ctxt(ty_param.ident.name)); + default_ban_rib.bindings.remove(&Ident::with_empty_ctxt(param.ident.name)); } } } - for p in &generics.where_clause.predicates { self.visit_where_predicate(p); } + for p in &generics.where_clause.predicates { + self.visit_where_predicate(p); + } } } @@ -2198,25 +2210,28 @@ impl<'a> Resolver<'a> { let mut function_type_rib = Rib::new(rib_kind); let mut seen_bindings = FxHashMap(); for param in &generics.params { - if let GenericParamAST::Type(ref type_parameter) = *param { - let ident = type_parameter.ident.modern(); - debug!("with_type_parameter_rib: {}", type_parameter.id); - - if seen_bindings.contains_key(&ident) { - let span = seen_bindings.get(&ident).unwrap(); - let err = ResolutionError::NameAlreadyUsedInTypeParameterList( - ident.name, - span, - ); - resolve_error(self, type_parameter.ident.span, err); - } - seen_bindings.entry(ident).or_insert(type_parameter.ident.span); + match param.kind { + GenericParamKindAST::Type { .. } => { + let ident = param.ident.modern(); + debug!("with_type_parameter_rib: {}", param.id); + + if seen_bindings.contains_key(&ident) { + let span = seen_bindings.get(&ident).unwrap(); + let err = ResolutionError::NameAlreadyUsedInTypeParameterList( + ident.name, + span, + ); + resolve_error(self, param.ident.span, err); + } + seen_bindings.entry(ident).or_insert(param.ident.span); - // plain insert (no renaming) - let def_id = self.definitions.local_def_id(type_parameter.id); - let def = Def::TyParam(def_id); - function_type_rib.bindings.insert(ident, def); - self.record_def(type_parameter.id, PathResolution::new(def)); + // plain insert (no renaming) + let def_id = self.definitions.local_def_id(param.id); + let def = Def::TyParam(def_id); + function_type_rib.bindings.insert(ident, def); + self.record_def(param.id, PathResolution::new(def)); + } + _ => {} } } self.ribs[TypeNS].push(function_type_rib); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 303406dac76..94552e08a8c 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -370,35 +370,38 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { id: NodeId, ) { for param in &generics.params { - if let ast::GenericParamAST::Type(ref ty_param) = *param { - let param_ss = ty_param.ident.span; - let name = escape(self.span.snippet(param_ss)); - // Append $id to name to make sure each one is unique - let qualname = format!("{}::{}${}", prefix, name, id); - if !self.span.filter_generated(Some(param_ss), full_span) { - let id = ::id_from_node_id(ty_param.id, &self.save_ctxt); - let span = self.span_from_span(param_ss); + match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => {} + ast::GenericParamKindAST::Type { .. } => { + let param_ss = param.ident.span; + let name = escape(self.span.snippet(param_ss)); + // Append $id to name to make sure each one is unique. + let qualname = format!("{}::{}${}", prefix, name, id); + if !self.span.filter_generated(Some(param_ss), full_span) { + let id = ::id_from_node_id(param.id, &self.save_ctxt); + let span = self.span_from_span(param_ss); - self.dumper.dump_def( - &Access { - public: false, - reachable: false, - }, - Def { - kind: DefKind::Type, - id, - span, - name, - qualname, - value: String::new(), - parent: None, - children: vec![], - decl_id: None, - docs: String::new(), - sig: None, - attributes: vec![], - }, - ); + self.dumper.dump_def( + &Access { + public: false, + reachable: false, + }, + Def { + kind: DefKind::Type, + id, + span, + name, + qualname, + value: String::new(), + parent: None, + children: vec![], + decl_id: None, + docs: String::new(), + sig: None, + attributes: vec![], + }, + ); + } } } } @@ -1479,14 +1482,17 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc fn visit_generics(&mut self, generics: &'l ast::Generics) { for param in &generics.params { - if let ast::GenericParamAST::Type(ref ty_param) = *param { - for bound in ty_param.bounds.iter() { - if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { - self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) + match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => {} + ast::GenericParamKindAST::Type { ref bounds, ref default, .. } => { + for bound in bounds { + if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { + self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) + } + } + if let Some(ref ty) = default { + self.visit_ty(&ty); } - } - if let Some(ref ty) = ty_param.default { - self.visit_ty(&ty); } } } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index a634e979363..f656b013c0a 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -934,9 +934,9 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String { sig.push_str(&generics .params .iter() - .map(|param| match *param { - ast::GenericParamAST::Lifetime(ref l) => l.lifetime.ident.name.to_string(), - ast::GenericParamAST::Type(ref t) => t.ident.to_string(), + .map(|param| match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => param.ident.name.to_string(), + ast::GenericParamKindAST::Type { .. } => param.ident.to_string(), }) .collect::>() .join(", ")); diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index f5384683506..8e8e0dfa182 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -223,9 +223,9 @@ impl Sig for ast::Ty { text.push_str("for<"); text.push_str(&f.generic_params .iter() - .filter_map(|p| match *p { - ast::GenericParamAST::Lifetime(ref l) => { - Some(l.lifetime.ident.to_string()) + .filter_map(|param| match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => { + Some(param.ident.to_string()) } _ => None, }) @@ -617,45 +617,34 @@ impl Sig for ast::Generics { let mut defs = vec![]; for param in &self.params { - match *param { - ast::GenericParamAST::Lifetime(ref l) => { - let mut l_text = l.lifetime.ident.to_string(); - defs.push(SigElement { - id: id_from_node_id(l.lifetime.id, scx), - start: offset + text.len(), - end: offset + text.len() + l_text.len(), - }); - - if !l.bounds.is_empty() { - l_text.push_str(": "); - let bounds = l.bounds - .iter() + let mut param_text = param.ident.to_string(); + defs.push(SigElement { + id: id_from_node_id(param.id, scx), + start: offset + text.len(), + end: offset + text.len() + param_text.len(), + }); + match param.kind { + ast::GenericParamKindAST::Lifetime { ref bounds, .. } => { + if !bounds.is_empty() { + param_text.push_str(": "); + let bounds = bounds.iter() .map(|l| l.ident.to_string()) .collect::>() .join(" + "); - l_text.push_str(&bounds); + param_text.push_str(&bounds); // FIXME add lifetime bounds refs. } - text.push_str(&l_text); - text.push(','); } - ast::GenericParamAST::Type(ref t) => { - let mut t_text = t.ident.to_string(); - defs.push(SigElement { - id: id_from_node_id(t.id, scx), - start: offset + text.len(), - end: offset + text.len() + t_text.len(), - }); - - if !t.bounds.is_empty() { - t_text.push_str(": "); - t_text.push_str(&pprust::bounds_to_string(&t.bounds)); + ast::GenericParamKindAST::Type { ref bounds, .. } => { + if !bounds.is_empty() { + param_text.push_str(": "); + param_text.push_str(&pprust::bounds_to_string(bounds)); // FIXME descend properly into bounds. } - text.push_str(&t_text); - text.push(','); } } + text.push_str(¶m_text); + text.push(','); } text.push('>'); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 17df8dd7027..c354edc5aaf 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -58,14 +58,6 @@ impl fmt::Debug for Lifetime { } } -/// A lifetime definition, e.g. `'a: 'b+'c+'d` -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub struct LifetimeDef { - pub attrs: ThinVec, - pub lifetime: Lifetime, - pub bounds: Vec -} - /// A "Path" is essentially Rust's notion of a name. /// /// It's represented as a sequence of identifiers, @@ -329,31 +321,38 @@ pub enum TraitBoundModifier { pub type TyParamBounds = Vec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub struct TyParam { - pub attrs: ThinVec, - pub ident: Ident, - pub id: NodeId, - pub bounds: TyParamBounds, - pub default: Option>, +pub enum GenericParamKindAST { + /// A lifetime definition, e.g. `'a: 'b+'c+'d`. + Lifetime { + bounds: Vec, + lifetime: Lifetime, + }, + Type { + bounds: TyParamBounds, + default: Option>, + } } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum GenericParamAST { - Lifetime(LifetimeDef), - Type(TyParam), +pub struct GenericParamAST { + pub ident: Ident, + pub id: NodeId, + pub attrs: ThinVec, + + pub kind: GenericParamKindAST, } impl GenericParamAST { pub fn is_lifetime_param(&self) -> bool { - match *self { - GenericParamAST::Lifetime(_) => true, + match self.kind { + GenericParamKindAST::Lifetime { .. } => true, _ => false, } } pub fn is_type_param(&self) -> bool { - match *self { - GenericParamAST::Type(_) => true, + match self.kind { + GenericParamKindAST::Type { .. } => true, _ => false, } } @@ -383,10 +382,8 @@ impl Generics { pub fn span_for_name(&self, name: &str) -> Option { for param in &self.params { - if let GenericParamAST::Type(ref t) = *param { - if t.ident.name == name { - return Some(t.ident.span); - } + if param.ident.name == name { + return Some(param.ident.span); } } None diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1c74a2bd5be..42745c14965 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -69,7 +69,7 @@ pub trait AstBuilder { id: ast::Ident, attrs: Vec, bounds: ast::TyParamBounds, - default: Option>) -> ast::TyParam; + default: Option>) -> ast::GenericParamAST; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef; @@ -80,7 +80,7 @@ pub trait AstBuilder { ident: ast::Ident, attrs: Vec, bounds: Vec) - -> ast::LifetimeDef; + -> ast::GenericParamAST; // statements fn stmt_expr(&self, expr: P) -> ast::Stmt; @@ -437,13 +437,15 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ident: ast::Ident, attrs: Vec, bounds: ast::TyParamBounds, - default: Option>) -> ast::TyParam { - ast::TyParam { + default: Option>) -> ast::GenericParamAST { + ast::GenericParamAST { ident: ident.with_span_pos(span), id: ast::DUMMY_NODE_ID, attrs: attrs.into(), - bounds, - default, + kind: ast::GenericParamKindAST::Type { + bounds, + default, + } } } @@ -475,11 +477,16 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ident: ast::Ident, attrs: Vec, bounds: Vec) - -> ast::LifetimeDef { - ast::LifetimeDef { + -> ast::GenericParamAST { + let lifetime = self.lifetime(span, ident); + ast::GenericParamAST { + ident: lifetime.ident, + id: lifetime.id, attrs: attrs.into(), - lifetime: self.lifetime(span, ident), - bounds, + kind: ast::GenericParamKindAST::Lifetime { + lifetime, + bounds, + } } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 1e09c7b2206..2f43487e036 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -687,38 +687,23 @@ pub fn noop_fold_ty_param_bound(tpb: TyParamBound, fld: &mut T) } } -pub fn noop_fold_ty_param(tp: TyParam, fld: &mut T) -> TyParam { - let TyParam {attrs, id, ident, bounds, default} = tp; - let attrs: Vec<_> = attrs.into(); - TyParam { - attrs: attrs.into_iter() - .flat_map(|x| fld.fold_attribute(x).into_iter()) - .collect::>() - .into(), - id: fld.new_id(id), - ident: fld.fold_ident(ident), - bounds: fld.fold_bounds(bounds), - default: default.map(|x| fld.fold_ty(x)), - } -} - pub fn noop_fold_generic_param(param: GenericParamAST, fld: &mut T) -> GenericParamAST { match param { - GenericParamAST::Lifetime(l) => { - let attrs: Vec<_> = l.attrs.into(); + GenericParamAST::Lifetime { bounds, lifetime } => { + let attrs: Vec<_> = param.attrs.into(); GenericParamAST::Lifetime(LifetimeDef { attrs: attrs.into_iter() .flat_map(|x| fld.fold_attribute(x).into_iter()) .collect::>() .into(), lifetime: Lifetime { - id: fld.new_id(l.lifetime.id), - ident: fld.fold_ident(l.lifetime.ident), + id: fld.new_id(param.id), + ident: fld.fold_ident(param.ident), }, - bounds: l.bounds.move_map(|l| noop_fold_lifetime(l, fld)), + bounds: bounds.move_map(|l| noop_fold_lifetime(l, fld)), }) } - GenericParamAST::Type(t) => GenericParamAST::Type(fld.fold_ty_param(t)), + GenericParamAST::Type { .. } => GenericParamAST::Type(fld.fold_ty_param(param)), } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index be4a4b8b11f..2a1fc6b291c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -21,10 +21,10 @@ use ast::EnumDef; use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; -use ast::GenericParamAST; +use ast::{GenericParamAST, GenericParamKindAST}; use ast::GenericArgAST; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; -use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind}; +use ast::{Label, Lifetime, Lit, LitKind}; use ast::Local; use ast::MacStmtStyle; use ast::{Mac, Mac_, MacDelimiter}; @@ -36,7 +36,7 @@ use ast::{VariantData, StructField}; use ast::StrStyle; use ast::SelfKind; use ast::{TraitItem, TraitRef, TraitObjectSyntax}; -use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; +use ast::{Ty, TyKind, TypeBinding, TyParamBounds}; use ast::{Visibility, VisibilityKind, WhereClause, CrateSugar}; use ast::{UseTree, UseTreeKind}; use ast::{BinOpKind, UnOp}; @@ -1311,9 +1311,7 @@ impl<'a> Parser<'a> { let lo = self.span; let (name, node, generics) = if self.eat_keyword(keywords::Type) { - let (generics, TyParam {ident, bounds, default, ..}) = - self.parse_trait_item_assoc_ty(vec![])?; - (ident, TraitItemKind::Type(bounds, default), generics) + self.parse_trait_item_assoc_ty()? } else if self.is_const_item() { self.expect_keyword(keywords::Const)?; let ident = self.parse_ident()?; @@ -4805,7 +4803,9 @@ impl<'a> Parser<'a> { } /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )? - fn parse_ty_param(&mut self, preceding_attrs: Vec) -> PResult<'a, TyParam> { + fn parse_ty_param(&mut self, + preceding_attrs: Vec) + -> PResult<'a, GenericParamAST> { let ident = self.parse_ident()?; // Parse optional colon and param bounds. @@ -4821,19 +4821,21 @@ impl<'a> Parser<'a> { None }; - Ok(TyParam { - attrs: preceding_attrs.into(), + Ok(GenericParamAST { ident, + attrs: preceding_attrs.into(), id: ast::DUMMY_NODE_ID, - bounds, - default, + kind: GenericParamKindAST::Type { + bounds, + default, + } }) } /// Parses the following grammar: /// TraitItemAssocTy = Ident ["<"...">"] [":" [TyParamBounds]] ["where" ...] ["=" Ty] - fn parse_trait_item_assoc_ty(&mut self, preceding_attrs: Vec) - -> PResult<'a, (ast::Generics, TyParam)> { + fn parse_trait_item_assoc_ty(&mut self) + -> PResult<'a, (Ident, TraitItemKind, ast::Generics)> { let ident = self.parse_ident()?; let mut generics = self.parse_generics()?; @@ -4852,13 +4854,7 @@ impl<'a> Parser<'a> { }; self.expect(&token::Semi)?; - Ok((generics, TyParam { - attrs: preceding_attrs.into(), - ident, - id: ast::DUMMY_NODE_ID, - bounds, - default, - })) + Ok((ident, TraitItemKind::Type(bounds, default), generics)) } /// Parses (possibly empty) list of lifetime and type parameters, possibly including @@ -4876,18 +4872,22 @@ impl<'a> Parser<'a> { } else { Vec::new() }; - params.push(ast::GenericParamAST::Lifetime(LifetimeDef { + params.push(ast::GenericParamAST { + ident: lifetime.ident, + id: lifetime.id, attrs: attrs.into(), - lifetime, - bounds, - })); + kind: ast::GenericParamKindAST::Lifetime { + lifetime, + bounds, + } + }); if seen_ty_param { self.span_err(self.prev_span, "lifetime parameters must be declared prior to type parameters"); } } else if self.check_ident() { // Parse type parameter. - params.push(ast::GenericParamAST::Type(self.parse_ty_param(attrs)?)); + params.push(self.parse_ty_param(attrs)?); seen_ty_param = true; } else { // Check for trailing attributes and stop parsing. diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a7a85a4c71f..1626135400d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2878,12 +2878,24 @@ impl<'a> State<'a> { self.s.word("<")?; self.commasep(Inconsistent, &generic_params, |s, param| { - match *param { - ast::GenericParamAST::Lifetime(ref lifetime_def) => { - s.print_outer_attributes_inline(&lifetime_def.attrs)?; - s.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds) + match param.kind { + ast::GenericParamKindAST::Lifetime { ref bounds, ref lifetime } => { + s.print_outer_attributes_inline(¶m.attrs)?; + s.print_lifetime_bounds(lifetime, bounds) }, - ast::GenericParamAST::Type(ref ty_param) => s.print_ty_param(ty_param), + ast::GenericParamKindAST::Type { ref bounds, ref default } => { + s.print_outer_attributes_inline(¶m.attrs)?; + s.print_ident(param.ident)?; + s.print_bounds(":", bounds)?; + match default { + Some(ref default) => { + s.s.space()?; + s.word_space("=")?; + s.print_type(default) + } + _ => Ok(()) + } + } } })?; @@ -2891,20 +2903,6 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_ty_param(&mut self, param: &ast::TyParam) -> io::Result<()> { - self.print_outer_attributes_inline(¶m.attrs)?; - self.print_ident(param.ident)?; - self.print_bounds(":", ¶m.bounds)?; - match param.default { - Some(ref default) => { - self.s.space()?; - self.word_space("=")?; - self.print_type(default) - } - _ => Ok(()) - } - } - pub fn print_where_clause(&mut self, where_clause: &ast::WhereClause) -> io::Result<()> { if where_clause.predicates.is_empty() { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 091673bfba9..c919f6c355c 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -491,17 +491,17 @@ pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a TyPar } pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParamAST) { - match *param { - GenericParamAST::Lifetime(ref l) => { - visitor.visit_ident(l.lifetime.ident); - walk_list!(visitor, visit_lifetime, &l.bounds); - walk_list!(visitor, visit_attribute, &*l.attrs); + match param.kind { + GenericParamKindAST::Lifetime { ref bounds, ref lifetime, .. } => { + visitor.visit_ident(param.ident); + walk_list!(visitor, visit_lifetime, bounds); + walk_list!(visitor, visit_attribute, param.attrs.iter()); } - GenericParamAST::Type(ref t) => { + GenericParamKindAST::Type { ref bounds, ref default, .. } => { visitor.visit_ident(t.ident); - walk_list!(visitor, visit_ty_param_bound, &t.bounds); - walk_list!(visitor, visit_ty, &t.default); - walk_list!(visitor, visit_attribute, &*t.attrs); + walk_list!(visitor, visit_ty_param_bound, bounds); + walk_list!(visitor, visit_ty, default); + walk_list!(visitor, visit_attribute, param.attrs.iter()); } } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 4bc8d208bab..cbf7b1e0876 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -192,8 +192,8 @@ use std::collections::HashSet; use std::vec; use rustc_target::spec::abi::Abi; -use syntax::ast::{self, BinOpKind, EnumDef, Expr, GenericParamAST, Generics, Ident, PatKind}; -use syntax::ast::{VariantData, GenericArgAST}; +use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; +use syntax::ast::{VariantData, GenericParamKindAST, GenericArgAST}; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -547,9 +547,9 @@ impl<'a> TraitDef<'a> { // Create the generic parameters params.extend(generics.params.iter().map(|param| { - match *param { - ref l @ GenericParamAST::Lifetime(_) => l.clone(), - GenericParamAST::Type(ref ty_param) => { + match param.kind { + GenericParamKindAST::Lifetime { .. } => param.clone(), + GenericParamKindAST::Type { bounds: ref ty_bounds, .. } => { // I don't think this can be moved out of the loop, since // a TyParamBound requires an ast id let mut bounds: Vec<_> = @@ -564,12 +564,11 @@ impl<'a> TraitDef<'a> { bounds.push(cx.typarambound(trait_path.clone())); // also add in any bounds from the declaration - for declared_bound in ty_param.bounds.iter() { + for declared_bound in ty_bounds { bounds.push((*declared_bound).clone()); } - let ty_param = cx.typaram(self.span, ty_param.ident, vec![], bounds, None); - GenericParamAST::Type(ty_param) + cx.typaram(self.span, param.ident, vec![], bounds, None) } } })); @@ -607,8 +606,8 @@ impl<'a> TraitDef<'a> { // Extra scope required here so ty_params goes out of scope before params is moved let mut ty_params = params.iter() - .filter_map(|param| match *param { - ast::GenericParamAST::Type(ref t) => Some(t), + .filter_map(|param| match param.kind { + ast::GenericParamKindAST::Type { .. } => Some(param), _ => None, }) .peekable(); @@ -668,17 +667,16 @@ impl<'a> TraitDef<'a> { // Create the type parameters on the `self` path. let self_ty_params: Vec> = generics.params .iter() - .filter_map(|param| match *param { - GenericParamAST::Type(ref ty_param) - => Some(cx.ty_ident(self.span, ty_param.ident)), + .filter_map(|param| match param.kind { + GenericParamKindAST::Type { .. } => Some(cx.ty_ident(self.span, param.ident)), _ => None, }) .collect(); let self_lifetimes: Vec = generics.params .iter() - .filter_map(|param| match *param { - GenericParamAST::Lifetime(ref ld) => Some(ld.lifetime), + .filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { ref lifetime, .. } => Some(*lifetime), _ => None, }) .collect(); diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 22487e7bfe3..c9f274ed210 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -15,7 +15,7 @@ pub use self::PtrTy::*; pub use self::Ty::*; use syntax::ast; -use syntax::ast::{Expr, GenericParamAST, Generics, Ident, SelfKind, GenericArgAST}; +use syntax::ast::{Expr, GenericParamKindAST, Generics, Ident, SelfKind, GenericArgAST}; use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::codemap::{respan, DUMMY_SP}; @@ -191,9 +191,9 @@ impl<'a> Ty<'a> { Self_ => { let ty_params: Vec> = self_generics.params .iter() - .filter_map(|param| match *param { - GenericParamAST::Type(ref ty_param) => { - Some(cx.ty_ident(span, ty_param.ident)) + .filter_map(|param| match param.kind { + GenericParamKindAST::Type { .. } => { + Some(cx.ty_ident(span, param.ident)) } _ => None, }) @@ -201,8 +201,8 @@ impl<'a> Ty<'a> { let lifetimes: Vec = self_generics.params .iter() - .filter_map(|param| match *param { - GenericParamAST::Lifetime(ref ld) => Some(ld.lifetime), + .filter_map(|param| match param.kind { + GenericParamKindAST::Lifetime { ref lifetime, .. } => Some(*lifetime), _ => None, }) .collect(); @@ -234,7 +234,7 @@ fn mk_ty_param(cx: &ExtCtxt, bounds: &[Path], self_ident: Ident, self_generics: &Generics) - -> ast::TyParam { + -> ast::GenericParamAST { let bounds = bounds.iter() .map(|b| { let path = b.to_path(cx, span, self_ident, self_generics); @@ -244,7 +244,7 @@ fn mk_ty_param(cx: &ExtCtxt, cx.typaram(span, cx.ident_of(name), attrs.to_owned(), bounds, None) } -fn mk_generics(params: Vec, span: Span) -> Generics { +fn mk_generics(params: Vec, span: Span) -> Generics { Generics { params, where_clause: ast::WhereClause { @@ -282,16 +282,13 @@ impl<'a> LifetimeBounds<'a> { let bounds = bounds.iter() .map(|b| cx.lifetime(span, Ident::from_str(b))) .collect(); - let lifetime_def = cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds); - GenericParamAST::Lifetime(lifetime_def) + cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds) }) .chain(self.bounds .iter() .map(|t| { let (name, ref bounds) = *t; - GenericParamAST::Type(mk_ty_param( - cx, span, name, &[], &bounds, self_ty, self_generics - )) + mk_ty_param(cx, span, name, &[], &bounds, self_ty, self_generics) }) ) .collect(); diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index 9bc19bb5ede..6813ce4c265 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -134,9 +134,12 @@ fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String { match item.node { ast::ItemKind::Struct(_, ast::Generics { ref params, .. }) | ast::ItemKind::Enum(_, ast::Generics { ref params, .. }) => { - for param in params.iter() { - if let ast::GenericParamAST::Type(ref ty) = *param { - typaram.push_str(&ty.ident.as_str()); + for param in params { + match param.kind { + ast::GenericParamKindAST::Type { .. } => { + typaram.push_str(¶m.ident.as_str()); + } + _ => {} } } } -- cgit 1.4.1-3-g733a5 From 3bcb006fd96763b24c34a8cf2abdf081d2e912b1 Mon Sep 17 00:00:00 2001 From: varkor Date: Sun, 27 May 2018 20:07:09 +0100 Subject: Rename structures in ast --- src/librustc/hir/lowering.rs | 24 ++++++++++++------------ src/librustc/hir/map/def_collector.rs | 6 +++--- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 2 +- src/librustc_driver/pretty.rs | 2 +- src/librustc_passes/ast_validation.rs | 16 ++++++++-------- src/librustc_resolve/lib.rs | 12 ++++++------ src/librustc_save_analysis/dump_visitor.rs | 12 ++++++------ src/librustc_save_analysis/lib.rs | 4 ++-- src/librustc_save_analysis/sig.rs | 6 +++--- src/libsyntax/ast.rs | 20 ++++++++++---------- src/libsyntax/ext/build.rs | 26 +++++++++++++------------- src/libsyntax/fold.rs | 24 ++++++++++++------------ src/libsyntax/parse/parser.rs | 28 ++++++++++++++-------------- src/libsyntax/print/pprust.rs | 20 ++++++++++---------- src/libsyntax/util/node_count.rs | 2 +- src/libsyntax/visit.rs | 14 +++++++------- src/libsyntax_ext/deriving/clone.rs | 6 +++--- src/libsyntax_ext/deriving/cmp/eq.rs | 4 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 18 +++++++++--------- src/libsyntax_ext/deriving/generic/ty.rs | 18 +++++++++--------- src/libsyntax_ext/deriving/mod.rs | 2 +- src/libsyntax_ext/env.rs | 4 ++-- 23 files changed, 136 insertions(+), 136 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index c0f94a138af..71b0b66b59a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -325,7 +325,7 @@ impl<'a> LoweringContext<'a> { .params .iter() .filter(|param| match param.kind { - ast::GenericParamKindAST::Lifetime { .. } => true, + ast::GenericParamKind::Lifetime { .. } => true, _ => false, }) .count(); @@ -758,13 +758,13 @@ impl<'a> LoweringContext<'a> { // This is used to track which lifetimes have already been defined, and // which are new in-band lifetimes that need to have a definition created // for them. - fn with_in_scope_lifetime_defs(&mut self, params: &Vec, f: F) -> T + fn with_in_scope_lifetime_defs(&mut self, params: &Vec, f: F) -> T where F: FnOnce(&mut LoweringContext) -> T, { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = params.iter().filter_map(|param| match param.kind { - GenericParamKindAST::Lifetime { .. } => Some(param.ident.name), + GenericParamKind::Lifetime { .. } => Some(param.ident.name), _ => None, }); self.in_scope_lifetimes.extend(lt_def_names); @@ -1044,12 +1044,12 @@ impl<'a> LoweringContext<'a> { } fn lower_generic_arg(&mut self, - arg: &ast::GenericArgAST, + arg: &ast::GenericArg, itctx: ImplTraitContext) -> hir::GenericArg { match arg { - ast::GenericArgAST::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)), - ast::GenericArgAST::Type(ty) => GenericArg::Type(self.lower_ty(&ty, itctx)), + ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)), + ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty(&ty, itctx)), } } @@ -1745,7 +1745,7 @@ impl<'a> LoweringContext<'a> { ) -> (hir::GenericArgs, bool) { let &AngleBracketedArgs { ref args, ref bindings, .. } = data; let has_types = args.iter().any(|arg| match arg { - GenericArgAST::Type(_) => true, + ast::GenericArg::Type(_) => true, _ => false, }); (hir::GenericArgs { @@ -1934,7 +1934,7 @@ impl<'a> LoweringContext<'a> { fn lower_generic_params( &mut self, - params: &Vec, + params: &Vec, add_bounds: &NodeMap>, itctx: ImplTraitContext, ) -> hir::HirVec { @@ -1942,12 +1942,12 @@ impl<'a> LoweringContext<'a> { } fn lower_generic_param(&mut self, - param: &GenericParamAST, + param: &GenericParam, add_bounds: &NodeMap>, itctx: ImplTraitContext) -> hir::GenericParam { match param.kind { - GenericParamKindAST::Lifetime { ref bounds, ref lifetime, .. } => { + GenericParamKind::Lifetime { ref bounds, ref lifetime, .. } => { let was_collecting_in_band = self.is_collecting_in_band_lifetimes; self.is_collecting_in_band_lifetimes = false; @@ -1968,7 +1968,7 @@ impl<'a> LoweringContext<'a> { param } - GenericParamKindAST::Type { ref bounds, ref default } => { + GenericParamKind::Type { ref bounds, ref default } => { let mut name = self.lower_ident(param.ident); // Don't expose `Self` (recovered "keyword used as ident" parse error). @@ -2044,7 +2044,7 @@ impl<'a> LoweringContext<'a> { { for param in &generics.params { match param.kind { - GenericParamKindAST::Type { .. } => { + GenericParamKind::Type { .. } => { if node_id == param.id { add_bounds.entry(param.id) .or_insert(Vec::new()) diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index ab4a0826584..8aa5dd4ad80 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -170,11 +170,11 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { } } - fn visit_generic_param(&mut self, param: &'a GenericParamAST) { + fn visit_generic_param(&mut self, param: &'a GenericParam) { let name = param.ident.name.as_interned_str(); let def_path_data = match param.kind { - GenericParamKindAST::Lifetime { .. } => DefPathData::LifetimeParam(name), - GenericParamKindAST::Type { .. } => DefPathData::TypeParam(name), + GenericParamKind::Lifetime { .. } => DefPathData::LifetimeParam(name), + GenericParamKind::Type { .. } => DefPathData::TypeParam(name), }; self.create_def(param.id, def_path_data, REGULAR_SPACE, param.ident.span); diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7236eebdb6f..824930a7eb0 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -990,7 +990,7 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { run_lints!(self, check_expr_post, early_passes, e); } - fn visit_generic_param(&mut self, param: &'a ast::GenericParamAST) { + fn visit_generic_param(&mut self, param: &'a ast::GenericParam) { run_lints!(self, check_generic_param, early_passes, param); ast_visit::walk_generic_param(self, param); } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 3d31a651b2f..9338e235c53 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -254,7 +254,7 @@ pub trait EarlyLintPass: LintPass { fn check_expr(&mut self, _: &EarlyContext, _: &ast::Expr) { } fn check_expr_post(&mut self, _: &EarlyContext, _: &ast::Expr) { } fn check_ty(&mut self, _: &EarlyContext, _: &ast::Ty) { } - fn check_generic_param(&mut self, _: &EarlyContext, _: &ast::GenericParamAST) { } + fn check_generic_param(&mut self, _: &EarlyContext, _: &ast::GenericParam) { } fn check_generics(&mut self, _: &EarlyContext, _: &ast::Generics) { } fn check_where_predicate(&mut self, _: &EarlyContext, _: &ast::WherePredicate) { } fn check_poly_trait_ref(&mut self, _: &EarlyContext, _: &ast::PolyTraitRef, diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 14003f0fd37..67720e61e91 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -681,7 +681,7 @@ impl<'a> ReplaceBodyWithLoop<'a> { None => false, Some(&ast::GenericArgs::AngleBracketed(ref data)) => { let types = data.args.iter().filter_map(|arg| match arg { - ast::GenericArgAST::Type(ty) => Some(ty), + ast::GenericArg::Type(ty) => Some(ty), _ => None, }); any_involves_impl_trait(types.into_iter()) || diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index d9a69f09d34..dfcdb688b00 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -138,11 +138,11 @@ impl<'a> AstValidator<'a> { } } - fn check_late_bound_lifetime_defs(&self, params: &Vec) { + fn check_late_bound_lifetime_defs(&self, params: &Vec) { // Check only lifetime parameters are present and that the lifetime // parameters that are present have no bounds. let non_lt_param_spans: Vec<_> = params.iter().filter_map(|param| match param.kind { - GenericParamKindAST::Lifetime { ref bounds, .. } => { + GenericParamKind::Lifetime { ref bounds, .. } => { if !bounds.is_empty() { let spans: Vec<_> = bounds.iter().map(|b| b.ident.span).collect(); self.err_handler() @@ -329,8 +329,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ItemKind::TraitAlias(Generics { ref params, .. }, ..) => { for param in params { match param.kind { - GenericParamKindAST::Lifetime { .. } => {} - GenericParamKindAST::Type { ref bounds, ref default, .. } => { + GenericParamKind::Lifetime { .. } => {} + GenericParamKind::Type { ref bounds, ref default, .. } => { if !bounds.is_empty() { self.err_handler() .span_err(param.ident.span, "type parameters on the left \ @@ -404,12 +404,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { let mut seen_default = None; for param in &generics.params { match (¶m.kind, seen_non_lifetime_param) { - (GenericParamKindAST::Lifetime { .. }, true) => { + (GenericParamKind::Lifetime { .. }, true) => { self.err_handler() .span_err(param.ident.span, "lifetime parameters must be leading"); }, - (GenericParamKindAST::Lifetime { .. }, false) => {} - (GenericParamKindAST::Type { ref default, .. }, _) => { + (GenericParamKind::Lifetime { .. }, false) => {} + (GenericParamKind::Type { ref default, .. }, _) => { seen_non_lifetime_param = true; if default.is_some() { seen_default = Some(param.ident.span); @@ -514,7 +514,7 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> { match *generic_args { GenericArgs::AngleBracketed(ref data) => { data.args.iter().for_each(|arg| match arg { - GenericArgAST::Type(ty) => self.visit_ty(ty), + GenericArg::Type(ty) => self.visit_ty(ty), _ => {} }); for type_binding in &data.bindings { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 314eae8f338..6561202be51 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -56,7 +56,7 @@ use syntax::util::lev_distance::find_best_match_for_name; use syntax::visit::{self, FnKind, Visitor}; use syntax::attr; use syntax::ast::{Arm, BindingMode, Block, Crate, Expr, ExprKind}; -use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, GenericParamKindAST, Generics}; +use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, GenericParamKind, Generics}; use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind}; use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path}; use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind}; @@ -800,8 +800,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { let mut found_default = false; default_ban_rib.bindings.extend(generics.params.iter() .filter_map(|param| match param.kind { - GenericParamKindAST::Lifetime { .. } => None, - GenericParamKindAST::Type { ref default, .. } => { + GenericParamKind::Lifetime { .. } => None, + GenericParamKind::Type { ref default, .. } => { if found_default || default.is_some() { found_default = true; return Some((Ident::with_empty_ctxt(param.ident.name), Def::Err)); @@ -812,8 +812,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { for param in &generics.params { match param.kind { - GenericParamKindAST::Lifetime { .. } => self.visit_generic_param(param), - GenericParamKindAST::Type { ref bounds, ref default, .. } => { + GenericParamKind::Lifetime { .. } => self.visit_generic_param(param), + GenericParamKind::Type { ref bounds, ref default, .. } => { for bound in bounds { self.visit_ty_param_bound(bound); } @@ -2208,7 +2208,7 @@ impl<'a> Resolver<'a> { let mut function_type_rib = Rib::new(rib_kind); let mut seen_bindings = FxHashMap(); generics.params.iter().for_each(|param| match param.kind { - GenericParamKindAST::Type { .. } => { + GenericParamKind::Type { .. } => { let ident = param.ident.modern(); debug!("with_type_parameter_rib: {}", param.id); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index ea5f452199a..6cfec57f80e 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -371,8 +371,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { ) { for param in &generics.params { match param.kind { - ast::GenericParamKindAST::Lifetime { .. } => {} - ast::GenericParamKindAST::Type { .. } => { + ast::GenericParamKind::Lifetime { .. } => {} + ast::GenericParamKind::Type { .. } => { let param_ss = param.ident.span; let name = escape(self.span.snippet(param_ss)); // Append $id to name to make sure each one is unique. @@ -827,7 +827,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { match **generic_args { ast::GenericArgs::AngleBracketed(ref data) => { data.args.iter().for_each(|arg| match arg { - ast::GenericArgAST::Type(ty) => self.visit_ty(ty), + ast::GenericArg::Type(ty) => self.visit_ty(ty), _ => {} }); } @@ -914,7 +914,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { if let Some(ref generic_args) = seg.args { if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args { data.args.iter().for_each(|arg| match arg { - ast::GenericArgAST::Type(ty) => self.visit_ty(ty), + ast::GenericArg::Type(ty) => self.visit_ty(ty), _ => {} }); } @@ -1486,8 +1486,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc fn visit_generics(&mut self, generics: &'l ast::Generics) { generics.params.iter().for_each(|param| match param.kind { - ast::GenericParamKindAST::Lifetime { .. } => {} - ast::GenericParamKindAST::Type { ref bounds, ref default, .. } => { + ast::GenericParamKind::Lifetime { .. } => {} + ast::GenericParamKind::Type { ref bounds, ref default, .. } => { for bound in bounds { if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index f656b013c0a..528f6ba96fa 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -935,8 +935,8 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String { .params .iter() .map(|param| match param.kind { - ast::GenericParamKindAST::Lifetime { .. } => param.ident.name.to_string(), - ast::GenericParamKindAST::Type { .. } => param.ident.to_string(), + ast::GenericParamKind::Lifetime { .. } => param.ident.name.to_string(), + ast::GenericParamKind::Type { .. } => param.ident.to_string(), }) .collect::>() .join(", ")); diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 8e8e0dfa182..6a63995c0fd 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -224,7 +224,7 @@ impl Sig for ast::Ty { text.push_str(&f.generic_params .iter() .filter_map(|param| match param.kind { - ast::GenericParamKindAST::Lifetime { .. } => { + ast::GenericParamKind::Lifetime { .. } => { Some(param.ident.to_string()) } _ => None, @@ -624,7 +624,7 @@ impl Sig for ast::Generics { end: offset + text.len() + param_text.len(), }); match param.kind { - ast::GenericParamKindAST::Lifetime { ref bounds, .. } => { + ast::GenericParamKind::Lifetime { ref bounds, .. } => { if !bounds.is_empty() { param_text.push_str(": "); let bounds = bounds.iter() @@ -635,7 +635,7 @@ impl Sig for ast::Generics { // FIXME add lifetime bounds refs. } } - ast::GenericParamKindAST::Type { ref bounds, .. } => { + ast::GenericParamKind::Type { ref bounds, .. } => { if !bounds.is_empty() { param_text.push_str(": "); param_text.push_str(&pprust::bounds_to_string(bounds)); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c2626c70a42..f589057218c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -160,7 +160,7 @@ impl GenericArgs { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum GenericArgAST { +pub enum GenericArg { Lifetime(Lifetime), Type(P), } @@ -171,7 +171,7 @@ pub struct AngleBracketedArgs { /// Overall span pub span: Span, /// The arguments for this path segment. - pub args: Vec, + pub args: Vec, /// Bindings (equality constraints) on associated types, if present. /// /// E.g., `Foo`. @@ -299,7 +299,7 @@ pub enum TraitBoundModifier { pub type TyParamBounds = Vec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum GenericParamKindAST { +pub enum GenericParamKind { /// A lifetime definition, e.g. `'a: 'b+'c+'d`. Lifetime { bounds: Vec, @@ -312,19 +312,19 @@ pub enum GenericParamKindAST { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub struct GenericParamAST { +pub struct GenericParam { pub ident: Ident, pub id: NodeId, pub attrs: ThinVec, - pub kind: GenericParamKindAST, + pub kind: GenericParamKind, } /// Represents lifetime, type and const parameters attached to a declaration of /// a function, enum, trait, etc. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Generics { - pub params: Vec, + pub params: Vec, pub where_clause: WhereClause, pub span: Span, } @@ -380,7 +380,7 @@ impl WherePredicate { pub struct WhereBoundPredicate { pub span: Span, /// Any generics from a `for` binding - pub bound_generic_params: Vec, + pub bound_generic_params: Vec, /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) @@ -1512,7 +1512,7 @@ impl fmt::Debug for Ty { pub struct BareFnTy { pub unsafety: Unsafety, pub abi: Abi, - pub generic_params: Vec, + pub generic_params: Vec, pub decl: P } @@ -1891,7 +1891,7 @@ pub struct TraitRef { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct PolyTraitRef { /// The `'a` in `<'a> Foo<&'a T>` - pub bound_generic_params: Vec, + pub bound_generic_params: Vec, /// The `Foo<&'a T>` in `<'a> Foo<&'a T>` pub trait_ref: TraitRef, @@ -1900,7 +1900,7 @@ pub struct PolyTraitRef { } impl PolyTraitRef { - pub fn new(generic_params: Vec, path: Path, span: Span) -> Self { + pub fn new(generic_params: Vec, path: Path, span: Span) -> Self { PolyTraitRef { bound_generic_params: generic_params, trait_ref: TraitRef { path: path, ref_id: DUMMY_NODE_ID }, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 42745c14965..695ad9c233f 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -31,7 +31,7 @@ pub trait AstBuilder { fn path_all(&self, sp: Span, global: bool, idents: Vec, - args: Vec, + args: Vec, bindings: Vec) -> ast::Path; @@ -42,7 +42,7 @@ pub trait AstBuilder { fn qpath_all(&self, self_type: P, trait_path: ast::Path, ident: ast::Ident, - args: Vec, + args: Vec, bindings: Vec) -> (ast::QSelf, ast::Path); @@ -69,7 +69,7 @@ pub trait AstBuilder { id: ast::Ident, attrs: Vec, bounds: ast::TyParamBounds, - default: Option>) -> ast::GenericParamAST; + default: Option>) -> ast::GenericParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef; @@ -80,7 +80,7 @@ pub trait AstBuilder { ident: ast::Ident, attrs: Vec, bounds: Vec) - -> ast::GenericParamAST; + -> ast::GenericParam; // statements fn stmt_expr(&self, expr: P) -> ast::Stmt; @@ -314,7 +314,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, global: bool, mut idents: Vec , - args: Vec, + args: Vec, bindings: Vec ) -> ast::Path { let last_ident = idents.pop().unwrap(); @@ -356,7 +356,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self_type: P, trait_path: ast::Path, ident: ast::Ident, - args: Vec, + args: Vec, bindings: Vec) -> (ast::QSelf, ast::Path) { let mut path = trait_path; @@ -424,7 +424,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.path_all(DUMMY_SP, true, self.std_path(&["option", "Option"]), - vec![ast::GenericArgAST::Type(ty)], + vec![ast::GenericArg::Type(ty)], Vec::new())) } @@ -437,12 +437,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ident: ast::Ident, attrs: Vec, bounds: ast::TyParamBounds, - default: Option>) -> ast::GenericParamAST { - ast::GenericParamAST { + default: Option>) -> ast::GenericParam { + ast::GenericParam { ident: ident.with_span_pos(span), id: ast::DUMMY_NODE_ID, attrs: attrs.into(), - kind: ast::GenericParamKindAST::Type { + kind: ast::GenericParamKind::Type { bounds, default, } @@ -477,13 +477,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ident: ast::Ident, attrs: Vec, bounds: Vec) - -> ast::GenericParamAST { + -> ast::GenericParam { let lifetime = self.lifetime(span, ident); - ast::GenericParamAST { + ast::GenericParam { ident: lifetime.ident, id: lifetime.id, attrs: attrs.into(), - kind: ast::GenericParamKindAST::Lifetime { + kind: ast::GenericParamKind::Lifetime { lifetime, bounds, } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 2f43487e036..ea147186b18 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -132,10 +132,10 @@ pub trait Folder : Sized { noop_fold_exprs(es, self) } - fn fold_generic_arg(&mut self, arg: GenericArgAST) -> GenericArgAST { + fn fold_generic_arg(&mut self, arg: GenericArg) -> GenericArg { match arg { - GenericArgAST::Lifetime(lt) => GenericArgAST::Lifetime(self.fold_lifetime(lt)), - GenericArgAST::Type(ty) => GenericArgAST::Type(self.fold_ty(ty)), + GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.fold_lifetime(lt)), + GenericArg::Type(ty) => GenericArg::Type(self.fold_ty(ty)), } } @@ -244,11 +244,11 @@ pub trait Folder : Sized { noop_fold_ty_param(tp, self) } - fn fold_generic_param(&mut self, param: GenericParamAST) -> GenericParamAST { + fn fold_generic_param(&mut self, param: GenericParam) -> GenericParam { noop_fold_generic_param(param, self) } - fn fold_generic_params(&mut self, params: Vec) -> Vec { + fn fold_generic_params(&mut self, params: Vec) -> Vec { noop_fold_generic_params(params, self) } @@ -687,11 +687,11 @@ pub fn noop_fold_ty_param_bound(tpb: TyParamBound, fld: &mut T) } } -pub fn noop_fold_generic_param(param: GenericParamAST, fld: &mut T) -> GenericParamAST { - match param { - GenericParamAST::Lifetime { bounds, lifetime } => { +pub fn noop_fold_generic_param(param: GenericParam, fld: &mut T) -> GenericParam { + match param.kind { + GenericParamKind::Lifetime { bounds, lifetime } => { let attrs: Vec<_> = param.attrs.into(); - GenericParamAST::Lifetime(LifetimeDef { + GenericParamKind::Lifetime(LifetimeDef { attrs: attrs.into_iter() .flat_map(|x| fld.fold_attribute(x).into_iter()) .collect::>() @@ -703,14 +703,14 @@ pub fn noop_fold_generic_param(param: GenericParamAST, fld: &mut T) - bounds: bounds.move_map(|l| noop_fold_lifetime(l, fld)), }) } - GenericParamAST::Type { .. } => GenericParamAST::Type(fld.fold_ty_param(param)), + GenericParamKind::Type { .. } => GenericParamKind::Type(fld.fold_ty_param(param)), } } pub fn noop_fold_generic_params( - params: Vec, + params: Vec, fld: &mut T -) -> Vec { +) -> Vec { params.move_map(|p| fld.fold_generic_param(p)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2a1fc6b291c..203b529222d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -21,8 +21,8 @@ use ast::EnumDef; use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; -use ast::{GenericParamAST, GenericParamKindAST}; -use ast::GenericArgAST; +use ast::{GenericParam, GenericParamKind}; +use ast::GenericArg; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; use ast::{Label, Lifetime, Lit, LitKind}; use ast::Local; @@ -1246,7 +1246,7 @@ impl<'a> Parser<'a> { } /// parse a TyKind::BareFn type: - fn parse_ty_bare_fn(&mut self, generic_params: Vec) -> PResult<'a, TyKind> { + fn parse_ty_bare_fn(&mut self, generic_params: Vec) -> PResult<'a, TyKind> { /* [unsafe] [extern "ABI"] fn (S) -> T @@ -1563,7 +1563,7 @@ impl<'a> Parser<'a> { Ok(P(ty)) } - fn parse_remaining_bounds(&mut self, generic_params: Vec, path: ast::Path, + fn parse_remaining_bounds(&mut self, generic_params: Vec, path: ast::Path, lo: Span, parse_plus: bool) -> PResult<'a, TyKind> { let poly_trait_ref = PolyTraitRef::new(generic_params, path, lo.to(self.prev_span)); let mut bounds = vec![TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)]; @@ -4805,7 +4805,7 @@ impl<'a> Parser<'a> { /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )? fn parse_ty_param(&mut self, preceding_attrs: Vec) - -> PResult<'a, GenericParamAST> { + -> PResult<'a, GenericParam> { let ident = self.parse_ident()?; // Parse optional colon and param bounds. @@ -4821,11 +4821,11 @@ impl<'a> Parser<'a> { None }; - Ok(GenericParamAST { + Ok(GenericParam { ident, attrs: preceding_attrs.into(), id: ast::DUMMY_NODE_ID, - kind: GenericParamKindAST::Type { + kind: GenericParamKind::Type { bounds, default, } @@ -4859,7 +4859,7 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type parameters, possibly including /// trailing comma and erroneous trailing attributes. - crate fn parse_generic_params(&mut self) -> PResult<'a, Vec> { + crate fn parse_generic_params(&mut self) -> PResult<'a, Vec> { let mut params = Vec::new(); let mut seen_ty_param = false; loop { @@ -4872,11 +4872,11 @@ impl<'a> Parser<'a> { } else { Vec::new() }; - params.push(ast::GenericParamAST { + params.push(ast::GenericParam { ident: lifetime.ident, id: lifetime.id, attrs: attrs.into(), - kind: ast::GenericParamKindAST::Lifetime { + kind: ast::GenericParamKind::Lifetime { lifetime, bounds, } @@ -4937,7 +4937,7 @@ impl<'a> Parser<'a> { /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings, /// possibly including trailing comma. fn parse_generic_args(&mut self) - -> PResult<'a, (Vec, Vec)> { + -> PResult<'a, (Vec, Vec)> { let mut args = Vec::new(); let mut bindings = Vec::new(); let mut seen_type = false; @@ -4945,7 +4945,7 @@ impl<'a> Parser<'a> { loop { if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { // Parse lifetime argument. - args.push(GenericArgAST::Lifetime(self.expect_lifetime())); + args.push(GenericArg::Lifetime(self.expect_lifetime())); if seen_type || seen_binding { self.span_err(self.prev_span, "lifetime parameters must be declared prior to type parameters"); @@ -4970,7 +4970,7 @@ impl<'a> Parser<'a> { self.span_err(ty_param.span, "type parameters must be declared prior to associated type bindings"); } - args.push(GenericArgAST::Type(ty_param)); + args.push(GenericArg::Type(ty_param)); seen_type = true; } else { break @@ -5692,7 +5692,7 @@ impl<'a> Parser<'a> { Ok((keywords::Invalid.ident(), item_kind, Some(attrs))) } - fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { + fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { if self.eat_keyword(keywords::For) { self.expect_lt()?; let params = self.parse_generic_params()?; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 458947299c8..84a4a51b716 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -13,7 +13,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::{self, Abi}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Attribute, MacDelimiter, GenericArgAST}; +use ast::{Attribute, MacDelimiter, GenericArg}; use util::parser::{self, AssocOp, Fixity}; use attr; use codemap::{self, CodeMap}; @@ -344,7 +344,7 @@ pub fn trait_item_to_string(i: &ast::TraitItem) -> String { to_string(|s| s.print_trait_item(i)) } -pub fn generic_params_to_string(generic_params: &[ast::GenericParamAST]) -> String { +pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String { to_string(|s| s.print_generic_params(generic_params)) } @@ -1017,10 +1017,10 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_generic_arg(&mut self, generic_arg: &GenericArgAST) -> io::Result<()> { + pub fn print_generic_arg(&mut self, generic_arg: &GenericArg) -> io::Result<()> { match generic_arg { - GenericArgAST::Lifetime(lt) => self.print_lifetime(lt), - GenericArgAST::Type(ty) => self.print_type(ty), + GenericArg::Lifetime(lt) => self.print_lifetime(lt), + GenericArg::Type(ty) => self.print_type(ty), } } @@ -1443,7 +1443,7 @@ impl<'a> State<'a> { fn print_formal_generic_params( &mut self, - generic_params: &[ast::GenericParamAST] + generic_params: &[ast::GenericParam] ) -> io::Result<()> { if !generic_params.is_empty() { self.s.word("for")?; @@ -2869,7 +2869,7 @@ impl<'a> State<'a> { pub fn print_generic_params( &mut self, - generic_params: &[ast::GenericParamAST] + generic_params: &[ast::GenericParam] ) -> io::Result<()> { if generic_params.is_empty() { return Ok(()); @@ -2879,11 +2879,11 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &generic_params, |s, param| { match param.kind { - ast::GenericParamKindAST::Lifetime { ref bounds, ref lifetime } => { + ast::GenericParamKind::Lifetime { ref bounds, ref lifetime } => { s.print_outer_attributes_inline(¶m.attrs)?; s.print_lifetime_bounds(lifetime, bounds) }, - ast::GenericParamKindAST::Type { ref bounds, ref default } => { + ast::GenericParamKind::Type { ref bounds, ref default } => { s.print_outer_attributes_inline(¶m.attrs)?; s.print_ident(param.ident)?; s.print_bounds(":", bounds)?; @@ -3045,7 +3045,7 @@ impl<'a> State<'a> { unsafety: ast::Unsafety, decl: &ast::FnDecl, name: Option, - generic_params: &Vec) + generic_params: &Vec) -> io::Result<()> { self.ibox(INDENT_UNIT)?; if !generic_params.is_empty() { diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index caddd0513d1..95ae9f9bcf8 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -71,7 +71,7 @@ impl<'ast> Visitor<'ast> for NodeCounter { self.count += 1; walk_ty(self, t) } - fn visit_generic_param(&mut self, param: &GenericParamAST) { + fn visit_generic_param(&mut self, param: &GenericParam) { self.count += 1; walk_generic_param(self, param) } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index c919f6c355c..3a81796bae4 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -73,7 +73,7 @@ pub trait Visitor<'ast>: Sized { fn visit_expr(&mut self, ex: &'ast Expr) { walk_expr(self, ex) } fn visit_expr_post(&mut self, _ex: &'ast Expr) { } fn visit_ty(&mut self, t: &'ast Ty) { walk_ty(self, t) } - fn visit_generic_param(&mut self, param: &'ast GenericParamAST) { + fn visit_generic_param(&mut self, param: &'ast GenericParam) { walk_generic_param(self, param) } fn visit_generics(&mut self, g: &'ast Generics) { walk_generics(self, g) } @@ -133,10 +133,10 @@ pub trait Visitor<'ast>: Sized { fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) { walk_generic_args(self, path_span, generic_args) } - fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArgAST) { + fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) { match generic_arg { - GenericArgAST::Lifetime(lt) => self.visit_lifetime(lt), - GenericArgAST::Type(ty) => self.visit_ty(ty), + GenericArg::Lifetime(lt) => self.visit_lifetime(lt), + GenericArg::Type(ty) => self.visit_ty(ty), } } fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) { @@ -490,14 +490,14 @@ pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a TyPar } } -pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParamAST) { +pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) { match param.kind { - GenericParamKindAST::Lifetime { ref bounds, ref lifetime, .. } => { + GenericParamKind::Lifetime { ref bounds, ref lifetime, .. } => { visitor.visit_ident(param.ident); walk_list!(visitor, visit_lifetime, bounds); walk_list!(visitor, visit_attribute, param.attrs.iter()); } - GenericParamKindAST::Type { ref bounds, ref default, .. } => { + GenericParamKind::Type { ref bounds, ref default, .. } => { visitor.visit_ident(t.ident); walk_list!(visitor, visit_ty_param_bound, bounds); walk_list!(visitor, visit_ty, default); diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 5f943a4cd00..9aeac5b1ddb 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -13,7 +13,7 @@ use deriving::generic::*; use deriving::generic::ty::*; use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; -use syntax::ast::GenericArgAST; +use syntax::ast::GenericArg; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -50,7 +50,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt, ItemKind::Enum(_, Generics { ref params, .. }) => { if attr::contains_name(&annitem.attrs, "rustc_copy_clone_marker") && !params.iter().any(|param| match param.kind { - ast::GenericParamKindAST::Type { .. } => true, + ast::GenericParamKind::Type { .. } => true, _ => false, }) { @@ -127,7 +127,7 @@ fn cs_clone_shallow(name: &str, let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["clone", helper_name]), - vec![GenericArgAST::Type(ty)], vec![]); + vec![GenericArg::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &VariantData) { diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index e9bcf70e90c..00ab39032ac 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, Expr, MetaItem, GenericArgAST}; +use syntax::ast::{self, Expr, MetaItem, GenericArg}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -62,7 +62,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) let span = span.with_ctxt(cx.backtrace()); let assert_path = cx.path_all(span, true, cx.std_path(&["cmp", helper_name]), - vec![GenericArgAST::Type(ty)], vec![]); + vec![GenericArg::Type(ty)], vec![]); stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); } fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec, variant: &ast::VariantData) { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index fc244f67bb6..6c9aea51c7c 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -193,7 +193,7 @@ use std::vec; use rustc_target::spec::abi::Abi; use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; -use syntax::ast::{VariantData, GenericParamKindAST, GenericArgAST}; +use syntax::ast::{VariantData, GenericParamKind, GenericArg}; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; @@ -423,7 +423,7 @@ impl<'a> TraitDef<'a> { ast::ItemKind::Enum(_, ref generics) | ast::ItemKind::Union(_, ref generics) => { !generics.params.iter().any(|param| match param.kind { - ast::GenericParamKindAST::Type { .. } => true, + ast::GenericParamKind::Type { .. } => true, _ => false, }) } @@ -550,8 +550,8 @@ impl<'a> TraitDef<'a> { // Create the generic parameters params.extend(generics.params.iter().map(|param| match param.kind { - GenericParamKindAST::Lifetime { .. } => param.clone(), - GenericParamKindAST::Type { bounds: ref ty_bounds, .. } => { + GenericParamKind::Lifetime { .. } => param.clone(), + GenericParamKind::Type { bounds: ref ty_bounds, .. } => { // I don't think this can be moved out of the loop, since // a TyParamBound requires an ast id let mut bounds: Vec<_> = @@ -608,7 +608,7 @@ impl<'a> TraitDef<'a> { let mut ty_params = params.iter() .filter_map(|param| match param.kind { - ast::GenericParamKindAST::Type { .. } => Some(param), + ast::GenericParamKind::Type { .. } => Some(param), _ => None, }) .peekable(); @@ -669,7 +669,7 @@ impl<'a> TraitDef<'a> { let self_ty_params: Vec> = generics.params .iter() .filter_map(|param| match param.kind { - GenericParamKindAST::Type { .. } => Some(cx.ty_ident(self.span, param.ident)), + GenericParamKind::Type { .. } => Some(cx.ty_ident(self.span, param.ident)), _ => None, }) .collect(); @@ -677,15 +677,15 @@ impl<'a> TraitDef<'a> { let self_lifetimes: Vec = generics.params .iter() .filter_map(|param| match param.kind { - GenericParamKindAST::Lifetime { ref lifetime, .. } => Some(*lifetime), + GenericParamKind::Lifetime { ref lifetime, .. } => Some(*lifetime), _ => None, }) .collect(); let self_params = self_lifetimes.into_iter() - .map(|lt| GenericArgAST::Lifetime(lt)) + .map(|lt| GenericArg::Lifetime(lt)) .chain(self_ty_params.into_iter().map(|ty| - GenericArgAST::Type(ty))) + GenericArg::Type(ty))) .collect(); // Create the type of `self`. diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index c9f274ed210..78f6a9b9137 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -15,7 +15,7 @@ pub use self::PtrTy::*; pub use self::Ty::*; use syntax::ast; -use syntax::ast::{Expr, GenericParamKindAST, Generics, Ident, SelfKind, GenericArgAST}; +use syntax::ast::{Expr, GenericParamKind, Generics, Ident, SelfKind, GenericArg}; use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::codemap::{respan, DUMMY_SP}; @@ -89,8 +89,8 @@ impl<'a> Path<'a> { let tys: Vec> = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect(); let params = lt.into_iter() - .map(|lt| GenericArgAST::Lifetime(lt)) - .chain(tys.into_iter().map(|ty| GenericArgAST::Type(ty))) + .map(|lt| GenericArg::Lifetime(lt)) + .chain(tys.into_iter().map(|ty| GenericArg::Type(ty))) .collect(); match self.kind { @@ -192,7 +192,7 @@ impl<'a> Ty<'a> { let ty_params: Vec> = self_generics.params .iter() .filter_map(|param| match param.kind { - GenericParamKindAST::Type { .. } => { + GenericParamKind::Type { .. } => { Some(cx.ty_ident(span, param.ident)) } _ => None, @@ -202,15 +202,15 @@ impl<'a> Ty<'a> { let lifetimes: Vec = self_generics.params .iter() .filter_map(|param| match param.kind { - GenericParamKindAST::Lifetime { ref lifetime, .. } => Some(*lifetime), + GenericParamKind::Lifetime { ref lifetime, .. } => Some(*lifetime), _ => None, }) .collect(); let params = lifetimes.into_iter() - .map(|lt| GenericArgAST::Lifetime(lt)) + .map(|lt| GenericArg::Lifetime(lt)) .chain(ty_params.into_iter().map(|ty| - GenericArgAST::Type(ty))) + GenericArg::Type(ty))) .collect(); cx.path_all(span, @@ -234,7 +234,7 @@ fn mk_ty_param(cx: &ExtCtxt, bounds: &[Path], self_ident: Ident, self_generics: &Generics) - -> ast::GenericParamAST { + -> ast::GenericParam { let bounds = bounds.iter() .map(|b| { let path = b.to_path(cx, span, self_ident, self_generics); @@ -244,7 +244,7 @@ fn mk_ty_param(cx: &ExtCtxt, cx.typaram(span, cx.ident_of(name), attrs.to_owned(), bounds, None) } -fn mk_generics(params: Vec, span: Span) -> Generics { +fn mk_generics(params: Vec, span: Span) -> Generics { Generics { params, where_clause: ast::WhereClause { diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index 6813ce4c265..6ff385b18e8 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -136,7 +136,7 @@ fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String { ast::ItemKind::Enum(_, ast::Generics { ref params, .. }) => { for param in params { match param.kind { - ast::GenericParamKindAST::Type { .. } => { + ast::GenericParamKind::Type { .. } => { typaram.push_str(¶m.ident.as_str()); } _ => {} diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index a3254788d45..5c3080260cc 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -13,7 +13,7 @@ // interface. // -use syntax::ast::{self, Ident, GenericArgAST}; +use syntax::ast::{self, Ident, GenericArg}; use syntax::ext::base::*; use syntax::ext::base; use syntax::ext::build::AstBuilder; @@ -39,7 +39,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, cx.expr_path(cx.path_all(sp, true, cx.std_path(&["option", "Option", "None"]), - vec![GenericArgAST::Type(cx.ty_rptr(sp, + vec![GenericArg::Type(cx.ty_rptr(sp, cx.ty_ident(sp, Ident::from_str("str")), Some(lt), ast::Mutability::Immutable))], -- cgit 1.4.1-3-g733a5 From aed530a457dd937fa633dfe52cf07811196d3173 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 28 May 2018 13:33:28 +0100 Subject: Lift bounds into GenericParam --- src/librustc/hir/intravisit.rs | 8 +-- src/librustc/hir/lowering.rs | 58 ++++++++---------- src/librustc/hir/mod.rs | 43 ++++++------- src/librustc/hir/print.rs | 27 ++++---- src/librustc/ich/impls_hir.rs | 12 ++-- src/librustc/infer/error_reporting/mod.rs | 9 +-- src/librustc/middle/resolve_lifetime.rs | 89 +++++++++++++-------------- src/librustc_lint/builtin.rs | 9 +-- src/librustc_passes/ast_validation.rs | 14 ++--- src/librustc_passes/hir_stats.rs | 8 +-- src/librustc_privacy/lib.rs | 6 +- src/librustc_resolve/lib.rs | 4 +- src/librustc_save_analysis/dump_visitor.rs | 8 +-- src/librustc_save_analysis/sig.rs | 26 ++++---- src/librustc_typeck/check/compare_method.rs | 4 +- src/librustc_typeck/collect.rs | 45 +++++++------- src/librustdoc/clean/auto_trait.rs | 18 +++--- src/librustdoc/clean/inline.rs | 4 +- src/librustdoc/clean/mod.rs | 95 ++++++++++++++++------------- src/librustdoc/clean/simplify.rs | 2 +- src/librustdoc/core.rs | 2 +- src/librustdoc/doctree.rs | 2 +- src/librustdoc/html/format.rs | 20 +++--- src/librustdoc/html/render.rs | 6 +- src/libsyntax/ast.rs | 45 +++++++------- src/libsyntax/ext/build.rs | 16 ++--- src/libsyntax/fold.rs | 23 ++++--- src/libsyntax/parse/parser.rs | 22 ++++--- src/libsyntax/print/pprust.rs | 23 ++++--- src/libsyntax/util/node_count.rs | 2 +- src/libsyntax/visit.rs | 11 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 15 +++-- src/libsyntax_ext/deriving/generic/ty.rs | 7 +-- 33 files changed, 339 insertions(+), 344 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 0bbd2580807..d5c9d964eb2 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -314,7 +314,7 @@ 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 TyParamBound) { + fn visit_ty_param_bound(&mut self, bounds: &'v ParamBound) { walk_ty_param_bound(self, bounds) } fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: TraitBoundModifier) { @@ -731,12 +731,12 @@ 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 TyParamBound) { +pub fn walk_ty_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); } - RegionTyParamBound(ref lifetime) => { + Outlives(ref lifetime) => { visitor.visit_lifetime(lifetime); } } @@ -759,11 +759,11 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi } GenericParamKind::Type { name, ref bounds, ref default, ref attrs, .. } => { visitor.visit_name(param.span, name); - walk_list!(visitor, visit_ty_param_bound, bounds); walk_list!(visitor, visit_ty, default); walk_list!(visitor, visit_attribute, attrs.iter()); } } + walk_list!(visitor, visit_ty_param_bound, ¶m.bounds); } pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d8e03bea89d..494e6e1ba33 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -701,9 +701,9 @@ impl<'a> LoweringContext<'a> { id: def_node_id, span, pure_wrt_drop: false, + bounds: vec![].into(), kind: hir::GenericParamKind::Lifetime { name: hir_name, - bounds: vec![].into(), in_band: true, lifetime: hir::Lifetime { id: def_node_id, @@ -1127,7 +1127,7 @@ impl<'a> LoweringContext<'a> { Some(self.lower_poly_trait_ref(ty, itctx)) } TraitTyParamBound(_, TraitBoundModifier::Maybe) => None, - RegionTyParamBound(ref lifetime) => { + Outlives(ref lifetime) => { if lifetime_bound.is_none() { lifetime_bound = Some(self.lower_lifetime(lifetime)); } @@ -1246,16 +1246,16 @@ impl<'a> LoweringContext<'a> { span, ); - let hir_bounds = self.lower_bounds(bounds, itctx); + let hir_bounds = self.lower_param_bounds(bounds, itctx); // Set the name to `impl Bound1 + Bound2` let name = Symbol::intern(&pprust::ty_to_string(t)); self.in_band_ty_params.push(hir::GenericParam { id: def_node_id, span, pure_wrt_drop: false, + bounds: hir_bounds, kind: hir::GenericParamKind::Type { name, - bounds: hir_bounds, default: None, synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), attrs: P::new(), @@ -1299,7 +1299,7 @@ impl<'a> LoweringContext<'a> { &mut self, exist_ty_id: NodeId, parent_index: DefIndex, - bounds: &hir::TyParamBounds, + bounds: &hir::ParamBounds, ) -> (HirVec, HirVec) { // This visitor walks over impl trait bounds and creates defs for all lifetimes which // appear in the bounds, excluding lifetimes that are created within the bounds. @@ -1420,9 +1420,9 @@ impl<'a> LoweringContext<'a> { id: def_node_id, span: lifetime.span, pure_wrt_drop: false, + bounds: vec![].into(), kind: hir::GenericParamKind::Lifetime { name, - bounds: vec![].into(), in_band: false, lifetime: hir::Lifetime { id: def_node_id, @@ -1882,18 +1882,18 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_ty_param_bound( + fn lower_param_bound( &mut self, - tpb: &TyParamBound, + tpb: &ParamBound, itctx: ImplTraitContext, - ) -> hir::TyParamBound { + ) -> hir::ParamBound { match *tpb { TraitTyParamBound(ref ty, modifier) => hir::TraitTyParamBound( self.lower_poly_trait_ref(ty, itctx), self.lower_trait_bound_modifier(modifier), ), - RegionTyParamBound(ref lifetime) => { - hir::RegionTyParamBound(self.lower_lifetime(lifetime)) + Outlives(ref lifetime) => { + hir::Outlives(self.lower_lifetime(lifetime)) } } } @@ -1935,7 +1935,7 @@ impl<'a> LoweringContext<'a> { fn lower_generic_params( &mut self, params: &Vec, - add_bounds: &NodeMap>, + add_bounds: &NodeMap>, itctx: ImplTraitContext, ) -> hir::HirVec { params.iter().map(|param| self.lower_generic_param(param, add_bounds, itctx)).collect() @@ -1943,11 +1943,12 @@ impl<'a> LoweringContext<'a> { fn lower_generic_param(&mut self, param: &GenericParam, - add_bounds: &NodeMap>, + add_bounds: &NodeMap>, itctx: ImplTraitContext) -> hir::GenericParam { + let mut bounds = self.lower_param_bounds(¶m.bounds, itctx); match param.kind { - GenericParamKind::Lifetime { ref bounds, ref lifetime } => { + GenericParamKind::Lifetime { ref lifetime } => { let was_collecting_in_band = self.is_collecting_in_band_lifetimes; self.is_collecting_in_band_lifetimes = false; @@ -1956,9 +1957,9 @@ impl<'a> LoweringContext<'a> { id: lifetime.id, span: lifetime.span, pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), + bounds, kind: hir::GenericParamKind::Lifetime { name: lifetime.name, - bounds: bounds.iter().map(|lt| self.lower_lifetime(lt)).collect(), in_band: false, lifetime, } @@ -1968,7 +1969,7 @@ impl<'a> LoweringContext<'a> { param } - GenericParamKind::Type { ref bounds, ref default } => { + GenericParamKind::Type { ref default, .. } => { let mut name = self.lower_ident(param.ident); // Don't expose `Self` (recovered "keyword used as ident" parse error). @@ -1978,11 +1979,10 @@ impl<'a> LoweringContext<'a> { name = Symbol::gensym("Self"); } - let mut bounds = self.lower_bounds(bounds, itctx); let add_bounds = add_bounds.get(¶m.id).map_or(&[][..], |x| &x); if !add_bounds.is_empty() { bounds = bounds.into_iter() - .chain(self.lower_bounds(add_bounds, itctx).into_iter()) + .chain(self.lower_param_bounds(add_bounds, itctx).into_iter()) .collect(); } @@ -1990,9 +1990,9 @@ impl<'a> LoweringContext<'a> { id: self.lower_node_id(param.id).node_id, span: param.ident.span, pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), + bounds, kind: hir::GenericParamKind::Type { name, - bounds, default: default.as_ref().map(|x| { self.lower_ty(x, ImplTraitContext::Disallowed) }), @@ -2107,7 +2107,7 @@ impl<'a> LoweringContext<'a> { // Ignore `?Trait` bounds. // Tthey were copied into type parameters already. TraitTyParamBound(_, TraitBoundModifier::Maybe) => None, - _ => Some(this.lower_ty_param_bound( + _ => Some(this.lower_param_bound( bound, ImplTraitContext::Disallowed, )), @@ -2228,15 +2228,9 @@ impl<'a> LoweringContext<'a> { } } - fn lower_bounds( - &mut self, - bounds: &[TyParamBound], - itctx: ImplTraitContext, - ) -> hir::TyParamBounds { - bounds - .iter() - .map(|bound| self.lower_ty_param_bound(bound, itctx)) - .collect() + fn lower_param_bounds(&mut self, bounds: &[ParamBound], itctx: ImplTraitContext) + -> hir::ParamBounds { + bounds.iter().map(|bound| self.lower_param_bound(bound, itctx)).collect() } fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P { @@ -2422,7 +2416,7 @@ impl<'a> LoweringContext<'a> { ) } ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => { - let bounds = self.lower_bounds(bounds, ImplTraitContext::Disallowed); + let bounds = self.lower_param_bounds(bounds, ImplTraitContext::Disallowed); let items = items .iter() .map(|item| self.lower_trait_item_ref(item)) @@ -2437,7 +2431,7 @@ impl<'a> LoweringContext<'a> { } ItemKind::TraitAlias(ref generics, ref bounds) => hir::ItemTraitAlias( self.lower_generics(generics, ImplTraitContext::Disallowed), - self.lower_bounds(bounds, ImplTraitContext::Disallowed), + self.lower_param_bounds(bounds, ImplTraitContext::Disallowed), ), ItemKind::MacroDef(..) | ItemKind::Mac(..) => panic!("Shouldn't still be around"), } @@ -2664,7 +2658,7 @@ impl<'a> LoweringContext<'a> { TraitItemKind::Type(ref bounds, ref default) => ( self.lower_generics(&i.generics, ImplTraitContext::Disallowed), hir::TraitItemKind::Type( - self.lower_bounds(bounds, ImplTraitContext::Disallowed), + self.lower_param_bounds(bounds, ImplTraitContext::Disallowed), default .as_ref() .map(|x| self.lower_ty(x, ImplTraitContext::Disallowed)), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 135403c9c27..8253a34f310 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +22,7 @@ pub use self::Mutability::*; pub use self::PrimTy::*; pub use self::Stmt_::*; pub use self::Ty_::*; -pub use self::TyParamBound::*; +pub use self::ParamBound::*; pub use self::UnOp::*; pub use self::UnsafeSource::*; pub use self::Visibility::{Public, Inherited}; @@ -416,41 +416,42 @@ impl GenericArgs { } } +/// A modifier on a bound, currently this is only used for `?Sized`, where the +/// modifier is `Maybe`. Negative bounds should also be handled here. +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub enum TraitBoundModifier { + None, + Maybe, +} + +pub type Outlives = Lifetime; + /// The AST represents all type param bounds as types. /// typeck::collect::compute_bounds matches these against /// the "special" built-in traits (see middle::lang_items) and /// detects Copy, Send and Sync. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum TyParamBound { +pub enum ParamBound { TraitTyParamBound(PolyTraitRef, TraitBoundModifier), - RegionTyParamBound(Lifetime), + Outlives(Lifetime), } -impl TyParamBound { +impl ParamBound { pub fn span(&self) -> Span { match self { &TraitTyParamBound(ref t, ..) => t.span, - &RegionTyParamBound(ref l) => l.span, + &Outlives(ref l) => l.span, } } } -/// A modifier on a bound, currently this is only used for `?Sized`, where the -/// modifier is `Maybe`. Negative bounds should also be handled here. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum TraitBoundModifier { - None, - Maybe, -} - -pub type TyParamBounds = HirVec; +pub type ParamBounds = HirVec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum GenericParamKind { /// A lifetime definition, eg `'a: 'b + 'c + 'd`. Lifetime { name: LifetimeName, - bounds: HirVec, // Indicates that the lifetime definition was synthetically added // as a result of an in-band lifetime usage like: // `fn foo(x: &'a u8) -> &'a u8 { x }` @@ -460,7 +461,6 @@ pub enum GenericParamKind { }, Type { name: Name, - bounds: TyParamBounds, default: Option>, synthetic: Option, attrs: HirVec, @@ -470,6 +470,7 @@ pub enum GenericParamKind { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct GenericParam { pub id: NodeId, + pub bounds: ParamBounds, pub span: Span, pub pure_wrt_drop: bool, @@ -587,7 +588,7 @@ pub struct WhereBoundPredicate { /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: TyParamBounds, + pub bounds: ParamBounds, } /// A lifetime predicate, e.g. `'a: 'b+'c` @@ -1554,7 +1555,7 @@ pub enum TraitItemKind { Method(MethodSig, TraitMethod), /// An associated type with (possibly empty) bounds and optional concrete /// type - Type(TyParamBounds, Option>), + Type(ParamBounds, Option>), } // The bodies for items are stored "out of line", in a separate @@ -1639,7 +1640,7 @@ pub struct BareFnTy { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct ExistTy { pub generics: Generics, - pub bounds: TyParamBounds, + pub bounds: ParamBounds, pub impl_trait_fn: Option, } @@ -2048,9 +2049,9 @@ pub enum Item_ { /// A union definition, e.g. `union Foo {x: A, y: B}` ItemUnion(VariantData, Generics), /// Represents a Trait Declaration - ItemTrait(IsAuto, Unsafety, Generics, TyParamBounds, HirVec), + ItemTrait(IsAuto, Unsafety, Generics, ParamBounds, HirVec), /// Represents a Trait Alias Declaration - ItemTraitAlias(Generics, TyParamBounds), + ItemTraitAlias(Generics, ParamBounds), /// An implementation, eg `impl Trait for Foo { .. }` ItemImpl(Unsafety, diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index eabf554bc53..4058db17f2f 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -24,7 +24,7 @@ use syntax::util::parser::{self, AssocOp, Fixity}; use syntax_pos::{self, BytePos, FileName}; use hir; -use hir::{PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier, RangeEnd}; +use hir::{PatKind, Outlives, TraitTyParamBound, TraitBoundModifier, RangeEnd}; use hir::{GenericParam, GenericParamKind, GenericArg}; use std::cell::Cell; @@ -514,7 +514,7 @@ impl<'a> State<'a> { fn print_associated_type(&mut self, name: ast::Name, - bounds: Option<&hir::TyParamBounds>, + bounds: Option<&hir::ParamBounds>, ty: Option<&hir::Ty>) -> io::Result<()> { self.word_space("type")?; @@ -2071,7 +2071,7 @@ impl<'a> State<'a> { } } - pub fn print_bounds(&mut self, prefix: &str, bounds: &[hir::TyParamBound]) -> io::Result<()> { + pub fn print_bounds(&mut self, prefix: &str, bounds: &[hir::ParamBound]) -> io::Result<()> { if !bounds.is_empty() { self.s.word(prefix)?; let mut first = true; @@ -2092,7 +2092,7 @@ impl<'a> State<'a> { } self.print_poly_trait_ref(tref)?; } - RegionTyParamBound(lt) => { + Outlives(lt) => { self.print_lifetime(lt)?; } } @@ -2117,17 +2117,22 @@ impl<'a> State<'a> { pub fn print_generic_param(&mut self, param: &GenericParam) -> io::Result<()> { self.print_name(param.name())?; match param.kind { - GenericParamKind::Lifetime { ref bounds, .. } => { + GenericParamKind::Lifetime { .. } => { let mut sep = ":"; - for bound in bounds { - self.s.word(sep)?; - self.print_lifetime(bound)?; - sep = "+"; + for bound in ¶m.bounds { + match bound { + hir::ParamBound::Outlives(lt) => { + self.s.word(sep)?; + self.print_lifetime(lt)?; + sep = "+"; + } + _ => bug!(), + } } Ok(()) } - GenericParamKind::Type { ref bounds, ref default, .. } => { - self.print_bounds(":", bounds)?; + GenericParamKind::Type { ref default, .. } => { + self.print_bounds(":", ¶m.bounds)?; match default { Some(default) => { self.s.space()?; diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index fc0eee230cd..f8da828d2c3 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -184,9 +184,9 @@ impl_stable_hash_for!(struct hir::GenericArgs { parenthesized }); -impl_stable_hash_for!(enum hir::TyParamBound { +impl_stable_hash_for!(enum hir::ParamBound { TraitTyParamBound(poly_trait_ref, trait_bound_modifier), - RegionTyParamBound(lifetime) + Outlives(lifetime) }); impl_stable_hash_for!(enum hir::TraitBoundModifier { @@ -198,6 +198,7 @@ impl_stable_hash_for!(struct hir::GenericParam { id, span, pure_wrt_drop, + bounds, kind }); @@ -207,16 +208,13 @@ impl<'a> HashStable> for hir::GenericParamKind { hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match self { - hir::GenericParamKind::Lifetime { name, ref bounds, in_band, - ref lifetime } => { + hir::GenericParamKind::Lifetime { name, in_band, ref lifetime } => { name.hash_stable(hcx, hasher); - bounds.hash_stable(hcx, hasher); in_band.hash_stable(hcx, hasher); lifetime.hash_stable(hcx, hasher); } - hir::GenericParamKind::Type { name, ref bounds, ref default, synthetic, attrs } => { + hir::GenericParamKind::Type { name, ref default, synthetic, attrs } => { name.hash_stable(hcx, hasher); - bounds.hash_stable(hcx, hasher); default.hash_stable(hcx, hasher); synthetic.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index b30e5bab968..4d6f2fb41b0 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -61,7 +61,7 @@ use super::region_constraints::GenericKind; use super::lexical_region_resolve::RegionResolutionError; use std::fmt; -use hir::{self, GenericParamKind}; +use hir; use hir::map as hir_map; use hir::def_id::DefId; use middle::region; @@ -1038,12 +1038,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // instead we suggest `T: 'a + 'b` in that case. let mut has_bounds = false; if let hir_map::NodeGenericParam(ref param) = hir.get(id) { - match param.kind { - GenericParamKind::Type { ref bounds, .. } => { - has_bounds = !bounds.is_empty(); - } - _ => bug!("unexpected non-type NodeGenericParam"), - } + has_bounds = !param.bounds.is_empty(); } let sp = hir.span(id); // `sp` only covers `T`, change it so that it covers diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 561e6094c86..2963227c211 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -881,8 +881,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { for param in &generics.params { match param.kind { GenericParamKind::Lifetime { .. } => {} - GenericParamKind::Type { ref bounds, ref default, .. } => { - walk_list!(self, visit_ty_param_bound, bounds); + GenericParamKind::Type { ref default, .. } => { + walk_list!(self, visit_ty_param_bound, ¶m.bounds); if let Some(ref ty) = default { self.visit_ty(&ty); } @@ -1255,9 +1255,9 @@ fn object_lifetime_defaults_for_item( tcx: TyCtxt<'_, '_, '_>, generics: &hir::Generics, ) -> Vec { - fn add_bounds(set: &mut Set1, bounds: &[hir::TyParamBound]) { + fn add_bounds(set: &mut Set1, bounds: &[hir::ParamBound]) { for bound in bounds { - if let hir::RegionTyParamBound(ref lifetime) = *bound { + if let hir::Outlives(ref lifetime) = *bound { set.insert(lifetime.name); } } @@ -1265,10 +1265,10 @@ fn object_lifetime_defaults_for_item( generics.params.iter().filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => None, - GenericParamKind::Type { ref bounds, .. } => { + GenericParamKind::Type { .. } => { let mut set = Set1::Empty; - add_bounds(&mut set, &bounds); + add_bounds(&mut set, ¶m.bounds); let param_def_id = tcx.hir.local_def_id(param.id); for predicate in &generics.where_clause.predicates { @@ -2283,45 +2283,44 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // It is a soft error to shadow a lifetime within a parent scope. self.check_lifetime_param_for_shadowing(old_scope, &lifetime_i); - let bounds = match lifetime_i.kind { - GenericParamKind::Lifetime { ref bounds, .. } => bounds, - _ => bug!(), - }; - for bound in bounds { - match bound.name { - hir::LifetimeName::Underscore => { - let mut err = struct_span_err!( - self.tcx.sess, - bound.span, - E0637, - "invalid lifetime bound name: `'_`" - ); - err.span_label(bound.span, "`'_` is a reserved lifetime name"); - err.emit(); - } - hir::LifetimeName::Static => { - self.insert_lifetime(bound, Region::Static); - self.tcx - .sess - .struct_span_warn( - lifetime_i.span.to(bound.span), - &format!( - "unnecessary lifetime parameter `{}`", + for bound in &lifetime_i.bounds { + match bound { + hir::ParamBound::Outlives(lt) => match lt.name { + hir::LifetimeName::Underscore => { + let mut err = struct_span_err!( + self.tcx.sess, + lt.span, + E0637, + "invalid lifetime bound name: `'_`" + ); + err.span_label(lt.span, "`'_` is a reserved lifetime name"); + err.emit(); + } + hir::LifetimeName::Static => { + self.insert_lifetime(lt, Region::Static); + self.tcx + .sess + .struct_span_warn( + lifetime_i.span.to(lt.span), + &format!( + "unnecessary lifetime parameter `{}`", + lifetime_i.name() + ), + ) + .help(&format!( + "you can use the `'static` lifetime directly, in place \ + of `{}`", lifetime_i.name() - ), - ) - .help(&format!( - "you can use the `'static` lifetime directly, in place \ - of `{}`", - lifetime_i.name() - )) - .emit(); - } - hir::LifetimeName::Fresh(_) - | hir::LifetimeName::Implicit - | hir::LifetimeName::Name(_) => { - self.resolve_lifetime_ref(bound); + )) + .emit(); + } + hir::LifetimeName::Fresh(_) + | hir::LifetimeName::Implicit + | hir::LifetimeName::Name(_) => { + self.resolve_lifetime_ref(lt); + } } + _ => bug!(), } } } @@ -2521,8 +2520,8 @@ fn insert_late_bound_lifetimes( for param in &generics.params { match param.kind { - hir::GenericParamKind::Lifetime { ref bounds, .. } => { - if !bounds.is_empty() { + hir::GenericParamKind::Lifetime { .. } => { + if !param.bounds.is_empty() { // `'a: 'b` means both `'a` and `'b` are referenced appears_in_where_clause.regions.insert(lifetime_def.lifetime.name); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 18b7024a898..941fabe26a6 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1537,14 +1537,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds { } // The parameters must not have bounds for param in type_alias_generics.params.iter() { - let spans: Vec<_> = match param.kind { - GenericParamKind::Lifetime { ref bounds, .. } => { - bounds.iter().map(|b| b.span).collect() - } - GenericParamKind::Type { ref bounds, .. } => { - bounds.iter().map(|b| b.span()).collect() - } - }; + let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect(); if !spans.is_empty() { let mut err = cx.struct_span_lint( TYPE_ALIAS_BOUNDS, diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index dfcdb688b00..d14a02ec8d1 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -99,7 +99,7 @@ impl<'a> AstValidator<'a> { } } - fn no_questions_in_bounds(&self, bounds: &TyParamBounds, where_: &str, is_trait: bool) { + fn no_questions_in_bounds(&self, bounds: &ParamBounds, where_: &str, is_trait: bool) { for bound in bounds { if let TraitTyParamBound(ref poly, TraitBoundModifier::Maybe) = *bound { let mut err = self.err_handler().struct_span_err(poly.span, @@ -142,9 +142,9 @@ impl<'a> AstValidator<'a> { // Check only lifetime parameters are present and that the lifetime // parameters that are present have no bounds. let non_lt_param_spans: Vec<_> = params.iter().filter_map(|param| match param.kind { - GenericParamKind::Lifetime { ref bounds, .. } => { - if !bounds.is_empty() { - let spans: Vec<_> = bounds.iter().map(|b| b.ident.span).collect(); + GenericParamKind::Lifetime { .. } => { + if !param.bounds.is_empty() { + let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect(); self.err_handler() .span_err(spans, "lifetime bounds cannot be used in this context"); } @@ -190,7 +190,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { TyKind::TraitObject(ref bounds, ..) => { let mut any_lifetime_bounds = false; for bound in bounds { - if let RegionTyParamBound(ref lifetime) = *bound { + if let Outlives(ref lifetime) = *bound { if any_lifetime_bounds { span_err!(self.session, lifetime.ident.span, E0226, "only a single explicit lifetime bound is permitted"); @@ -330,8 +330,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> { for param in params { match param.kind { GenericParamKind::Lifetime { .. } => {} - GenericParamKind::Type { ref bounds, ref default, .. } => { - if !bounds.is_empty() { + GenericParamKind::Type { ref default, .. } => { + if !param.bounds.is_empty() { self.err_handler() .span_err(param.ident.span, "type parameters on the left \ side of a trait alias cannot be bounded"); diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index ba0be974b27..c58b6a96ee7 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -203,8 +203,8 @@ 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::TyParamBound) { - self.record("TyParamBound", Id::None, bounds); + fn visit_ty_param_bound(&mut self, bounds: &'v hir::ParamBound) { + self.record("ParamBound", Id::None, bounds); hir_visit::walk_ty_param_bound(self, bounds) } @@ -322,8 +322,8 @@ 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::TyParamBound) { - self.record("TyParamBound", Id::None, bounds); + fn visit_ty_param_bound(&mut self, bounds: &'v ast::ParamBound) { + self.record("ParamBound", Id::None, bounds); ast_visit::walk_ty_param_bound(self, bounds) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 388ac5cdb50..2667f68b260 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1038,7 +1038,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn check_ty_param_bound(&mut self, - ty_param_bound: &hir::TyParamBound) { + ty_param_bound: &hir::ParamBound) { if let hir::TraitTyParamBound(ref trait_ref, _) = *ty_param_bound { if self.path_is_private_type(&trait_ref.trait_ref.path) { self.old_error_set.insert(trait_ref.trait_ref.ref_id); @@ -1270,8 +1270,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn visit_generics(&mut self, generics: &'tcx hir::Generics) { generics.params.iter().for_each(|param| match param.kind { GenericParamKind::Lifetime { .. } => {} - GenericParamKind::Type { ref bounds, .. } => { - for bound in bounds { + GenericParamKind::Type { .. } => { + for bound in ¶m.bounds { self.check_ty_param_bound(bound); } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 6561202be51..b51ef904495 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -813,8 +813,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { for param in &generics.params { match param.kind { GenericParamKind::Lifetime { .. } => self.visit_generic_param(param), - GenericParamKind::Type { ref bounds, ref default, .. } => { - for bound in bounds { + GenericParamKind::Type { ref default, .. } => { + for bound in ¶m.bounds { self.visit_ty_param_bound(bound); } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 6cfec57f80e..cbae6c1ab1a 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -718,7 +718,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { &mut self, item: &'l ast::Item, generics: &'l ast::Generics, - trait_refs: &'l ast::TyParamBounds, + trait_refs: &'l ast::ParamBounds, methods: &'l [ast::TraitItem], ) { let name = item.ident.to_string(); @@ -762,7 +762,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { for super_bound in trait_refs.iter() { let trait_ref = match *super_bound { ast::TraitTyParamBound(ref trait_ref, _) => trait_ref, - ast::RegionTyParamBound(..) => { + ast::Outlives(..) => { continue; } }; @@ -1487,8 +1487,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc fn visit_generics(&mut self, generics: &'l ast::Generics) { generics.params.iter().for_each(|param| match param.kind { ast::GenericParamKind::Lifetime { .. } => {} - ast::GenericParamKind::Type { ref bounds, ref default, .. } => { - for bound in bounds { + ast::GenericParamKind::Type { ref default, .. } => { + for bound in ¶m.bounds { if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 6a63995c0fd..58e2e9b2258 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -104,7 +104,7 @@ pub fn assoc_const_signature( pub fn assoc_type_signature( id: NodeId, ident: ast::Ident, - bounds: Option<&ast::TyParamBounds>, + bounds: Option<&ast::ParamBounds>, default: Option<&ast::Ty>, scx: &SaveContext, ) -> Option { @@ -623,22 +623,22 @@ impl Sig for ast::Generics { start: offset + text.len(), end: offset + text.len() + param_text.len(), }); - match param.kind { - ast::GenericParamKind::Lifetime { ref bounds, .. } => { - if !bounds.is_empty() { - param_text.push_str(": "); - let bounds = bounds.iter() - .map(|l| l.ident.to_string()) + if !param.bounds.is_empty() { + param_text.push_str(": "); + match param.kind { + ast::GenericParamKind::Lifetime { .. } => { + let bounds = param.bounds.iter() + .map(|bound| match bound { + ast::ParamBound::Outlives(lt) => lt.ident.to_string(), + _ => panic!(), + }) .collect::>() .join(" + "); param_text.push_str(&bounds); // FIXME add lifetime bounds refs. } - } - ast::GenericParamKind::Type { ref bounds, .. } => { - if !bounds.is_empty() { - param_text.push_str(": "); - param_text.push_str(&pprust::bounds_to_string(bounds)); + ast::GenericParamKind::Type { .. } => { + param_text.push_str(&pprust::bounds_to_string(¶m.bounds)); // FIXME descend properly into bounds. } } @@ -841,7 +841,7 @@ fn name_and_generics( fn make_assoc_type_signature( id: NodeId, ident: ast::Ident, - bounds: Option<&ast::TyParamBounds>, + bounds: Option<&ast::ParamBounds>, default: Option<&ast::Ty>, scx: &SaveContext, ) -> Result { diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 8a64e4a5367..5f8955612e1 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -844,9 +844,9 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let bounds = impl_m.generics.params.iter().find_map(|param| { match param.kind { GenericParamKind::Lifetime { .. } => None, - GenericParamKind::Type { ref bounds, .. } => { + GenericParamKind::Type { .. } => { if param.id == impl_node_id { - Some(bounds) + Some(¶m.bounds) } else { None } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 2e4ceb5a65c..f95f6a26f0b 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -315,9 +315,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { let from_ty_params = ast_generics.params.iter() .filter_map(|param| match param.kind { - GenericParamKind::Type { ref bounds, .. } if param.id == param_id => { - Some(bounds) - } + GenericParamKind::Type { .. } if param.id == param_id => Some(¶m.bounds), _ => None }) .flat_map(|bounds| bounds.iter()) @@ -1252,7 +1250,7 @@ fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Is it marked with ?Sized fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, - ast_bounds: &[hir::TyParamBound], + ast_bounds: &[hir::ParamBound], span: Span) -> bool { let tcx = astconv.tcx(); @@ -1445,13 +1443,15 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, index += 1; match param.kind { - GenericParamKind::Lifetime { ref bounds, .. } => { - for bound in bounds { - let bound_region = AstConv::ast_region_to_region(&icx, bound, None); - let outlives = - ty::Binder::bind(ty::OutlivesPredicate(region, bound_region)); - predicates.push(outlives.to_predicate()); - } + GenericParamKind::Lifetime { .. } => { + param.bounds.iter().for_each(|bound| match bound { + hir::ParamBound::Outlives(lt) => { + let bound = AstConv::ast_region_to_region(&icx, <, None); + let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound)); + predicates.push(outlives.to_predicate()); + } + _ => bug!(), + }); }, _ => bug!(), } @@ -1461,13 +1461,12 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // type parameter (e.g., ``). for param in &ast_generics.params { match param.kind { - GenericParamKind::Type { ref bounds, .. } => { - let param_ty = ty::ParamTy::new(index, param.name().as_interned_str()) - .to_ty(tcx); + GenericParamKind::Type { .. } => { + let param_ty = ty::ParamTy::new(index, param.name().as_interned_str()).to_ty(tcx); index += 1; - let bounds = - compute_bounds(&icx, param_ty, bounds, SizedByDefault::Yes, param.span); + let sized = SizedByDefault::Yes; + let bounds = compute_bounds(&icx, param_ty, ¶m.bounds, sized, param.span); predicates.extend(bounds.predicates(tcx, param_ty)); } _ => {} @@ -1483,7 +1482,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for bound in bound_pred.bounds.iter() { match bound { - &hir::TyParamBound::TraitTyParamBound(ref poly_trait_ref, _) => { + &hir::ParamBound::TraitTyParamBound(ref poly_trait_ref, _) => { let mut projections = Vec::new(); let trait_ref = @@ -1499,7 +1498,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - &hir::TyParamBound::RegionTyParamBound(ref lifetime) => { + &hir::ParamBound::Outlives(ref lifetime) => { let region = AstConv::ast_region_to_region(&icx, lifetime, None); @@ -1578,7 +1577,7 @@ pub enum SizedByDefault { Yes, No, } /// built-in trait (formerly known as kind): Send. pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, param_ty: Ty<'tcx>, - ast_bounds: &[hir::TyParamBound], + ast_bounds: &[hir::ParamBound], sized_by_default: SizedByDefault, span: Span) -> Bounds<'tcx> @@ -1591,7 +1590,7 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, trait_bounds.push(b); } hir::TraitTyParamBound(_, hir::TraitBoundModifier::Maybe) => {} - hir::RegionTyParamBound(ref l) => { + hir::Outlives(ref l) => { region_bounds.push(l); } } @@ -1625,14 +1624,14 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, } } -/// Converts a specific TyParamBound from the AST into a set of +/// Converts a specific ParamBound from the AST into a set of /// predicates that apply to the self-type. A vector is returned /// because this can be anywhere from 0 predicates (`T:?Sized` adds no /// predicates) to 1 (`T:Foo`) to many (`T:Bar` adds `T:Bar` /// and `::X == i32`). fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, param_ty: Ty<'tcx>, - bound: &hir::TyParamBound) + bound: &hir::ParamBound) -> Vec> { match *bound { @@ -1646,7 +1645,7 @@ fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, .chain(Some(pred.to_predicate())) .collect() } - hir::RegionTyParamBound(ref lifetime) => { + hir::Outlives(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region)); vec![ty::Predicate::TypeOutlives(pred)] diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 2a63b124866..2686ad96c6e 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -536,7 +536,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { fn make_final_bounds<'b, 'c, 'cx>( &self, - ty_to_bounds: FxHashMap>, + ty_to_bounds: FxHashMap>, ty_to_fn: FxHashMap, Option)>, lifetime_to_bounds: FxHashMap>, ) -> Vec { @@ -589,7 +589,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { } _ => panic!("Unexpected data: {:?}, {:?}", ty, data), }; - bounds.insert(TyParamBound::TraitBound( + bounds.insert(ParamBound::TraitBound( PolyTrait { trait_: new_ty, generic_params: poly_trait.generic_params, @@ -732,7 +732,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // later let is_fn = match &mut b { - &mut TyParamBound::TraitBound(ref mut p, _) => { + &mut ParamBound::TraitBound(ref mut p, _) => { // Insert regions into the for_generics hash map first, to ensure // that we don't end up with duplicate bounds (e.g. for<'b, 'b>) for_generics.extend(p.generic_params.clone()); @@ -826,7 +826,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { .entry(*ty.clone()) .or_insert_with(|| FxHashSet()); - bounds.insert(TyParamBound::TraitBound( + bounds.insert(ParamBound::TraitBound( PolyTrait { trait_: Type::ResolvedPath { path: new_trait_path, @@ -843,7 +843,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // that we don't see a // duplicate bound like `T: Iterator + Iterator` // on the docs page. - bounds.remove(&TyParamBound::TraitBound( + bounds.remove(&ParamBound::TraitBound( PolyTrait { trait_: *trait_.clone(), generic_params: Vec::new(), @@ -877,7 +877,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { default.take(); let generic_ty = Type::Generic(param.name.clone()); if !has_sized.contains(&generic_ty) { - bounds.insert(0, TyParamBound::maybe_sized(self.cx)); + bounds.insert(0, ParamBound::maybe_sized(self.cx)); } } GenericParamDefKind::Lifetime => {} @@ -911,7 +911,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // both for visual consistency between 'rustdoc' runs, and to // make writing tests much easier #[inline] - fn sort_where_bounds(&self, mut bounds: &mut Vec) { + fn sort_where_bounds(&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. @@ -939,7 +939,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // to end users, it makes writing tests much more difficult, as predicates // can appear in any order in the final result. // - // To solve this problem, we sort WherePredicates and TyParamBounds + // To solve this problem, we sort WherePredicates and ParamBounds // by their Debug string. The thing to keep in mind is that we don't really // care what the final order is - we're synthesizing an impl or bound // ourselves, so any order can be considered equally valid. By sorting the @@ -949,7 +949,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // Using the Debug impementation for sorting prevents us from needing to // write quite a bit of almost entirely useless code (e.g. how should two // Types be sorted relative to each other). It also allows us to solve the - // problem for both WherePredicates and TyParamBounds at the same time. This + // problem for both WherePredicates and ParamBounds at the same time. This // approach is probably somewhat slower, but the small number of items // involved (impls rarely have more than a few bounds) means that it // shouldn't matter in practice. diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 80eb2d1e214..afe959aaec5 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -474,7 +474,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean: } if *s == "Self" => { bounds.retain(|bound| { match *bound { - clean::TyParamBound::TraitBound(clean::PolyTrait { + clean::ParamBound::TraitBound(clean::PolyTrait { trait_: clean::ResolvedPath { did, .. }, .. }, _) => did != trait_did, @@ -505,7 +505,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean: /// the metadata for a crate, so we want to separate those out and create a new /// list of explicit supertrait bounds to render nicely. fn separate_supertrait_bounds(mut g: clean::Generics) - -> (clean::Generics, Vec) { + -> (clean::Generics, Vec) { let mut ty_bounds = Vec::new(); g.where_predicates.retain(|pred| { match *pred { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 89835ab6aae..4cc8de91baa 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -14,7 +14,7 @@ pub use self::Type::*; pub use self::Mutability::*; pub use self::ItemEnum::*; -pub use self::TyParamBound::*; +pub use self::ParamBound::*; pub use self::SelfTy::*; pub use self::FunctionRetTy::*; pub use self::Visibility::{Public, Inherited}; @@ -532,7 +532,7 @@ pub enum ItemEnum { MacroItem(Macro), PrimitiveItem(PrimitiveType), AssociatedConstItem(Type, Option), - AssociatedTypeItem(Vec, Option), + AssociatedTypeItem(Vec, Option), /// An item that has been stripped by a rustdoc pass StrippedItem(Box), KeywordItem(String), @@ -1458,13 +1458,13 @@ impl Clean for [ast::Attribute] { } #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] -pub enum TyParamBound { +pub enum ParamBound { RegionBound(Lifetime), TraitBound(PolyTrait, hir::TraitBoundModifier) } -impl TyParamBound { - fn maybe_sized(cx: &DocContext) -> TyParamBound { +impl ParamBound { + fn maybe_sized(cx: &DocContext) -> ParamBound { let did = cx.tcx.require_lang_item(lang_items::SizedTraitLangItem); let empty = cx.tcx.intern_substs(&[]); let path = external_path(cx, &cx.tcx.item_name(did).as_str(), @@ -1483,7 +1483,7 @@ impl TyParamBound { fn is_sized_bound(&self, cx: &DocContext) -> bool { use rustc::hir::TraitBoundModifier as TBM; - if let TyParamBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self { + if let ParamBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self { if trait_.def_id() == cx.tcx.lang_items().sized_trait() { return true; } @@ -1492,7 +1492,7 @@ impl TyParamBound { } fn get_poly_trait(&self) -> Option { - if let TyParamBound::TraitBound(ref p, _) = *self { + if let ParamBound::TraitBound(ref p, _) = *self { return Some(p.clone()) } None @@ -1500,17 +1500,17 @@ impl TyParamBound { fn get_trait_type(&self) -> Option { - if let TyParamBound::TraitBound(PolyTrait { ref trait_, .. }, _) = *self { + if let ParamBound::TraitBound(PolyTrait { ref trait_, .. }, _) = *self { return Some(trait_.clone()); } None } } -impl Clean for hir::TyParamBound { - fn clean(&self, cx: &DocContext) -> TyParamBound { +impl Clean for hir::ParamBound { + fn clean(&self, cx: &DocContext) -> ParamBound { match *self { - hir::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)), + hir::Outlives(lt) => RegionBound(lt.clean(cx)), hir::TraitTyParamBound(ref t, modifier) => TraitBound(t.clean(cx), modifier), } } @@ -1570,8 +1570,8 @@ fn external_path(cx: &DocContext, name: &str, trait_did: Option, has_self } } -impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec) { - fn clean(&self, cx: &DocContext) -> TyParamBound { +impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec) { + fn clean(&self, cx: &DocContext) -> ParamBound { let (trait_ref, ref bounds) = *self; inline::record_extern_fqn(cx, trait_ref.def_id, TypeKind::Trait); let path = external_path(cx, &cx.tcx.item_name(trait_ref.def_id).as_str(), @@ -1614,14 +1614,14 @@ impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec } } -impl<'tcx> Clean for ty::TraitRef<'tcx> { - fn clean(&self, cx: &DocContext) -> TyParamBound { +impl<'tcx> Clean for ty::TraitRef<'tcx> { + fn clean(&self, cx: &DocContext) -> ParamBound { (self, vec![]).clean(cx) } } -impl<'tcx> Clean>> for Substs<'tcx> { - fn clean(&self, cx: &DocContext) -> Option> { +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)); @@ -1671,10 +1671,15 @@ impl Clean for hir::Lifetime { impl Clean for hir::GenericParam { fn clean(&self, _: &DocContext) -> Lifetime { match self.kind { - hir::GenericParamKind::Lifetime { ref bounds, .. } => { - if bounds.len() > 0 { - let mut s = format!("{}: {}", self.name(), bounds[0].name.name()); - for bound in bounds.iter().skip(1) { + hir::GenericParamKind::Lifetime { .. } => { + if self.bounds.len() > 0 { + let mut bounds = self.bounds.iter().map(|bound| match bound { + hir::ParamBound::Outlives(lt) => lt, + _ => panic!(), + }); + let name = bounds.next().unwrap().name.name(); + let mut s = format!("{}: {}", self.name(), name); + for bound in bounds { s.push_str(&format!(" + {}", bound.name.name())); } Lifetime(s) @@ -1715,7 +1720,7 @@ impl Clean> for ty::RegionKind { #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] pub enum WherePredicate { - BoundPredicate { ty: Type, bounds: Vec }, + BoundPredicate { ty: Type, bounds: Vec }, RegionPredicate { lifetime: Lifetime, bounds: Vec}, EqPredicate { lhs: Type, rhs: Type }, } @@ -1797,7 +1802,7 @@ impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region< WherePredicate::BoundPredicate { ty: ty.clean(cx), - bounds: vec![TyParamBound::RegionBound(lt.clean(cx).unwrap())] + bounds: vec![ParamBound::RegionBound(lt.clean(cx).unwrap())] } } } @@ -1814,8 +1819,8 @@ impl<'tcx> Clean for ty::ProjectionPredicate<'tcx> { impl<'tcx> Clean for ty::ProjectionTy<'tcx> { fn clean(&self, cx: &DocContext) -> Type { let trait_ = match self.trait_ref(cx.tcx).clean(cx) { - TyParamBound::TraitBound(t, _) => t.trait_, - TyParamBound::RegionBound(_) => { + ParamBound::TraitBound(t, _) => t.trait_, + ParamBound::RegionBound(_) => { panic!("cleaning a trait got a region") } }; @@ -1832,7 +1837,7 @@ pub enum GenericParamDefKind { Lifetime, Type { did: DefId, - bounds: Vec, + bounds: Vec, default: Option, synthetic: Option, }, @@ -1887,10 +1892,15 @@ impl<'tcx> Clean for ty::GenericParamDef { impl Clean for hir::GenericParam { fn clean(&self, cx: &DocContext) -> GenericParamDef { let (name, kind) = match self.kind { - hir::GenericParamKind::Lifetime { ref bounds, .. } => { - let name = if bounds.len() > 0 { - let mut s = format!("{}: {}", self.name(), bounds[0].name.name()); - for bound in bounds.iter().skip(1) { + hir::GenericParamKind::Lifetime { .. } => { + let name = if self.bounds.len() > 0 { + let mut bounds = self.bounds.iter().map(|bound| match bound { + hir::ParamBound::Outlives(lt) => lt, + _ => panic!(), + }); + let name = bounds.next().unwrap().name.name(); + let mut s = format!("{}: {}", self.name(), name); + for bound in bounds { s.push_str(&format!(" + {}", bound.name.name())); } s @@ -1899,10 +1909,10 @@ impl Clean for hir::GenericParam { }; (name, GenericParamDefKind::Lifetime) } - hir::GenericParamKind::Type { ref bounds, ref default, synthetic, .. } => { + hir::GenericParamKind::Type { ref default, synthetic, .. } => { (self.name().clean(cx), GenericParamDefKind::Type { did: cx.tcx.hir.local_def_id(self.id), - bounds: bounds.clean(cx), + bounds: self.bounds.clean(cx), default: default.clean(cx), synthetic: synthetic, }) @@ -2041,7 +2051,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, if !sized_params.contains(&tp.name) { where_predicates.push(WP::BoundPredicate { ty: Type::Generic(tp.name.clone()), - bounds: vec![TyParamBound::maybe_sized(cx)], + bounds: vec![ParamBound::maybe_sized(cx)], }) } } @@ -2282,7 +2292,7 @@ pub struct Trait { pub unsafety: hir::Unsafety, pub items: Vec, pub generics: Generics, - pub bounds: Vec, + pub bounds: Vec, pub is_spotlight: bool, pub is_auto: bool, } @@ -2504,7 +2514,7 @@ impl<'tcx> Clean for ty::AssociatedItem { // at the end. match bounds.iter().position(|b| b.is_sized_bound(cx)) { Some(i) => { bounds.remove(i); } - None => bounds.push(TyParamBound::maybe_sized(cx)), + None => bounds.push(ParamBound::maybe_sized(cx)), } let ty = if self.defaultness.has_value() { @@ -2559,7 +2569,7 @@ pub enum Type { /// structs/enums/traits (most that'd be an hir::TyPath) ResolvedPath { path: Path, - typarams: Option>, + typarams: Option>, did: DefId, /// true if is a `T::Name` path for associated types is_generic: bool, @@ -2595,7 +2605,7 @@ pub enum Type { Infer, // impl TraitA+TraitB - ImplTrait(Vec), + ImplTrait(Vec), } #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Copy, Debug)] @@ -3147,7 +3157,6 @@ impl<'tcx> Clean for Ty<'tcx> { } } - let bounds = bounds.predicates.iter().filter_map(|pred| if let ty::Predicate::Projection(proj) = *pred { let proj = proj.skip_binder(); @@ -3169,7 +3178,7 @@ impl<'tcx> Clean for Ty<'tcx> { }).collect::>(); bounds.extend(regions); if !has_sized && !bounds.is_empty() { - bounds.insert(0, TyParamBound::maybe_sized(cx)); + bounds.insert(0, ParamBound::maybe_sized(cx)); } ImplTrait(bounds) } @@ -4465,11 +4474,11 @@ impl AutoTraitResult { } } -impl From for SimpleBound { - fn from(bound: TyParamBound) -> Self { +impl From for SimpleBound { + fn from(bound: ParamBound) -> Self { match bound.clone() { - TyParamBound::RegionBound(l) => SimpleBound::RegionBound(l), - TyParamBound::TraitBound(t, mod_) => match t.trait_ { + ParamBound::RegionBound(l) => SimpleBound::RegionBound(l), + ParamBound::TraitBound(t, mod_) => match t.trait_ { Type::ResolvedPath { path, typarams, .. } => { SimpleBound::TraitBound(path.segments, typarams diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 95ceee85690..81ad2a5bf51 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -147,7 +147,7 @@ pub fn ty_params(mut params: Vec) -> Vec) -> Vec { +fn ty_bounds(bounds: Vec) -> Vec { bounds } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index e858f10860b..7147e13805f 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -77,7 +77,7 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> { /// Table node id of lifetime parameter definition -> substituted lifetime pub lt_substs: RefCell>, /// Table DefId of `impl Trait` in argument position -> bounds - pub impl_trait_bounds: RefCell>>, + pub impl_trait_bounds: RefCell>>, pub send_trait: Option, pub fake_def_ids: RefCell>, pub all_fake_def_ids: RefCell>, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index f85a70a6d40..542d753c4f0 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -201,7 +201,7 @@ pub struct Trait { pub name: Name, pub items: hir::HirVec, pub generics: hir::Generics, - pub bounds: hir::HirVec, + pub bounds: hir::HirVec, pub attrs: hir::HirVec, pub id: ast::NodeId, pub whence: Span, diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 86c312275ff..4174f656995 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -46,7 +46,7 @@ pub struct MutableSpace(pub clean::Mutability); #[derive(Copy, Clone)] pub struct RawMutableSpace(pub clean::Mutability); /// Wrapper struct for emitting type parameter bounds. -pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]); +pub struct ParamBounds<'a>(pub &'a [clean::ParamBound]); /// Wrapper struct for emitting a comma-separated list of items pub struct CommaSep<'a, T: 'a>(pub &'a [T]); pub struct AbiSpace(pub Abi); @@ -104,9 +104,9 @@ impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> { } } -impl<'a> fmt::Display for TyParamBounds<'a> { +impl<'a> fmt::Display for ParamBounds<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let &TyParamBounds(bounds) = self; + let &ParamBounds(bounds) = self; for (i, bound) in bounds.iter().enumerate() { if i > 0 { f.write_str(" + ")?; @@ -126,9 +126,9 @@ impl fmt::Display for clean::GenericParamDef { if !bounds.is_empty() { if f.alternate() { - write!(f, ": {:#}", TyParamBounds(bounds))?; + write!(f, ": {:#}", ParamBounds(bounds))?; } else { - write!(f, ": {}", TyParamBounds(bounds))?; + write!(f, ": {}", ParamBounds(bounds))?; } } @@ -190,9 +190,9 @@ impl<'a> fmt::Display for WhereClause<'a> { &clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => { let bounds = bounds; if f.alternate() { - clause.push_str(&format!("{:#}: {:#}", ty, TyParamBounds(bounds))); + clause.push_str(&format!("{:#}: {:#}", ty, ParamBounds(bounds))); } else { - clause.push_str(&format!("{}: {}", ty, TyParamBounds(bounds))); + clause.push_str(&format!("{}: {}", ty, ParamBounds(bounds))); } } &clean::WherePredicate::RegionPredicate { ref lifetime, @@ -267,7 +267,7 @@ impl fmt::Display for clean::PolyTrait { } } -impl fmt::Display for clean::TyParamBound { +impl fmt::Display for clean::ParamBound { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { clean::RegionBound(ref lt) => { @@ -512,7 +512,7 @@ fn primitive_link(f: &mut fmt::Formatter, /// Helper to render type parameters fn tybounds(w: &mut fmt::Formatter, - typarams: &Option>) -> fmt::Result { + typarams: &Option>) -> fmt::Result { match *typarams { Some(ref params) => { for param in params { @@ -667,7 +667,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: } } clean::ImplTrait(ref bounds) => { - write!(f, "impl {}", TyParamBounds(bounds)) + write!(f, "impl {}", ParamBounds(bounds)) } clean::QPath { ref name, ref self_type, ref trait_ } => { let should_show_cast = match *trait_ { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 675d1097bda..21724c2d730 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -69,7 +69,7 @@ use doctree; use fold::DocFolder; use html::escape::Escape; use html::format::{ConstnessSpace}; -use html::format::{TyParamBounds, WhereClause, href, AbiSpace}; +use html::format::{ParamBounds, WhereClause, href, AbiSpace}; use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace}; use html::format::fmt_impl_for_trait_page; use html::item_type::ItemType; @@ -2960,14 +2960,14 @@ fn assoc_const(w: &mut fmt::Formatter, } fn assoc_type(w: &mut W, it: &clean::Item, - bounds: &Vec, + bounds: &Vec, default: Option<&clean::Type>, link: AssocItemLink) -> fmt::Result { write!(w, "type {}", naive_assoc_href(it, link), it.name.as_ref().unwrap())?; if !bounds.is_empty() { - write!(w, ": {}", TyParamBounds(bounds))? + write!(w, ": {}", ParamBounds(bounds))? } if let Some(default) = default { write!(w, " = {}", default)?; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f589057218c..b082cde5df7 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,7 @@ // The Rust abstract syntax tree. -pub use self::TyParamBound::*; +pub use self::ParamBound::*; pub use self::UnsafeSource::*; pub use self::GenericArgs::*; pub use symbol::{Ident, Symbol as Name}; @@ -269,44 +269,42 @@ pub const CRATE_NODE_ID: NodeId = NodeId(0); /// small, positive ids. pub const DUMMY_NODE_ID: NodeId = NodeId(!0); +/// A modifier on a bound, currently this is only used for `?Sized`, where the +/// modifier is `Maybe`. Negative bounds should also be handled here. +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub enum TraitBoundModifier { + None, + Maybe, +} + /// The AST represents all type param bounds as types. /// typeck::collect::compute_bounds matches these against /// the "special" built-in traits (see middle::lang_items) and /// detects Copy, Send and Sync. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum TyParamBound { +pub enum ParamBound { TraitTyParamBound(PolyTraitRef, TraitBoundModifier), - RegionTyParamBound(Lifetime) + Outlives(Lifetime) } -impl TyParamBound { +impl ParamBound { pub fn span(&self) -> Span { match self { &TraitTyParamBound(ref t, ..) => t.span, - &RegionTyParamBound(ref l) => l.ident.span, + &Outlives(ref l) => l.ident.span, } } } -/// A modifier on a bound, currently this is only used for `?Sized`, where the -/// modifier is `Maybe`. Negative bounds should also be handled here. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum TraitBoundModifier { - None, - Maybe, -} - -pub type TyParamBounds = Vec; +pub type ParamBounds = Vec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum GenericParamKind { /// A lifetime definition, e.g. `'a: 'b+'c+'d`. Lifetime { - bounds: Vec, lifetime: Lifetime, }, Type { - bounds: TyParamBounds, default: Option>, } } @@ -316,6 +314,7 @@ pub struct GenericParam { pub ident: Ident, pub id: NodeId, pub attrs: ThinVec, + pub bounds: ParamBounds, pub kind: GenericParamKind, } @@ -384,7 +383,7 @@ pub struct WhereBoundPredicate { /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: TyParamBounds, + pub bounds: ParamBounds, } /// A lifetime predicate. @@ -930,7 +929,7 @@ impl Expr { } } - fn to_bound(&self) -> Option { + fn to_bound(&self) -> Option { match &self.node { ExprKind::Path(None, path) => Some(TraitTyParamBound(PolyTraitRef::new(Vec::new(), path.clone(), self.span), @@ -1355,7 +1354,7 @@ pub struct TraitItem { pub enum TraitItemKind { Const(P, Option>), Method(MethodSig, Option>), - Type(TyParamBounds, Option>), + Type(ParamBounds, Option>), Macro(Mac), } @@ -1540,10 +1539,10 @@ pub enum TyKind { Path(Option, Path), /// A trait object type `Bound1 + Bound2 + Bound3` /// where `Bound` is a trait or a lifetime. - TraitObject(TyParamBounds, TraitObjectSyntax), + TraitObject(ParamBounds, TraitObjectSyntax), /// An `impl Bound1 + Bound2 + Bound3` type /// where `Bound` is a trait or a lifetime. - ImplTrait(TyParamBounds), + ImplTrait(ParamBounds), /// No-op; kept solely so that we can pretty-print faithfully Paren(P), /// Unused for now @@ -2064,11 +2063,11 @@ pub enum ItemKind { /// A Trait declaration (`trait` or `pub trait`). /// /// E.g. `trait Foo { .. }`, `trait Foo { .. }` or `auto trait Foo {}` - Trait(IsAuto, Unsafety, Generics, TyParamBounds, Vec), + Trait(IsAuto, Unsafety, Generics, ParamBounds, Vec), /// Trait alias /// /// E.g. `trait Foo = Bar + Quux;` - TraitAlias(Generics, TyParamBounds), + TraitAlias(Generics, ParamBounds), /// An implementation. /// /// E.g. `impl Foo { .. }` or `impl Trait for Foo { .. }` diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 695ad9c233f..ea151ca68a8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -68,18 +68,18 @@ pub trait AstBuilder { span: Span, id: ast::Ident, attrs: Vec, - bounds: ast::TyParamBounds, + bounds: ast::ParamBounds, default: Option>) -> ast::GenericParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef; - fn typarambound(&self, path: ast::Path) -> ast::TyParamBound; + fn ty_param_bound(&self, path: ast::Path) -> ast::ParamBound; fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime; fn lifetime_def(&self, span: Span, ident: ast::Ident, attrs: Vec, - bounds: Vec) + bounds: ast::ParamBounds) -> ast::GenericParam; // statements @@ -436,14 +436,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, ident: ast::Ident, attrs: Vec, - bounds: ast::TyParamBounds, + bounds: ast::ParamBounds, default: Option>) -> ast::GenericParam { ast::GenericParam { ident: ident.with_span_pos(span), id: ast::DUMMY_NODE_ID, attrs: attrs.into(), + bounds, kind: ast::GenericParamKind::Type { - bounds, default, } } @@ -464,7 +464,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } } - fn typarambound(&self, path: ast::Path) -> ast::TyParamBound { + fn ty_param_bound(&self, path: ast::Path) -> ast::ParamBound { ast::TraitTyParamBound(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None) } @@ -476,16 +476,16 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, ident: ast::Ident, attrs: Vec, - bounds: Vec) + bounds: ast::ParamBounds) -> ast::GenericParam { let lifetime = self.lifetime(span, ident); ast::GenericParam { ident: lifetime.ident, id: lifetime.id, attrs: attrs.into(), + bounds, kind: ast::GenericParamKind::Lifetime { lifetime, - bounds, } } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index ea147186b18..a0c69d83e84 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -268,17 +268,16 @@ pub trait Folder : Sized { noop_fold_interpolated(nt, self) } - fn fold_opt_bounds(&mut self, b: Option) - -> Option { + fn fold_opt_bounds(&mut self, b: Option) -> Option { noop_fold_opt_bounds(b, self) } - fn fold_bounds(&mut self, b: TyParamBounds) - -> TyParamBounds { + fn fold_bounds(&mut self, b: ParamBounds) + -> ParamBounds { noop_fold_bounds(b, self) } - fn fold_ty_param_bound(&mut self, tpb: TyParamBound) -> TyParamBound { + fn fold_ty_param_bound(&mut self, tpb: ParamBound) -> ParamBound { noop_fold_ty_param_bound(tpb, self) } @@ -678,12 +677,12 @@ pub fn noop_fold_fn_decl(decl: P, fld: &mut T) -> P { }) } -pub fn noop_fold_ty_param_bound(tpb: TyParamBound, fld: &mut T) - -> TyParamBound +pub fn noop_fold_ty_param_bound(tpb: ParamBound, fld: &mut T) + -> ParamBound where T: Folder { match tpb { TraitTyParamBound(ty, modifier) => TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier), - RegionTyParamBound(lifetime) => RegionTyParamBound(noop_fold_lifetime(lifetime, fld)), + Outlives(lifetime) => Outlives(noop_fold_lifetime(lifetime, fld)), } } @@ -850,13 +849,13 @@ pub fn noop_fold_mt(MutTy {ty, mutbl}: MutTy, folder: &mut T) -> MutT } } -pub fn noop_fold_opt_bounds(b: Option, folder: &mut T) - -> Option { +pub fn noop_fold_opt_bounds(b: Option, folder: &mut T) + -> Option { b.map(|bounds| folder.fold_bounds(bounds)) } -fn noop_fold_bounds(bounds: TyParamBounds, folder: &mut T) - -> TyParamBounds { +fn noop_fold_bounds(bounds: ParamBounds, folder: &mut T) + -> ParamBounds { bounds.move_map(|bound| folder.fold_ty_param_bound(bound)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 203b529222d..ce79735fff5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -10,7 +10,7 @@ use rustc_target::spec::abi::{self, Abi}; use ast::{AngleBracketedArgs, ParenthesizedArgData, AttrStyle, BareFnTy}; -use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; +use ast::{Outlives, TraitTyParamBound, TraitBoundModifier}; use ast::Unsafety; use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use ast::Block; @@ -36,7 +36,7 @@ use ast::{VariantData, StructField}; use ast::StrStyle; use ast::SelfKind; use ast::{TraitItem, TraitRef, TraitObjectSyntax}; -use ast::{Ty, TyKind, TypeBinding, TyParamBounds}; +use ast::{Ty, TyKind, TypeBinding, ParamBounds}; use ast::{Visibility, VisibilityKind, WhereClause, CrateSugar}; use ast::{UseTree, UseTreeKind}; use ast::{BinOpKind, UnOp}; @@ -4735,7 +4735,7 @@ impl<'a> Parser<'a> { // LT_BOUND = LIFETIME (e.g. `'a`) // TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) // TY_BOUND_NOPAREN = [?] [for] SIMPLE_PATH (e.g. `?for<'a: 'b> m::Trait<'a>`) - fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, TyParamBounds> { + fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, ParamBounds> { let mut bounds = Vec::new(); loop { // This needs to be syncronized with `Token::can_begin_bound`. @@ -4752,7 +4752,7 @@ impl<'a> Parser<'a> { self.span_err(question_span, "`?` may only modify trait bounds, not lifetime bounds"); } - bounds.push(RegionTyParamBound(self.expect_lifetime())); + bounds.push(Outlives(RegionTyParamBound(self.expect_lifetime()))); if has_parens { self.expect(&token::CloseDelim(token::Paren))?; self.span_err(self.prev_span, @@ -4784,7 +4784,7 @@ impl<'a> Parser<'a> { return Ok(bounds); } - fn parse_ty_param_bounds(&mut self) -> PResult<'a, TyParamBounds> { + fn parse_ty_param_bounds(&mut self) -> PResult<'a, ParamBounds> { self.parse_ty_param_bounds_common(true) } @@ -4823,17 +4823,17 @@ impl<'a> Parser<'a> { Ok(GenericParam { ident, - attrs: preceding_attrs.into(), id: ast::DUMMY_NODE_ID, + attrs: preceding_attrs.into(), + bounds, kind: GenericParamKind::Type { - bounds, default, } }) } /// Parses the following grammar: - /// TraitItemAssocTy = Ident ["<"...">"] [":" [TyParamBounds]] ["where" ...] ["=" Ty] + /// TraitItemAssocTy = Ident ["<"...">"] [":" [ParamBounds]] ["where" ...] ["=" Ty] fn parse_trait_item_assoc_ty(&mut self) -> PResult<'a, (Ident, TraitItemKind, ast::Generics)> { let ident = self.parse_ident()?; @@ -4868,7 +4868,9 @@ impl<'a> Parser<'a> { let lifetime = self.expect_lifetime(); // Parse lifetime parameter. let bounds = if self.eat(&token::Colon) { - self.parse_lt_param_bounds() + self.parse_lt_param_bounds().iter() + .map(|bound| ast::ParamBound::Outlives(*bound)) + .collect() } else { Vec::new() }; @@ -4876,9 +4878,9 @@ impl<'a> Parser<'a> { ident: lifetime.ident, id: lifetime.id, attrs: attrs.into(), + bounds, kind: ast::GenericParamKind::Lifetime { lifetime, - bounds, } }); if seen_ty_param { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 84a4a51b716..c8d139c7de9 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -12,7 +12,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::{self, Abi}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; -use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; +use ast::{SelfKind, Outlives, TraitTyParamBound, TraitBoundModifier}; use ast::{Attribute, MacDelimiter, GenericArg}; use util::parser::{self, AssocOp, Fixity}; use attr; @@ -292,7 +292,7 @@ pub fn ty_to_string(ty: &ast::Ty) -> String { to_string(|s| s.print_type(ty)) } -pub fn bounds_to_string(bounds: &[ast::TyParamBound]) -> String { +pub fn bounds_to_string(bounds: &[ast::ParamBound]) -> String { to_string(|s| s.print_bounds("", bounds)) } @@ -1178,7 +1178,7 @@ impl<'a> State<'a> { fn print_associated_type(&mut self, ident: ast::Ident, - bounds: Option<&ast::TyParamBounds>, + bounds: Option<&ast::ParamBounds>, ty: Option<&ast::Ty>) -> io::Result<()> { self.word_space("type")?; @@ -2811,7 +2811,7 @@ impl<'a> State<'a> { pub fn print_bounds(&mut self, prefix: &str, - bounds: &[ast::TyParamBound]) + bounds: &[ast::ParamBound]) -> io::Result<()> { if !bounds.is_empty() { self.s.word(prefix)?; @@ -2833,7 +2833,7 @@ impl<'a> State<'a> { } self.print_poly_trait_ref(tref)?; } - RegionTyParamBound(lt) => { + Outlives(lt) => { self.print_lifetime(lt)?; } } @@ -2879,14 +2879,19 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &generic_params, |s, param| { match param.kind { - ast::GenericParamKind::Lifetime { ref bounds, ref lifetime } => { + ast::GenericParamKind::Lifetime { ref lifetime } => { s.print_outer_attributes_inline(¶m.attrs)?; - s.print_lifetime_bounds(lifetime, bounds) + s.print_lifetime_bounds(lifetime, ¶m.bounds.iter().map(|bound| { + match bound { + ast::ParamBound::Outlives(lt) => *lt, + _ => panic!(), + } + }).collect::>().as_slice()) }, - ast::GenericParamKind::Type { ref bounds, ref default } => { + ast::GenericParamKind::Type { ref default } => { s.print_outer_attributes_inline(¶m.attrs)?; s.print_ident(param.ident)?; - s.print_bounds(":", bounds)?; + s.print_bounds(":", ¶m.bounds)?; match default { Some(ref default) => { s.s.space()?; diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index 95ae9f9bcf8..485775765ab 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -95,7 +95,7 @@ impl<'ast> Visitor<'ast> for NodeCounter { self.count += 1; walk_trait_ref(self, t) } - fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) { + fn visit_ty_param_bound(&mut self, bounds: &ParamBound) { self.count += 1; walk_ty_param_bound(self, bounds) } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index e12369a522d..4e0c417d4fb 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -86,7 +86,7 @@ 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 TyParamBound) { + fn visit_ty_param_bound(&mut self, bounds: &'ast ParamBound) { walk_ty_param_bound(self, bounds) } fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) { @@ -479,31 +479,30 @@ 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 TyParamBound) { +pub fn walk_ty_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); } - RegionTyParamBound(ref lifetime) => { + Outlives(ref lifetime) => { visitor.visit_lifetime(lifetime); } } } pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) { + visitor.visit_ident(param.ident); match param.kind { GenericParamKind::Lifetime { ref bounds, ref lifetime } => { - visitor.visit_ident(param.ident); walk_list!(visitor, visit_lifetime, bounds); - walk_list!(visitor, visit_attribute, param.attrs.iter()); } GenericParamKind::Type { ref bounds, ref default } => { visitor.visit_ident(t.ident); walk_list!(visitor, visit_ty_param_bound, bounds); walk_list!(visitor, visit_ty, default); - walk_list!(visitor, visit_attribute, param.attrs.iter()); } } + walk_list!(visitor, visit_attribute, param.attrs.iter()); } pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 1024d445cdb..a7d8156f4a0 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -551,22 +551,21 @@ impl<'a> TraitDef<'a> { // Create the generic parameters params.extend(generics.params.iter().map(|param| match param.kind { GenericParamKind::Lifetime { .. } => param.clone(), - GenericParamKind::Type { bounds: ref ty_bounds, .. } => { + GenericParamKind::Type { .. } => { // I don't think this can be moved out of the loop, since - // a TyParamBound requires an ast id + // a ParamBound requires an ast id let mut bounds: Vec<_> = // extra restrictions on the generics parameters to the // type being derived upon self.additional_bounds.iter().map(|p| { - cx.typarambound(p.to_path(cx, self.span, - type_ident, generics)) + cx.ty_param_bound(p.to_path(cx, self.span, type_ident, generics)) }).collect(); // require the current trait - bounds.push(cx.typarambound(trait_path.clone())); + bounds.push(cx.ty_param_bound(trait_path.clone())); // also add in any bounds from the declaration - for declared_bound in ty_bounds { + for declared_bound in ¶m.bounds { bounds.push((*declared_bound).clone()); } @@ -635,12 +634,12 @@ impl<'a> TraitDef<'a> { let mut bounds: Vec<_> = self.additional_bounds .iter() .map(|p| { - cx.typarambound(p.to_path(cx, self.span, type_ident, generics)) + cx.ty_param_bound(p.to_path(cx, self.span, type_ident, generics)) }) .collect(); // require the current trait - bounds.push(cx.typarambound(trait_path.clone())); + bounds.push(cx.ty_param_bound(trait_path.clone())); let predicate = ast::WhereBoundPredicate { span: self.span, diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 127ed62b8c5..327a35d39b3 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -219,7 +219,7 @@ fn mk_ty_param(cx: &ExtCtxt, let bounds = bounds.iter() .map(|b| { let path = b.to_path(cx, span, self_ident, self_generics); - cx.typarambound(path) + cx.ty_param_bound(path) }) .collect(); cx.typaram(span, cx.ident_of(name), attrs.to_owned(), bounds, None) @@ -261,9 +261,8 @@ impl<'a> LifetimeBounds<'a> { .iter() .map(|&(lt, ref bounds)| { let bounds = bounds.iter() - .map(|b| cx.lifetime(span, Ident::from_str(b))) - .collect(); - cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds) + .map(|b| ast::ParamBound::Outlives(cx.lifetime(span, Ident::from_str(b)))); + cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds.collect()) }) .chain(self.bounds .iter() -- cgit 1.4.1-3-g733a5 From 80dbe58efc7152cc9925012de0e568f36a9893a8 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 28 May 2018 15:23:16 +0100 Subject: 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(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index d5c9d964eb2..a550f60fb4b 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 494e6e1ba33..fed4f150075 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 8253a34f310..8249b306a0c 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 4058db17f2f..10cecdb2d47 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 2963227c211..fc160b35ae4 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 c58b6a96ee7..879adebf7ea 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 b51ef904495..731c6e2ef82 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 f95f6a26f0b..c2b52e0de75 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 2686ad96c6e..9671007a06b 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 afe959aaec5..c85178961c1 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 4cc8de91baa..2f48267579a 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 81ad2a5bf51..c7477645d6a 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 4174f656995..bd9194a8669 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 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, + 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 { + 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::>().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) => { -- cgit 1.4.1-3-g733a5 From 6015edf9af375385ca9eb2ebbb8794c782fa7244 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 30 May 2018 16:49:39 +0100 Subject: Remove name from GenericParamKind::Lifetime --- src/librustc/hir/intravisit.rs | 4 +--- src/librustc/hir/lowering.rs | 23 +++++-------------- src/librustc/hir/mod.rs | 2 -- src/librustc/ich/impls_hir.rs | 3 +-- src/libsyntax/ast.rs | 4 +--- src/libsyntax/ext/build.rs | 4 +--- src/libsyntax/parse/parser.rs | 4 +--- src/libsyntax/print/pprust.rs | 37 +++++++++++++------------------ src/libsyntax_ext/deriving/generic/mod.rs | 4 ++-- src/libsyntax_ext/deriving/generic/ty.rs | 4 ++-- 10 files changed, 30 insertions(+), 59 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index a550f60fb4b..5a41d71b93d 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -736,9 +736,7 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBou TraitTyParamBound(ref typ, modifier) => { visitor.visit_poly_trait_ref(typ, modifier); } - Outlives(ref lifetime) => { - visitor.visit_lifetime(lifetime); - } + Outlives(ref lifetime) => visitor.visit_lifetime(lifetime), } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d0a3f0d097f..ec162adf52b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -706,13 +706,8 @@ impl<'a> LoweringContext<'a> { kind: hir::GenericParamKind::Lifetime { lt_name: hir_name, in_band: true, - lifetime: hir::Lifetime { - id: def_node_id, - span, - name: hir_name, } } - } }) .chain(in_band_ty_params.into_iter()) .collect(); @@ -1423,12 +1418,7 @@ impl<'a> LoweringContext<'a> { kind: hir::GenericParamKind::Lifetime { lt_name: name, in_band: false, - lifetime: hir::Lifetime { - id: def_node_id, - span: lifetime.span, - name, } - } }); } } @@ -1947,21 +1937,20 @@ impl<'a> LoweringContext<'a> { -> hir::GenericParam { let mut bounds = self.lower_param_bounds(¶m.bounds, itctx); match param.kind { - GenericParamKind::Lifetime { ref lifetime } => { + GenericParamKind::Lifetime => { let was_collecting_in_band = self.is_collecting_in_band_lifetimes; self.is_collecting_in_band_lifetimes = false; - let lifetime = self.lower_lifetime(lifetime); + let lt = self.lower_lifetime(&Lifetime { id: param.id, ident: param.ident }); let param = hir::GenericParam { - id: lifetime.id, - name: lifetime.name.name(), - span: lifetime.span, + id: lt.id, + name: lt.name.name(), + span: lt.span, pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), bounds, kind: hir::GenericParamKind::Lifetime { - lt_name: lifetime.name, + lt_name: lt.name, in_band: false, - lifetime, } }; diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index b4470ed7c1e..cf0ae5aa94d 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -454,8 +454,6 @@ pub enum GenericParamKind { // as a result of an in-band lifetime usage like: // `fn foo(x: &'a u8) -> &'a u8 { x }` in_band: bool, - // We keep a `Lifetime` around for now just so we can `visit_lifetime`. - lifetime: Lifetime, }, Type { default: Option>, diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 0c31134ae9c..ae2bf1e4c74 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -209,10 +209,9 @@ impl<'a> HashStable> for hir::GenericParamKind { hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match self { - hir::GenericParamKind::Lifetime { lt_name, in_band, ref lifetime } => { + hir::GenericParamKind::Lifetime { lt_name, in_band } => { lt_name.hash_stable(hcx, hasher); in_band.hash_stable(hcx, hasher); - lifetime.hash_stable(hcx, hasher); } hir::GenericParamKind::Type { ref default, synthetic, attrs } => { default.hash_stable(hcx, hasher); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 67679468fe4..98f786628f9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -301,9 +301,7 @@ pub type ParamBounds = Vec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum GenericParamKind { /// A lifetime definition, e.g. `'a: 'b+'c+'d`. - Lifetime { - lifetime: Lifetime, - }, + Lifetime, Type { default: Option>, } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index ea151ca68a8..cc0bc7f0c74 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -484,9 +484,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: lifetime.id, attrs: attrs.into(), bounds, - kind: ast::GenericParamKind::Lifetime { - lifetime, - } + kind: ast::GenericParamKind::Lifetime, } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 66e48512065..b2cfb459c35 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4877,9 +4877,7 @@ impl<'a> Parser<'a> { id: lifetime.id, attrs: attrs.into(), bounds, - kind: ast::GenericParamKind::Lifetime { - lifetime, - } + kind: ast::GenericParamKind::Lifetime, }); if seen_ty_param { self.span_err(self.prev_span, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c672b01fb27..5d39367f4b0 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -308,8 +308,8 @@ pub fn expr_to_string(e: &ast::Expr) -> String { to_string(|s| s.print_expr(e)) } -pub fn lifetime_to_string(e: &ast::Lifetime) -> String { - to_string(|s| s.print_lifetime(e)) +pub fn lifetime_to_string(lt: &ast::Lifetime) -> String { + to_string(|s| s.print_lifetime(*lt)) } pub fn tt_to_string(tt: tokenstream::TokenTree) -> String { @@ -1008,10 +1008,9 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_opt_lifetime(&mut self, - lifetime: &Option) -> io::Result<()> { - if let Some(l) = *lifetime { - self.print_lifetime(&l)?; + pub fn print_opt_lifetime(&mut self, lifetime: &Option) -> io::Result<()> { + if let Some(lt) = *lifetime { + self.print_lifetime(lt)?; self.nbsp()?; } Ok(()) @@ -1019,7 +1018,7 @@ impl<'a> State<'a> { pub fn print_generic_arg(&mut self, generic_arg: &GenericArg) -> io::Result<()> { match generic_arg { - GenericArg::Lifetime(lt) => self.print_lifetime(lt), + GenericArg::Lifetime(lt) => self.print_lifetime(*lt), GenericArg::Type(ty) => self.print_type(ty), } } @@ -2833,26 +2832,19 @@ impl<'a> State<'a> { } self.print_poly_trait_ref(tref)?; } - Outlives(lt) => { - self.print_lifetime(lt)?; - } + Outlives(lt) => self.print_lifetime(*lt)?, } } } Ok(()) } - pub fn print_lifetime(&mut self, - lifetime: &ast::Lifetime) - -> io::Result<()> - { + pub fn print_lifetime(&mut self, lifetime: ast::Lifetime) -> io::Result<()> { self.print_name(lifetime.ident.name) } - pub fn print_lifetime_bounds(&mut self, - lifetime: &ast::Lifetime, - bounds: &ast::ParamBounds) - -> io::Result<()> + pub fn print_lifetime_bounds(&mut self, lifetime: ast::Lifetime, bounds: &ast::ParamBounds) + -> io::Result<()> { self.print_lifetime(lifetime)?; if !bounds.is_empty() { @@ -2862,7 +2854,7 @@ impl<'a> State<'a> { self.s.word(" + ")?; } match bound { - ast::ParamBound::Outlives(lt) => self.print_lifetime(lt)?, + ast::ParamBound::Outlives(lt) => self.print_lifetime(*lt)?, _ => panic!(), } } @@ -2882,9 +2874,10 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &generic_params, |s, param| { match param.kind { - ast::GenericParamKind::Lifetime { ref lifetime } => { + ast::GenericParamKind::Lifetime => { s.print_outer_attributes_inline(¶m.attrs)?; - s.print_lifetime_bounds(lifetime, ¶m.bounds) + let lt = ast::Lifetime { id: param.id, ident: param.ident }; + s.print_lifetime_bounds(lt, ¶m.bounds) }, ast::GenericParamKind::Type { ref default } => { s.print_outer_attributes_inline(¶m.attrs)?; @@ -2934,7 +2927,7 @@ impl<'a> State<'a> { ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, ref bounds, ..}) => { - self.print_lifetime_bounds(lifetime, bounds)?; + self.print_lifetime_bounds(*lifetime, bounds)?; } ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref lhs_ty, ref rhs_ty, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index a7d8156f4a0..89b50044129 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -665,8 +665,8 @@ impl<'a> TraitDef<'a> { let trait_ref = cx.trait_ref(trait_path); let self_params: Vec<_> = generics.params.iter().map(|param| match param.kind { - GenericParamKind::Lifetime { ref lifetime, .. } => { - GenericArg::Lifetime(*lifetime) + GenericParamKind::Lifetime { .. } => { + GenericArg::Lifetime(ast::Lifetime { id: param.id, ident: param.ident }) } GenericParamKind::Type { .. } => { GenericArg::Type(cx.ty_ident(self.span, param.ident)) diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 327a35d39b3..99b6398160e 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -190,8 +190,8 @@ impl<'a> Ty<'a> { match *self { Self_ => { let params: Vec<_> = generics.params.iter().map(|param| match param.kind { - GenericParamKind::Lifetime { ref lifetime, .. } => { - GenericArg::Lifetime(*lifetime) + GenericParamKind::Lifetime { .. } => { + GenericArg::Lifetime(ast::Lifetime { id: param.id, ident: param.ident }) } GenericParamKind::Type { .. } => { GenericArg::Type(cx.ty_ident(span, param.ident)) -- cgit 1.4.1-3-g733a5 From 8bc3a35576dd4e2f02b9d34fe5ed241288b5bfbe Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 13 Jun 2018 13:29:40 +0100 Subject: Fix HasAttrs support for GenericParam --- src/libsyntax/attr.rs | 15 +++++---------- src/libsyntax/parse/parser.rs | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 2389ed799cf..ded493fe395 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -1446,17 +1446,12 @@ impl HasAttrs for Stmt { impl HasAttrs for GenericParam { fn attrs(&self) -> &[ast::Attribute] { - match self { - GenericParam::Lifetime(lifetime) => lifetime.attrs(), - GenericParam::Type(ty) => ty.attrs(), - } + &self.attrs } - fn map_attrs) -> Vec>(self, f: F) -> Self { - match self { - GenericParam::Lifetime(lifetime) => GenericParam::Lifetime(lifetime.map_attrs(f)), - GenericParam::Type(ty) => GenericParam::Type(ty.map_attrs(f)), - } + fn map_attrs) -> Vec>(mut self, f: F) -> Self { + self.attrs = self.attrs.map_attrs(f); + self } } @@ -1479,5 +1474,5 @@ macro_rules! derive_has_attrs { derive_has_attrs! { Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::ImplItem, ast::TraitItem, ast::Arm, - ast::Field, ast::FieldPat, ast::Variant_, ast::LifetimeDef, ast::TyParam + ast::Field, ast::FieldPat, ast::Variant_ } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b2cfb459c35..f69361c28ad 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4752,7 +4752,7 @@ impl<'a> Parser<'a> { self.span_err(question_span, "`?` may only modify trait bounds, not lifetime bounds"); } - bounds.push(Outlives(RegionTyParamBound(self.expect_lifetime()))); + bounds.push(Outlives(self.expect_lifetime())); if has_parens { self.expect(&token::CloseDelim(token::Paren))?; self.span_err(self.prev_span, -- cgit 1.4.1-3-g733a5 From 7de6ed06a528db8f34ca3e75ded9d77ab9ba8b9a Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 14 Jun 2018 11:25:14 +0100 Subject: Rename TraitTyParamBound to ParamBound::Trait --- src/librustc/hir/intravisit.rs | 4 ++-- src/librustc/hir/lowering.rs | 14 +++++++------- src/librustc/hir/mod.rs | 7 +++---- src/librustc/hir/print.rs | 14 +++++++------- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc_passes/ast_validation.rs | 4 ++-- src/librustc_privacy/lib.rs | 2 +- src/librustc_save_analysis/dump_visitor.rs | 4 ++-- src/librustc_typeck/collect.rs | 26 +++++++++----------------- src/librustdoc/clean/mod.rs | 12 +++++++----- src/libsyntax/ast.rs | 6 +++--- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/fold.rs | 4 ++-- src/libsyntax/parse/parser.rs | 8 ++++---- src/libsyntax/print/pprust.rs | 8 ++++---- src/libsyntax/visit.rs | 2 +- 17 files changed, 57 insertions(+), 64 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 9c154d2e4af..a66650aa161 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -733,10 +733,10 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBound) { match *bound { - TraitTyParamBound(ref typ, modifier) => { + ParamBound::Trait(ref typ, modifier) => { visitor.visit_poly_trait_ref(typ, modifier); } - Outlives(ref lifetime) => visitor.visit_lifetime(lifetime), + ParamBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime), } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 7ef72fd7542..2a231448490 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1108,10 +1108,10 @@ impl<'a> LoweringContext<'a> { let bounds = bounds .iter() .filter_map(|bound| match *bound { - TraitTyParamBound(ref ty, TraitBoundModifier::None) => { + Trait(ref ty, TraitBoundModifier::None) => { Some(self.lower_poly_trait_ref(ty, itctx)) } - TraitTyParamBound(_, TraitBoundModifier::Maybe) => None, + Trait(_, TraitBoundModifier::Maybe) => None, Outlives(ref lifetime) => { if lifetime_bound.is_none() { lifetime_bound = Some(self.lower_lifetime(lifetime)); @@ -1875,12 +1875,12 @@ impl<'a> LoweringContext<'a> { itctx: ImplTraitContext, ) -> hir::ParamBound { match *tpb { - TraitTyParamBound(ref ty, modifier) => hir::TraitTyParamBound( + ParamBound::Trait(ref ty, modifier) => hir::ParamBound::Trait( self.lower_poly_trait_ref(ty, itctx), self.lower_trait_bound_modifier(modifier), ), - Outlives(ref lifetime) => { - hir::Outlives(self.lower_lifetime(lifetime)) + ParamBound::Outlives(ref lifetime) => { + hir::ParamBound::Outlives(self.lower_lifetime(lifetime)) } } } @@ -2010,7 +2010,7 @@ impl<'a> LoweringContext<'a> { for pred in &generics.where_clause.predicates { if let WherePredicate::BoundPredicate(ref bound_pred) = *pred { 'next_bound: for bound in &bound_pred.bounds { - if let TraitTyParamBound(_, TraitBoundModifier::Maybe) = *bound { + if let ParamBound::Trait(_, TraitBoundModifier::Maybe) = *bound { let report_error = |this: &mut Self| { this.diagnostic().span_err( bound_pred.bounded_ty.span, @@ -2095,7 +2095,7 @@ impl<'a> LoweringContext<'a> { .filter_map(|bound| match *bound { // Ignore `?Trait` bounds. // Tthey were copied into type parameters already. - TraitTyParamBound(_, TraitBoundModifier::Maybe) => None, + ParamBound::Trait(_, TraitBoundModifier::Maybe) => None, _ => Some(this.lower_param_bound( bound, ImplTraitContext::Disallowed, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index ab7e8c4e813..974d287cd97 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +22,6 @@ pub use self::Mutability::*; pub use self::PrimTy::*; pub use self::Stmt_::*; pub use self::Ty_::*; -pub use self::ParamBound::*; pub use self::UnOp::*; pub use self::UnsafeSource::*; pub use self::Visibility::{Public, Inherited}; @@ -445,15 +444,15 @@ pub enum TraitBoundModifier { /// detects Copy, Send and Sync. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum ParamBound { - TraitTyParamBound(PolyTraitRef, TraitBoundModifier), + Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime), } impl ParamBound { pub fn span(&self) -> Span { match self { - &TraitTyParamBound(ref t, ..) => t.span, - &Outlives(ref l) => l.span, + &ParamBound::Trait(ref t, ..) => t.span, + &ParamBound::Outlives(ref l) => l.span, } } } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 56a4c2d3cb5..b6fd1362554 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -24,7 +24,7 @@ use syntax::util::parser::{self, AssocOp, Fixity}; use syntax_pos::{self, BytePos, FileName}; use hir; -use hir::{PatKind, Outlives, TraitTyParamBound, TraitBoundModifier, RangeEnd}; +use hir::{PatKind, ParamBound, TraitBoundModifier, RangeEnd}; use hir::{GenericParam, GenericParamKind, GenericArg}; use std::cell::Cell; @@ -740,7 +740,7 @@ impl<'a> State<'a> { self.print_generic_params(&generics.params)?; let mut real_bounds = Vec::with_capacity(bounds.len()); for b in bounds.iter() { - if let TraitTyParamBound(ref ptr, hir::TraitBoundModifier::Maybe) = *b { + if let ParamBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -766,7 +766,7 @@ impl<'a> State<'a> { let mut real_bounds = Vec::with_capacity(bounds.len()); // FIXME(durka) this seems to be some quite outdated syntax for b in bounds.iter() { - if let TraitTyParamBound(ref ptr, hir::TraitBoundModifier::Maybe) = *b { + if let ParamBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -2086,13 +2086,13 @@ impl<'a> State<'a> { } match bound { - TraitTyParamBound(tref, modifier) => { + ParamBound::Trait(tref, modifier) => { if modifier == &TraitBoundModifier::Maybe { self.s.word("?")?; } self.print_poly_trait_ref(tref)?; } - Outlives(lt) => { + ParamBound::Outlives(lt) => { self.print_lifetime(lt)?; } } @@ -2121,7 +2121,7 @@ impl<'a> State<'a> { let mut sep = ":"; for bound in ¶m.bounds { match bound { - hir::ParamBound::Outlives(lt) => { + ParamBound::Outlives(lt) => { self.s.word(sep)?; self.print_lifetime(lt)?; sep = "+"; @@ -2181,7 +2181,7 @@ impl<'a> State<'a> { for (i, bound) in bounds.iter().enumerate() { match bound { - hir::ParamBound::Outlives(lt) => { + ParamBound::Outlives(lt) => { self.print_lifetime(lt)?; } _ => bug!(), diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 51934ad8e6a..ec55a05822c 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -189,7 +189,7 @@ impl_stable_hash_for!(struct hir::GenericArgs { }); impl_stable_hash_for!(enum hir::ParamBound { - TraitTyParamBound(poly_trait_ref, trait_bound_modifier), + Trait(poly_trait_ref, trait_bound_modifier), Outlives(lifetime) }); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 2461a1436bc..14c782308a8 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1256,7 +1256,7 @@ fn object_lifetime_defaults_for_item( ) -> Vec { fn add_bounds(set: &mut Set1, bounds: &[hir::ParamBound]) { for bound in bounds { - if let hir::Outlives(ref lifetime) = *bound { + if let hir::ParamBound::Outlives(ref lifetime) = *bound { set.insert(lifetime.name); } } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 3411c28f35b..bdfe1d50e26 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -101,7 +101,7 @@ impl<'a> AstValidator<'a> { fn no_questions_in_bounds(&self, bounds: &ParamBounds, where_: &str, is_trait: bool) { for bound in bounds { - if let TraitTyParamBound(ref poly, TraitBoundModifier::Maybe) = *bound { + if let Trait(ref poly, TraitBoundModifier::Maybe) = *bound { let mut err = self.err_handler().struct_span_err(poly.span, &format!("`?Trait` is not permitted in {}", where_)); if is_trait { @@ -203,7 +203,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } TyKind::ImplTrait(ref bounds) => { if !bounds.iter() - .any(|b| if let TraitTyParamBound(..) = *b { true } else { false }) { + .any(|b| if let Trait(..) = *b { true } else { false }) { self.err_handler().span_err(ty.span, "at least one trait must be specified"); } } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 2667f68b260..68b5a925ef3 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1039,7 +1039,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn check_ty_param_bound(&mut self, ty_param_bound: &hir::ParamBound) { - if let hir::TraitTyParamBound(ref trait_ref, _) = *ty_param_bound { + if let hir::ParamBound::Trait(ref trait_ref, _) = *ty_param_bound { if self.path_is_private_type(&trait_ref.trait_ref.path) { self.old_error_set.insert(trait_ref.trait_ref.ref_id); } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index cbae6c1ab1a..1373ee94587 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -761,7 +761,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // super-traits for super_bound in trait_refs.iter() { let trait_ref = match *super_bound { - ast::TraitTyParamBound(ref trait_ref, _) => trait_ref, + ast::Trait(ref trait_ref, _) => trait_ref, ast::Outlives(..) => { continue; } @@ -1489,7 +1489,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc ast::GenericParamKind::Lifetime { .. } => {} ast::GenericParamKind::Type { ref default, .. } => { for bound in ¶m.bounds { - if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { + if let ast::Trait(ref trait_ref, _) = *bound { self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index eb18916e781..f578d4f1ae6 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1257,7 +1257,7 @@ fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, // Try to find an unbound in bounds. let mut unbound = None; for ab in ast_bounds { - if let &hir::TraitTyParamBound(ref ptr, hir::TraitBoundModifier::Maybe) = ab { + if let &hir::ParamBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = ab { if unbound.is_none() { unbound = Some(ptr.trait_ref.clone()); } else { @@ -1482,7 +1482,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for bound in bound_pred.bounds.iter() { match bound { - &hir::ParamBound::TraitTyParamBound(ref poly_trait_ref, _) => { + &hir::ParamBound::Trait(ref poly_trait_ref, _) => { let mut projections = Vec::new(); let trait_ref = @@ -1591,22 +1591,16 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, let mut trait_bounds = vec![]; for ast_bound in ast_bounds { match *ast_bound { - hir::TraitTyParamBound(ref b, hir::TraitBoundModifier::None) => { - trait_bounds.push(b); - } - hir::TraitTyParamBound(_, hir::TraitBoundModifier::Maybe) => {} - hir::Outlives(ref l) => { - region_bounds.push(l); - } + hir::ParamBound::Trait(ref b, hir::TraitBoundModifier::None) => trait_bounds.push(b), + hir::ParamBound::Trait(_, hir::TraitBoundModifier::Maybe) => {} + hir::ParamBound::Outlives(ref l) => region_bounds.push(l), } } let mut projection_bounds = vec![]; let mut trait_bounds: Vec<_> = trait_bounds.iter().map(|&bound| { - astconv.instantiate_poly_trait_ref(bound, - param_ty, - &mut projection_bounds) + astconv.instantiate_poly_trait_ref(bound, param_ty, &mut projection_bounds) }).collect(); let region_bounds = region_bounds.into_iter().map(|r| { @@ -1640,7 +1634,7 @@ fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, -> Vec> { match *bound { - hir::TraitTyParamBound(ref tr, hir::TraitBoundModifier::None) => { + hir::ParamBound::Trait(ref tr, hir::TraitBoundModifier::None) => { let mut projections = Vec::new(); let pred = astconv.instantiate_poly_trait_ref(tr, param_ty, @@ -1650,14 +1644,12 @@ fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, .chain(Some(pred.to_predicate())) .collect() } - hir::Outlives(ref lifetime) => { + hir::ParamBound::Outlives(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region)); vec![ty::Predicate::TypeOutlives(pred)] } - hir::TraitTyParamBound(_, hir::TraitBoundModifier::Maybe) => { - Vec::new() - } + hir::ParamBound::Trait(_, hir::TraitBoundModifier::Maybe) => vec![], } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2b02c639b95..7f9500d21f0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1510,8 +1510,8 @@ impl ParamBound { impl Clean for hir::ParamBound { fn clean(&self, cx: &DocContext) -> ParamBound { match *self { - hir::Outlives(lt) => Outlives(lt.clean(cx)), - hir::TraitTyParamBound(ref t, modifier) => TraitBound(t.clean(cx), modifier), + hir::ParamBound::Outlives(lt) => Outlives(lt.clean(cx)), + hir::ParamBound::Trait(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(Outlives)); + .map(ParamBound::Outlives)); v.extend(self.types().map(|t| TraitBound(PolyTrait { trait_: t.clean(cx), generic_params: Vec::new(), @@ -3080,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(Outlives(b))); + reg.clean(cx).map(|b| typarams.push(ParamBound::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(), @@ -3137,7 +3137,9 @@ 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(Outlives(r))); + pred.skip_binder().1.clean(cx).map(|r| { + regions.push(ParamBound::Outlives(r)) + }); return None; } else { return None; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 389afa96ea0..6fe90025ff8 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -283,14 +283,14 @@ pub enum TraitBoundModifier { /// detects Copy, Send and Sync. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum ParamBound { - TraitTyParamBound(PolyTraitRef, TraitBoundModifier), + Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime) } impl ParamBound { pub fn span(&self) -> Span { match self { - &TraitTyParamBound(ref t, ..) => t.span, + &Trait(ref t, ..) => t.span, &Outlives(ref l) => l.ident.span, } } @@ -930,7 +930,7 @@ impl Expr { fn to_bound(&self) -> Option { match &self.node { ExprKind::Path(None, path) => - Some(TraitTyParamBound(PolyTraitRef::new(Vec::new(), path.clone(), self.span), + Some(Trait(PolyTraitRef::new(Vec::new(), path.clone(), self.span), TraitBoundModifier::None)), _ => None, } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index cc0bc7f0c74..28bfb1ff811 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -465,7 +465,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn ty_param_bound(&self, path: ast::Path) -> ast::ParamBound { - ast::TraitTyParamBound(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None) + ast::Trait(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None) } fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 804b1410b07..290607a702b 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -678,8 +678,8 @@ pub fn noop_fold_fn_decl(decl: P, fld: &mut T) -> P { pub fn noop_fold_param_bound(pb: ParamBound, fld: &mut T) -> ParamBound where T: Folder { match pb { - TraitTyParamBound(ty, modifier) => { - TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier) + Trait(ty, modifier) => { + Trait(fld.fold_poly_trait_ref(ty), modifier) } Outlives(lifetime) => Outlives(noop_fold_lifetime(lifetime, fld)), } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f69361c28ad..75eefb84432 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -10,7 +10,7 @@ use rustc_target::spec::abi::{self, Abi}; use ast::{AngleBracketedArgs, ParenthesizedArgData, AttrStyle, BareFnTy}; -use ast::{Outlives, TraitTyParamBound, TraitBoundModifier}; +use ast::{Outlives, Trait, TraitBoundModifier}; use ast::Unsafety; use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use ast::Block; @@ -1444,7 +1444,7 @@ impl<'a> Parser<'a> { TyKind::TraitObject(ref bounds, TraitObjectSyntax::None) if maybe_bounds && bounds.len() == 1 && !trailing_plus => { let path = match bounds[0] { - TraitTyParamBound(ref pt, ..) => pt.trait_ref.path.clone(), + Trait(ref pt, ..) => pt.trait_ref.path.clone(), _ => self.bug("unexpected lifetime bound"), }; self.parse_remaining_bounds(Vec::new(), path, lo, true)? @@ -1566,7 +1566,7 @@ impl<'a> Parser<'a> { fn parse_remaining_bounds(&mut self, generic_params: Vec, path: ast::Path, lo: Span, parse_plus: bool) -> PResult<'a, TyKind> { let poly_trait_ref = PolyTraitRef::new(generic_params, path, lo.to(self.prev_span)); - let mut bounds = vec![TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)]; + let mut bounds = vec![Trait(poly_trait_ref, TraitBoundModifier::None)]; if parse_plus { self.eat_plus(); // `+`, or `+=` gets split and `+` is discarded bounds.append(&mut self.parse_ty_param_bounds()?); @@ -4770,7 +4770,7 @@ impl<'a> Parser<'a> { } else { TraitBoundModifier::None }; - bounds.push(TraitTyParamBound(poly_trait, modifier)); + bounds.push(Trait(poly_trait, modifier)); } } else { break diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5d39367f4b0..38229fa4998 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -12,7 +12,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::{self, Abi}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; -use ast::{SelfKind, Outlives, TraitTyParamBound, TraitBoundModifier}; +use ast::{SelfKind, Outlives, Trait, TraitBoundModifier}; use ast::{Attribute, MacDelimiter, GenericArg}; use util::parser::{self, AssocOp, Fixity}; use attr; @@ -1364,7 +1364,7 @@ impl<'a> State<'a> { self.print_generic_params(&generics.params)?; let mut real_bounds = Vec::with_capacity(bounds.len()); for b in bounds.iter() { - if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = *b { + if let Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -1390,7 +1390,7 @@ impl<'a> State<'a> { let mut real_bounds = Vec::with_capacity(bounds.len()); // FIXME(durka) this seems to be some quite outdated syntax for b in bounds.iter() { - if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = *b { + if let Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -2826,7 +2826,7 @@ impl<'a> State<'a> { } match bound { - TraitTyParamBound(tref, modifier) => { + Trait(tref, modifier) => { if modifier == &TraitBoundModifier::Maybe { self.s.word("?")?; } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index f63b474f450..6beaabd03de 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -481,7 +481,7 @@ pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) { pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a ParamBound) { match *bound { - TraitTyParamBound(ref typ, ref modifier) => { + Trait(ref typ, ref modifier) => { visitor.visit_poly_trait_ref(typ, modifier); } Outlives(ref lifetime) => { -- cgit 1.4.1-3-g733a5 From c5f16e0e180f4f76187e55aecb5913a1cf7fab2a Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 14 Jun 2018 12:08:58 +0100 Subject: Rename ParamBound(s) to GenericBound(s) --- src/librustc/hir/intravisit.rs | 8 +-- src/librustc/hir/lowering.rs | 24 ++++----- src/librustc/hir/mod.rs | 24 ++++----- src/librustc/hir/print.rs | 18 +++---- src/librustc/ich/impls_hir.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 6 +-- src/librustc_passes/ast_validation.rs | 2 +- src/librustc_passes/hir_stats.rs | 8 +-- src/librustc_privacy/lib.rs | 4 +- src/librustc_save_analysis/dump_visitor.rs | 2 +- src/librustc_save_analysis/sig.rs | 6 +-- src/librustc_typeck/collect.rs | 30 +++++------ src/librustdoc/clean/auto_trait.rs | 24 ++++----- src/librustdoc/clean/inline.rs | 4 +- src/librustdoc/clean/mod.rs | 82 +++++++++++++++--------------- src/librustdoc/clean/simplify.rs | 2 +- src/librustdoc/core.rs | 2 +- src/librustdoc/doctree.rs | 2 +- src/librustdoc/html/format.rs | 20 ++++---- src/librustdoc/html/render.rs | 6 +-- src/libsyntax/ast.rs | 26 +++++----- src/libsyntax/ext/build.rs | 12 ++--- src/libsyntax/fold.rs | 16 +++--- src/libsyntax/parse/parser.rs | 12 ++--- src/libsyntax/print/pprust.rs | 10 ++-- src/libsyntax/util/node_count.rs | 2 +- src/libsyntax/visit.rs | 4 +- src/libsyntax_ext/deriving/generic/mod.rs | 2 +- src/libsyntax_ext/deriving/generic/ty.rs | 2 +- 29 files changed, 181 insertions(+), 181 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index a778ea12552..e49a5e4ee6a 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -314,7 +314,7 @@ pub trait Visitor<'v> : Sized { fn visit_trait_ref(&mut self, t: &'v TraitRef) { walk_trait_ref(self, t) } - fn visit_param_bound(&mut self, bounds: &'v ParamBound) { + fn visit_param_bound(&mut self, bounds: &'v GenericBound) { walk_param_bound(self, bounds) } fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: TraitBoundModifier) { @@ -731,12 +731,12 @@ 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_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 GenericBound) { match *bound { - ParamBound::Trait(ref typ, modifier) => { + GenericBound::Trait(ref typ, modifier) => { visitor.visit_poly_trait_ref(typ, modifier); } - ParamBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime), + GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime), } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index aec94d60f94..b725432eb5c 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1285,7 +1285,7 @@ impl<'a> LoweringContext<'a> { &mut self, exist_ty_id: NodeId, parent_index: DefIndex, - bounds: &hir::ParamBounds, + bounds: &hir::GenericBounds, ) -> (HirVec, HirVec) { // This visitor walks over impl trait bounds and creates defs for all lifetimes which // appear in the bounds, excluding lifetimes that are created within the bounds. @@ -1873,16 +1873,16 @@ impl<'a> LoweringContext<'a> { fn lower_param_bound( &mut self, - tpb: &ParamBound, + tpb: &GenericBound, itctx: ImplTraitContext, - ) -> hir::ParamBound { + ) -> hir::GenericBound { match *tpb { - ParamBound::Trait(ref ty, modifier) => hir::ParamBound::Trait( + GenericBound::Trait(ref ty, modifier) => hir::GenericBound::Trait( self.lower_poly_trait_ref(ty, itctx), self.lower_trait_bound_modifier(modifier), ), - ParamBound::Outlives(ref lifetime) => { - hir::ParamBound::Outlives(self.lower_lifetime(lifetime)) + GenericBound::Outlives(ref lifetime) => { + hir::GenericBound::Outlives(self.lower_lifetime(lifetime)) } } } @@ -1925,7 +1925,7 @@ impl<'a> LoweringContext<'a> { fn lower_generic_params( &mut self, params: &Vec, - add_bounds: &NodeMap>, + add_bounds: &NodeMap>, itctx: ImplTraitContext, ) -> hir::HirVec { params.iter().map(|param| self.lower_generic_param(param, add_bounds, itctx)).collect() @@ -1933,7 +1933,7 @@ impl<'a> LoweringContext<'a> { fn lower_generic_param(&mut self, param: &GenericParam, - add_bounds: &NodeMap>, + add_bounds: &NodeMap>, itctx: ImplTraitContext) -> hir::GenericParam { let mut bounds = self.lower_param_bounds(¶m.bounds, itctx); @@ -2013,7 +2013,7 @@ impl<'a> LoweringContext<'a> { for pred in &generics.where_clause.predicates { if let WherePredicate::BoundPredicate(ref bound_pred) = *pred { 'next_bound: for bound in &bound_pred.bounds { - if let ParamBound::Trait(_, TraitBoundModifier::Maybe) = *bound { + if let GenericBound::Trait(_, TraitBoundModifier::Maybe) = *bound { let report_error = |this: &mut Self| { this.diagnostic().span_err( bound_pred.bounded_ty.span, @@ -2098,7 +2098,7 @@ impl<'a> LoweringContext<'a> { .filter_map(|bound| match *bound { // Ignore `?Trait` bounds. // Tthey were copied into type parameters already. - ParamBound::Trait(_, TraitBoundModifier::Maybe) => None, + GenericBound::Trait(_, TraitBoundModifier::Maybe) => None, _ => Some(this.lower_param_bound( bound, ImplTraitContext::Disallowed, @@ -2217,8 +2217,8 @@ impl<'a> LoweringContext<'a> { } } - fn lower_param_bounds(&mut self, bounds: &[ParamBound], itctx: ImplTraitContext) - -> hir::ParamBounds { + fn lower_param_bounds(&mut self, bounds: &[GenericBound], itctx: ImplTraitContext) + -> hir::GenericBounds { bounds.iter().map(|bound| self.lower_param_bound(bound, itctx)).collect() } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 63b4614ef5d..f6876113c11 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -443,21 +443,21 @@ pub enum TraitBoundModifier { /// the "special" built-in traits (see middle::lang_items) and /// detects Copy, Send and Sync. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ParamBound { +pub enum GenericBound { Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime), } -impl ParamBound { +impl GenericBound { pub fn span(&self) -> Span { match self { - &ParamBound::Trait(ref t, ..) => t.span, - &ParamBound::Outlives(ref l) => l.span, + &GenericBound::Trait(ref t, ..) => t.span, + &GenericBound::Outlives(ref l) => l.span, } } } -pub type ParamBounds = HirVec; +pub type GenericBounds = HirVec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum GenericParamKind { @@ -479,7 +479,7 @@ pub struct GenericParam { pub id: NodeId, pub name: ParamName, pub attrs: HirVec, - pub bounds: ParamBounds, + pub bounds: GenericBounds, pub span: Span, pub pure_wrt_drop: bool, @@ -588,7 +588,7 @@ pub struct WhereBoundPredicate { /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: ParamBounds, + pub bounds: GenericBounds, } /// A lifetime predicate, e.g. `'a: 'b+'c` @@ -596,7 +596,7 @@ pub struct WhereBoundPredicate { pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, - pub bounds: ParamBounds, + pub bounds: GenericBounds, } /// An equality predicate (unsupported), e.g. `T=int` @@ -1555,7 +1555,7 @@ pub enum TraitItemKind { Method(MethodSig, TraitMethod), /// An associated type with (possibly empty) bounds and optional concrete /// type - Type(ParamBounds, Option>), + Type(GenericBounds, Option>), } // The bodies for items are stored "out of line", in a separate @@ -1640,7 +1640,7 @@ pub struct BareFnTy { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct ExistTy { pub generics: Generics, - pub bounds: ParamBounds, + pub bounds: GenericBounds, pub impl_trait_fn: Option, } @@ -2049,9 +2049,9 @@ pub enum Item_ { /// A union definition, e.g. `union Foo {x: A, y: B}` ItemUnion(VariantData, Generics), /// Represents a Trait Declaration - ItemTrait(IsAuto, Unsafety, Generics, ParamBounds, HirVec), + ItemTrait(IsAuto, Unsafety, Generics, GenericBounds, HirVec), /// Represents a Trait Alias Declaration - ItemTraitAlias(Generics, ParamBounds), + ItemTraitAlias(Generics, GenericBounds), /// An implementation, eg `impl Trait for Foo { .. }` ItemImpl(Unsafety, diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index b6fd1362554..229a4da465a 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -24,7 +24,7 @@ use syntax::util::parser::{self, AssocOp, Fixity}; use syntax_pos::{self, BytePos, FileName}; use hir; -use hir::{PatKind, ParamBound, TraitBoundModifier, RangeEnd}; +use hir::{PatKind, GenericBound, TraitBoundModifier, RangeEnd}; use hir::{GenericParam, GenericParamKind, GenericArg}; use std::cell::Cell; @@ -514,7 +514,7 @@ impl<'a> State<'a> { fn print_associated_type(&mut self, name: ast::Name, - bounds: Option<&hir::ParamBounds>, + bounds: Option<&hir::GenericBounds>, ty: Option<&hir::Ty>) -> io::Result<()> { self.word_space("type")?; @@ -740,7 +740,7 @@ impl<'a> State<'a> { self.print_generic_params(&generics.params)?; let mut real_bounds = Vec::with_capacity(bounds.len()); for b in bounds.iter() { - if let ParamBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b { + if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -766,7 +766,7 @@ impl<'a> State<'a> { let mut real_bounds = Vec::with_capacity(bounds.len()); // FIXME(durka) this seems to be some quite outdated syntax for b in bounds.iter() { - if let ParamBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b { + if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -2071,7 +2071,7 @@ impl<'a> State<'a> { } } - pub fn print_bounds(&mut self, prefix: &str, bounds: &[hir::ParamBound]) -> io::Result<()> { + pub fn print_bounds(&mut self, prefix: &str, bounds: &[hir::GenericBound]) -> io::Result<()> { if !bounds.is_empty() { self.s.word(prefix)?; let mut first = true; @@ -2086,13 +2086,13 @@ impl<'a> State<'a> { } match bound { - ParamBound::Trait(tref, modifier) => { + GenericBound::Trait(tref, modifier) => { if modifier == &TraitBoundModifier::Maybe { self.s.word("?")?; } self.print_poly_trait_ref(tref)?; } - ParamBound::Outlives(lt) => { + GenericBound::Outlives(lt) => { self.print_lifetime(lt)?; } } @@ -2121,7 +2121,7 @@ impl<'a> State<'a> { let mut sep = ":"; for bound in ¶m.bounds { match bound { - ParamBound::Outlives(lt) => { + GenericBound::Outlives(lt) => { self.s.word(sep)?; self.print_lifetime(lt)?; sep = "+"; @@ -2181,7 +2181,7 @@ impl<'a> State<'a> { for (i, bound) in bounds.iter().enumerate() { match bound { - ParamBound::Outlives(lt) => { + GenericBound::Outlives(lt) => { self.print_lifetime(lt)?; } _ => bug!(), diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index fbe2fdae877..882194ae64e 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -188,7 +188,7 @@ impl_stable_hash_for!(struct hir::GenericArgs { parenthesized }); -impl_stable_hash_for!(enum hir::ParamBound { +impl_stable_hash_for!(enum hir::GenericBound { Trait(poly_trait_ref, trait_bound_modifier), Outlives(lifetime) }); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 178b9b1f45a..091662966ea 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1250,9 +1250,9 @@ fn object_lifetime_defaults_for_item( tcx: TyCtxt<'_, '_, '_>, generics: &hir::Generics, ) -> Vec { - fn add_bounds(set: &mut Set1, bounds: &[hir::ParamBound]) { + fn add_bounds(set: &mut Set1, bounds: &[hir::GenericBound]) { for bound in bounds { - if let hir::ParamBound::Outlives(ref lifetime) = *bound { + if let hir::GenericBound::Outlives(ref lifetime) = *bound { set.insert(lifetime.name); } } @@ -2280,7 +2280,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { for bound in &lifetime_i.bounds { match bound { - hir::ParamBound::Outlives(lt) => match lt.name { + hir::GenericBound::Outlives(lt) => match lt.name { hir::LifetimeName::Underscore => { let mut err = struct_span_err!( self.tcx.sess, diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index bdfe1d50e26..4f04ad89698 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -99,7 +99,7 @@ impl<'a> AstValidator<'a> { } } - fn no_questions_in_bounds(&self, bounds: &ParamBounds, where_: &str, is_trait: bool) { + fn no_questions_in_bounds(&self, bounds: &GenericBounds, where_: &str, is_trait: bool) { for bound in bounds { if let Trait(ref poly, TraitBoundModifier::Maybe) = *bound { let mut err = self.err_handler().struct_span_err(poly.span, diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 879adebf7ea..e7b2869dfe6 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -203,8 +203,8 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_impl_item(self, ii) } - fn visit_param_bound(&mut self, bounds: &'v hir::ParamBound) { - self.record("ParamBound", Id::None, bounds); + fn visit_param_bound(&mut self, bounds: &'v hir::GenericBound) { + self.record("GenericBound", Id::None, bounds); hir_visit::walk_param_bound(self, bounds) } @@ -322,8 +322,8 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { ast_visit::walk_impl_item(self, ii) } - fn visit_param_bound(&mut self, bounds: &'v ast::ParamBound) { - self.record("ParamBound", Id::None, bounds); + fn visit_param_bound(&mut self, bounds: &'v ast::GenericBound) { + self.record("GenericBound", Id::None, bounds); ast_visit::walk_param_bound(self, bounds) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 68b5a925ef3..809f5a06952 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1038,8 +1038,8 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn check_ty_param_bound(&mut self, - ty_param_bound: &hir::ParamBound) { - if let hir::ParamBound::Trait(ref trait_ref, _) = *ty_param_bound { + ty_param_bound: &hir::GenericBound) { + if let hir::GenericBound::Trait(ref trait_ref, _) = *ty_param_bound { if self.path_is_private_type(&trait_ref.trait_ref.path) { self.old_error_set.insert(trait_ref.trait_ref.ref_id); } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 1373ee94587..0f0f3f6e789 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -718,7 +718,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { &mut self, item: &'l ast::Item, generics: &'l ast::Generics, - trait_refs: &'l ast::ParamBounds, + trait_refs: &'l ast::GenericBounds, methods: &'l [ast::TraitItem], ) { let name = item.ident.to_string(); diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 58e2e9b2258..7f2f0b0c837 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -104,7 +104,7 @@ pub fn assoc_const_signature( pub fn assoc_type_signature( id: NodeId, ident: ast::Ident, - bounds: Option<&ast::ParamBounds>, + bounds: Option<&ast::GenericBounds>, default: Option<&ast::Ty>, scx: &SaveContext, ) -> Option { @@ -629,7 +629,7 @@ impl Sig for ast::Generics { ast::GenericParamKind::Lifetime { .. } => { let bounds = param.bounds.iter() .map(|bound| match bound { - ast::ParamBound::Outlives(lt) => lt.ident.to_string(), + ast::GenericBound::Outlives(lt) => lt.ident.to_string(), _ => panic!(), }) .collect::>() @@ -841,7 +841,7 @@ fn name_and_generics( fn make_assoc_type_signature( id: NodeId, ident: ast::Ident, - bounds: Option<&ast::ParamBounds>, + bounds: Option<&ast::GenericBounds>, default: Option<&ast::Ty>, scx: &SaveContext, ) -> Result { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 6e154819c4c..7a4fbc73c2e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1249,7 +1249,7 @@ fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Is it marked with ?Sized fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, - ast_bounds: &[hir::ParamBound], + ast_bounds: &[hir::GenericBound], span: Span) -> bool { let tcx = astconv.tcx(); @@ -1257,7 +1257,7 @@ fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, // Try to find an unbound in bounds. let mut unbound = None; for ab in ast_bounds { - if let &hir::ParamBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = ab { + if let &hir::GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = ab { if unbound.is_none() { unbound = Some(ptr.trait_ref.clone()); } else { @@ -1444,7 +1444,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, match param.kind { GenericParamKind::Lifetime { .. } => { param.bounds.iter().for_each(|bound| match bound { - hir::ParamBound::Outlives(lt) => { + hir::GenericBound::Outlives(lt) => { let bound = AstConv::ast_region_to_region(&icx, <, None); let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound)); predicates.push(outlives.to_predicate()); @@ -1482,7 +1482,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for bound in bound_pred.bounds.iter() { match bound { - &hir::ParamBound::Trait(ref poly_trait_ref, _) => { + &hir::GenericBound::Trait(ref poly_trait_ref, _) => { let mut projections = Vec::new(); let trait_ref = @@ -1498,7 +1498,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - &hir::ParamBound::Outlives(ref lifetime) => { + &hir::GenericBound::Outlives(ref lifetime) => { let region = AstConv::ast_region_to_region(&icx, lifetime, None); @@ -1513,7 +1513,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let r1 = AstConv::ast_region_to_region(&icx, ®ion_pred.lifetime, None); for bound in ®ion_pred.bounds { let r2 = match bound { - hir::ParamBound::Outlives(lt) => { + hir::GenericBound::Outlives(lt) => { AstConv::ast_region_to_region(&icx, lt, None) } _ => bug!(), @@ -1582,7 +1582,7 @@ pub enum SizedByDefault { Yes, No, } /// built-in trait (formerly known as kind): Send. pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, param_ty: Ty<'tcx>, - ast_bounds: &[hir::ParamBound], + ast_bounds: &[hir::GenericBound], sized_by_default: SizedByDefault, span: Span) -> Bounds<'tcx> @@ -1591,9 +1591,9 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, let mut trait_bounds = vec![]; for ast_bound in ast_bounds { match *ast_bound { - hir::ParamBound::Trait(ref b, hir::TraitBoundModifier::None) => trait_bounds.push(b), - hir::ParamBound::Trait(_, hir::TraitBoundModifier::Maybe) => {} - hir::ParamBound::Outlives(ref l) => region_bounds.push(l), + hir::GenericBound::Trait(ref b, hir::TraitBoundModifier::None) => trait_bounds.push(b), + hir::GenericBound::Trait(_, hir::TraitBoundModifier::Maybe) => {} + hir::GenericBound::Outlives(ref l) => region_bounds.push(l), } } @@ -1623,18 +1623,18 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>, } } -/// Converts a specific ParamBound from the AST into a set of +/// Converts a specific GenericBound from the AST into a set of /// predicates that apply to the self-type. A vector is returned /// because this can be anywhere from 0 predicates (`T:?Sized` adds no /// predicates) to 1 (`T:Foo`) to many (`T:Bar` adds `T:Bar` /// and `::X == i32`). fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, param_ty: Ty<'tcx>, - bound: &hir::ParamBound) + bound: &hir::GenericBound) -> Vec> { match *bound { - hir::ParamBound::Trait(ref tr, hir::TraitBoundModifier::None) => { + hir::GenericBound::Trait(ref tr, hir::TraitBoundModifier::None) => { let mut projections = Vec::new(); let pred = astconv.instantiate_poly_trait_ref(tr, param_ty, @@ -1644,12 +1644,12 @@ fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx, 'tcx>, .chain(Some(pred.to_predicate())) .collect() } - hir::ParamBound::Outlives(ref lifetime) => { + hir::GenericBound::Outlives(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region)); vec![ty::Predicate::TypeOutlives(pred)] } - hir::ParamBound::Trait(_, hir::TraitBoundModifier::Maybe) => vec![], + hir::GenericBound::Trait(_, hir::TraitBoundModifier::Maybe) => vec![], } } diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 0874e921f41..5c09da90491 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -486,8 +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| ParamBound::Outlives(self.get_lifetime(region, names_map))) + let bounds: FxHashSet = finished.get(name).unwrap_or(&empty).iter() + .map(|region| GenericBound::Outlives(self.get_lifetime(region, names_map))) .collect(); if bounds.is_empty() { @@ -533,9 +533,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { fn make_final_bounds<'b, 'c, 'cx>( &self, - ty_to_bounds: FxHashMap>, + ty_to_bounds: FxHashMap>, ty_to_fn: FxHashMap, Option)>, - lifetime_to_bounds: FxHashMap>, + lifetime_to_bounds: FxHashMap>, ) -> Vec { ty_to_bounds .into_iter() @@ -586,7 +586,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { } _ => panic!("Unexpected data: {:?}, {:?}", ty, data), }; - bounds.insert(ParamBound::TraitBound( + bounds.insert(GenericBound::TraitBound( PolyTrait { trait_: new_ty, generic_params: poly_trait.generic_params, @@ -729,7 +729,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // later let is_fn = match &mut b { - &mut ParamBound::TraitBound(ref mut p, _) => { + &mut GenericBound::TraitBound(ref mut p, _) => { // Insert regions into the for_generics hash map first, to ensure // that we don't end up with duplicate bounds (e.g. for<'b, 'b>) for_generics.extend(p.generic_params.clone()); @@ -823,7 +823,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { .entry(*ty.clone()) .or_insert_with(|| FxHashSet()); - bounds.insert(ParamBound::TraitBound( + bounds.insert(GenericBound::TraitBound( PolyTrait { trait_: Type::ResolvedPath { path: new_trait_path, @@ -840,7 +840,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // that we don't see a // duplicate bound like `T: Iterator + Iterator` // on the docs page. - bounds.remove(&ParamBound::TraitBound( + bounds.remove(&GenericBound::TraitBound( PolyTrait { trait_: *trait_.clone(), generic_params: Vec::new(), @@ -874,7 +874,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { default.take(); let generic_ty = Type::Generic(param.name.clone()); if !has_sized.contains(&generic_ty) { - bounds.insert(0, ParamBound::maybe_sized(self.cx)); + bounds.insert(0, GenericBound::maybe_sized(self.cx)); } } GenericParamDefKind::Lifetime => {} @@ -908,7 +908,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // both for visual consistency between 'rustdoc' runs, and to // make writing tests much easier #[inline] - fn sort_where_bounds(&self, mut bounds: &mut Vec) { + fn sort_where_bounds(&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. @@ -928,7 +928,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // to end users, it makes writing tests much more difficult, as predicates // can appear in any order in the final result. // - // To solve this problem, we sort WherePredicates and ParamBounds + // To solve this problem, we sort WherePredicates and GenericBounds // by their Debug string. The thing to keep in mind is that we don't really // care what the final order is - we're synthesizing an impl or bound // ourselves, so any order can be considered equally valid. By sorting the @@ -938,7 +938,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // Using the Debug impementation for sorting prevents us from needing to // write quite a bit of almost entirely useless code (e.g. how should two // Types be sorted relative to each other). It also allows us to solve the - // problem for both WherePredicates and ParamBounds at the same time. This + // problem for both WherePredicates and GenericBounds at the same time. This // approach is probably somewhat slower, but the small number of items // involved (impls rarely have more than a few bounds) means that it // shouldn't matter in practice. diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index c85178961c1..f3a833bad8f 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -474,7 +474,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean: } if *s == "Self" => { bounds.retain(|bound| { match *bound { - clean::ParamBound::TraitBound(clean::PolyTrait { + clean::GenericBound::TraitBound(clean::PolyTrait { trait_: clean::ResolvedPath { did, .. }, .. }, _) => did != trait_did, @@ -505,7 +505,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean: /// the metadata for a crate, so we want to separate those out and create a new /// list of explicit supertrait bounds to render nicely. fn separate_supertrait_bounds(mut g: clean::Generics) - -> (clean::Generics, Vec) { + -> (clean::Generics, Vec) { let mut ty_bounds = Vec::new(); g.where_predicates.retain(|pred| { match *pred { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7f9500d21f0..031a948fe80 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -14,7 +14,7 @@ pub use self::Type::*; pub use self::Mutability::*; pub use self::ItemEnum::*; -pub use self::ParamBound::*; +pub use self::GenericBound::*; pub use self::SelfTy::*; pub use self::FunctionRetTy::*; pub use self::Visibility::{Public, Inherited}; @@ -532,7 +532,7 @@ pub enum ItemEnum { MacroItem(Macro), PrimitiveItem(PrimitiveType), AssociatedConstItem(Type, Option), - AssociatedTypeItem(Vec, Option), + AssociatedTypeItem(Vec, Option), /// An item that has been stripped by a rustdoc pass StrippedItem(Box), KeywordItem(String), @@ -1458,13 +1458,13 @@ impl Clean for [ast::Attribute] { } #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] -pub enum ParamBound { +pub enum GenericBound { TraitBound(PolyTrait, hir::TraitBoundModifier), Outlives(Lifetime), } -impl ParamBound { - fn maybe_sized(cx: &DocContext) -> ParamBound { +impl GenericBound { + fn maybe_sized(cx: &DocContext) -> GenericBound { let did = cx.tcx.require_lang_item(lang_items::SizedTraitLangItem); let empty = cx.tcx.intern_substs(&[]); let path = external_path(cx, &cx.tcx.item_name(did).as_str(), @@ -1483,7 +1483,7 @@ impl ParamBound { fn is_sized_bound(&self, cx: &DocContext) -> bool { use rustc::hir::TraitBoundModifier as TBM; - if let ParamBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self { + if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self { if trait_.def_id() == cx.tcx.lang_items().sized_trait() { return true; } @@ -1492,7 +1492,7 @@ impl ParamBound { } fn get_poly_trait(&self) -> Option { - if let ParamBound::TraitBound(ref p, _) = *self { + if let GenericBound::TraitBound(ref p, _) = *self { return Some(p.clone()) } None @@ -1500,18 +1500,18 @@ impl ParamBound { fn get_trait_type(&self) -> Option { - if let ParamBound::TraitBound(PolyTrait { ref trait_, .. }, _) = *self { + if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, _) = *self { return Some(trait_.clone()); } None } } -impl Clean for hir::ParamBound { - fn clean(&self, cx: &DocContext) -> ParamBound { +impl Clean for hir::GenericBound { + fn clean(&self, cx: &DocContext) -> GenericBound { match *self { - hir::ParamBound::Outlives(lt) => Outlives(lt.clean(cx)), - hir::ParamBound::Trait(ref t, modifier) => TraitBound(t.clean(cx), modifier), + hir::GenericBound::Outlives(lt) => Outlives(lt.clean(cx)), + hir::GenericBound::Trait(ref t, modifier) => TraitBound(t.clean(cx), modifier), } } } @@ -1570,8 +1570,8 @@ fn external_path(cx: &DocContext, name: &str, trait_did: Option, has_self } } -impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec) { - fn clean(&self, cx: &DocContext) -> ParamBound { +impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec) { + fn clean(&self, cx: &DocContext) -> GenericBound { let (trait_ref, ref bounds) = *self; inline::record_extern_fqn(cx, trait_ref.def_id, TypeKind::Trait); let path = external_path(cx, &cx.tcx.item_name(trait_ref.def_id).as_str(), @@ -1614,17 +1614,17 @@ impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec) } } -impl<'tcx> Clean for ty::TraitRef<'tcx> { - fn clean(&self, cx: &DocContext) -> ParamBound { +impl<'tcx> Clean for ty::TraitRef<'tcx> { + fn clean(&self, cx: &DocContext) -> GenericBound { (self, vec![]).clean(cx) } } -impl<'tcx> Clean>> for Substs<'tcx> { - fn clean(&self, cx: &DocContext) -> Option> { +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(ParamBound::Outlives)); + .map(GenericBound::Outlives)); v.extend(self.types().map(|t| TraitBound(PolyTrait { trait_: t.clean(cx), generic_params: Vec::new(), @@ -1674,7 +1674,7 @@ impl Clean for hir::GenericParam { hir::GenericParamKind::Lifetime { .. } => { if self.bounds.len() > 0 { let mut bounds = self.bounds.iter().map(|bound| match bound { - hir::ParamBound::Outlives(lt) => lt, + hir::GenericBound::Outlives(lt) => lt, _ => panic!(), }); let name = bounds.next().unwrap().name.name(); @@ -1720,8 +1720,8 @@ 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 }, + BoundPredicate { ty: Type, 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![ParamBound::Outlives(b.clean(cx).unwrap())] + bounds: vec![GenericBound::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::Outlives(lt.clean(cx).unwrap())] + bounds: vec![GenericBound::Outlives(lt.clean(cx).unwrap())] } } } @@ -1819,8 +1819,8 @@ impl<'tcx> Clean for ty::ProjectionPredicate<'tcx> { 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::Outlives(_) => panic!("cleaning a trait got a lifetime"), + GenericBound::TraitBound(t, _) => t.trait_, + GenericBound::Outlives(_) => panic!("cleaning a trait got a lifetime"), }; Type::QPath { name: cx.tcx.associated_item(self.item_def_id).name.clean(cx), @@ -1835,7 +1835,7 @@ pub enum GenericParamDefKind { Lifetime, Type { did: DefId, - bounds: Vec, + bounds: Vec, default: Option, synthetic: Option, }, @@ -1893,7 +1893,7 @@ impl Clean for hir::GenericParam { hir::GenericParamKind::Lifetime { .. } => { let name = if self.bounds.len() > 0 { let mut bounds = self.bounds.iter().map(|bound| match bound { - hir::ParamBound::Outlives(lt) => lt, + hir::GenericBound::Outlives(lt) => lt, _ => panic!(), }); let name = bounds.next().unwrap().name.name(); @@ -2049,7 +2049,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, if !sized_params.contains(&tp.name) { where_predicates.push(WP::BoundPredicate { ty: Type::Generic(tp.name.clone()), - bounds: vec![ParamBound::maybe_sized(cx)], + bounds: vec![GenericBound::maybe_sized(cx)], }) } } @@ -2290,7 +2290,7 @@ pub struct Trait { pub unsafety: hir::Unsafety, pub items: Vec, pub generics: Generics, - pub bounds: Vec, + pub bounds: Vec, pub is_spotlight: bool, pub is_auto: bool, } @@ -2512,7 +2512,7 @@ impl<'tcx> Clean for ty::AssociatedItem { // at the end. match bounds.iter().position(|b| b.is_sized_bound(cx)) { Some(i) => { bounds.remove(i); } - None => bounds.push(ParamBound::maybe_sized(cx)), + None => bounds.push(GenericBound::maybe_sized(cx)), } let ty = if self.defaultness.has_value() { @@ -2567,7 +2567,7 @@ pub enum Type { /// structs/enums/traits (most that'd be an hir::TyPath) ResolvedPath { path: Path, - typarams: Option>, + typarams: Option>, did: DefId, /// true if is a `T::Name` path for associated types is_generic: bool, @@ -2603,7 +2603,7 @@ pub enum Type { Infer, // impl TraitA+TraitB - ImplTrait(Vec), + ImplTrait(Vec), } #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Copy, Debug)] @@ -2977,7 +2977,7 @@ 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() { @@ -3080,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(ParamBound::Outlives(b))); + reg.clean(cx).map(|b| typarams.push(GenericBound::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(), @@ -3138,7 +3138,7 @@ impl<'tcx> Clean for Ty<'tcx> { } 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(ParamBound::Outlives(r)) + regions.push(GenericBound::Outlives(r)) }); return None; } else { @@ -3173,7 +3173,7 @@ impl<'tcx> Clean for Ty<'tcx> { }).collect::>(); bounds.extend(regions); if !has_sized && !bounds.is_empty() { - bounds.insert(0, ParamBound::maybe_sized(cx)); + bounds.insert(0, GenericBound::maybe_sized(cx)); } ImplTrait(bounds) } @@ -4469,11 +4469,11 @@ impl AutoTraitResult { } } -impl From for SimpleBound { - fn from(bound: ParamBound) -> Self { +impl From for SimpleBound { + fn from(bound: GenericBound) -> Self { match bound.clone() { - ParamBound::Outlives(l) => SimpleBound::Outlives(l), - ParamBound::TraitBound(t, mod_) => match t.trait_ { + GenericBound::Outlives(l) => SimpleBound::Outlives(l), + GenericBound::TraitBound(t, mod_) => match t.trait_ { Type::ResolvedPath { path, typarams, .. } => { SimpleBound::TraitBound(path.segments, typarams diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index c7477645d6a..a54eb64443b 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -147,7 +147,7 @@ pub fn ty_params(mut params: Vec) -> Vec) -> Vec { +fn ty_bounds(bounds: Vec) -> Vec { bounds } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 7147e13805f..53ebb3a12f5 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -77,7 +77,7 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> { /// Table node id of lifetime parameter definition -> substituted lifetime pub lt_substs: RefCell>, /// Table DefId of `impl Trait` in argument position -> bounds - pub impl_trait_bounds: RefCell>>, + pub impl_trait_bounds: RefCell>>, pub send_trait: Option, pub fake_def_ids: RefCell>, pub all_fake_def_ids: RefCell>, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 542d753c4f0..16d14bc56d6 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -201,7 +201,7 @@ pub struct Trait { pub name: Name, pub items: hir::HirVec, pub generics: hir::Generics, - pub bounds: hir::HirVec, + pub bounds: hir::HirVec, pub attrs: hir::HirVec, pub id: ast::NodeId, pub whence: Span, diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index bd9194a8669..987821d2e30 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -46,7 +46,7 @@ pub struct MutableSpace(pub clean::Mutability); #[derive(Copy, Clone)] pub struct RawMutableSpace(pub clean::Mutability); /// Wrapper struct for emitting type parameter bounds. -pub struct ParamBounds<'a>(pub &'a [clean::ParamBound]); +pub struct GenericBounds<'a>(pub &'a [clean::GenericBound]); /// Wrapper struct for emitting a comma-separated list of items pub struct CommaSep<'a, T: 'a>(pub &'a [T]); pub struct AbiSpace(pub Abi); @@ -104,9 +104,9 @@ impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> { } } -impl<'a> fmt::Display for ParamBounds<'a> { +impl<'a> fmt::Display for GenericBounds<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let &ParamBounds(bounds) = self; + let &GenericBounds(bounds) = self; for (i, bound) in bounds.iter().enumerate() { if i > 0 { f.write_str(" + ")?; @@ -126,9 +126,9 @@ impl fmt::Display for clean::GenericParamDef { if !bounds.is_empty() { if f.alternate() { - write!(f, ": {:#}", ParamBounds(bounds))?; + write!(f, ": {:#}", GenericBounds(bounds))?; } else { - write!(f, ": {}", ParamBounds(bounds))?; + write!(f, ": {}", GenericBounds(bounds))?; } } @@ -190,9 +190,9 @@ impl<'a> fmt::Display for WhereClause<'a> { &clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => { let bounds = bounds; if f.alternate() { - clause.push_str(&format!("{:#}: {:#}", ty, ParamBounds(bounds))); + clause.push_str(&format!("{:#}: {:#}", ty, GenericBounds(bounds))); } else { - clause.push_str(&format!("{}: {}", ty, ParamBounds(bounds))); + clause.push_str(&format!("{}: {}", ty, GenericBounds(bounds))); } } &clean::WherePredicate::RegionPredicate { ref lifetime, @@ -267,7 +267,7 @@ impl fmt::Display for clean::PolyTrait { } } -impl fmt::Display for clean::ParamBound { +impl fmt::Display for clean::GenericBound { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { clean::Outlives(ref lt) => { @@ -512,7 +512,7 @@ fn primitive_link(f: &mut fmt::Formatter, /// Helper to render type parameters fn tybounds(w: &mut fmt::Formatter, - typarams: &Option>) -> fmt::Result { + typarams: &Option>) -> fmt::Result { match *typarams { Some(ref params) => { for param in params { @@ -667,7 +667,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: } } clean::ImplTrait(ref bounds) => { - write!(f, "impl {}", ParamBounds(bounds)) + write!(f, "impl {}", GenericBounds(bounds)) } clean::QPath { ref name, ref self_type, ref trait_ } => { let should_show_cast = match *trait_ { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 21724c2d730..180591b3532 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -69,7 +69,7 @@ use doctree; use fold::DocFolder; use html::escape::Escape; use html::format::{ConstnessSpace}; -use html::format::{ParamBounds, WhereClause, href, AbiSpace}; +use html::format::{GenericBounds, WhereClause, href, AbiSpace}; use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace}; use html::format::fmt_impl_for_trait_page; use html::item_type::ItemType; @@ -2960,14 +2960,14 @@ fn assoc_const(w: &mut fmt::Formatter, } fn assoc_type(w: &mut W, it: &clean::Item, - bounds: &Vec, + bounds: &Vec, default: Option<&clean::Type>, link: AssocItemLink) -> fmt::Result { write!(w, "type {}", naive_assoc_href(it, link), it.name.as_ref().unwrap())?; if !bounds.is_empty() { - write!(w, ": {}", ParamBounds(bounds))? + write!(w, ": {}", GenericBounds(bounds))? } if let Some(default) = default { write!(w, " = {}", default)?; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6fe90025ff8..9dc13fab2d6 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,7 @@ // The Rust abstract syntax tree. -pub use self::ParamBound::*; +pub use self::GenericBound::*; pub use self::UnsafeSource::*; pub use self::GenericArgs::*; pub use symbol::{Ident, Symbol as Name}; @@ -282,12 +282,12 @@ pub enum TraitBoundModifier { /// the "special" built-in traits (see middle::lang_items) and /// detects Copy, Send and Sync. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ParamBound { +pub enum GenericBound { Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime) } -impl ParamBound { +impl GenericBound { pub fn span(&self) -> Span { match self { &Trait(ref t, ..) => t.span, @@ -296,7 +296,7 @@ impl ParamBound { } } -pub type ParamBounds = Vec; +pub type GenericBounds = Vec; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum GenericParamKind { @@ -312,7 +312,7 @@ pub struct GenericParam { pub id: NodeId, pub ident: Ident, pub attrs: ThinVec, - pub bounds: ParamBounds, + pub bounds: GenericBounds, pub kind: GenericParamKind, } @@ -381,7 +381,7 @@ pub struct WhereBoundPredicate { /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: ParamBounds, + pub bounds: GenericBounds, } /// A lifetime predicate. @@ -391,7 +391,7 @@ pub struct WhereBoundPredicate { pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, - pub bounds: ParamBounds, + pub bounds: GenericBounds, } /// An equality predicate (unsupported). @@ -927,7 +927,7 @@ impl Expr { } } - fn to_bound(&self) -> Option { + fn to_bound(&self) -> Option { match &self.node { ExprKind::Path(None, path) => Some(Trait(PolyTraitRef::new(Vec::new(), path.clone(), self.span), @@ -1352,7 +1352,7 @@ pub struct TraitItem { pub enum TraitItemKind { Const(P, Option>), Method(MethodSig, Option>), - Type(ParamBounds, Option>), + Type(GenericBounds, Option>), Macro(Mac), } @@ -1537,10 +1537,10 @@ pub enum TyKind { Path(Option, Path), /// A trait object type `Bound1 + Bound2 + Bound3` /// where `Bound` is a trait or a lifetime. - TraitObject(ParamBounds, TraitObjectSyntax), + TraitObject(GenericBounds, TraitObjectSyntax), /// An `impl Bound1 + Bound2 + Bound3` type /// where `Bound` is a trait or a lifetime. - ImplTrait(ParamBounds), + ImplTrait(GenericBounds), /// No-op; kept solely so that we can pretty-print faithfully Paren(P), /// Unused for now @@ -2061,11 +2061,11 @@ pub enum ItemKind { /// A Trait declaration (`trait` or `pub trait`). /// /// E.g. `trait Foo { .. }`, `trait Foo { .. }` or `auto trait Foo {}` - Trait(IsAuto, Unsafety, Generics, ParamBounds, Vec), + Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec), /// Trait alias /// /// E.g. `trait Foo = Bar + Quux;` - TraitAlias(Generics, ParamBounds), + TraitAlias(Generics, GenericBounds), /// An implementation. /// /// E.g. `impl Foo { .. }` or `impl Trait for Foo { .. }` diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 28bfb1ff811..9de6e14fbeb 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -68,18 +68,18 @@ pub trait AstBuilder { span: Span, id: ast::Ident, attrs: Vec, - bounds: ast::ParamBounds, + bounds: ast::GenericBounds, default: Option>) -> ast::GenericParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; fn poly_trait_ref(&self, span: Span, path: ast::Path) -> ast::PolyTraitRef; - fn ty_param_bound(&self, path: ast::Path) -> ast::ParamBound; + fn ty_param_bound(&self, path: ast::Path) -> ast::GenericBound; fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime; fn lifetime_def(&self, span: Span, ident: ast::Ident, attrs: Vec, - bounds: ast::ParamBounds) + bounds: ast::GenericBounds) -> ast::GenericParam; // statements @@ -436,7 +436,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, ident: ast::Ident, attrs: Vec, - bounds: ast::ParamBounds, + bounds: ast::GenericBounds, default: Option>) -> ast::GenericParam { ast::GenericParam { ident: ident.with_span_pos(span), @@ -464,7 +464,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } } - fn ty_param_bound(&self, path: ast::Path) -> ast::ParamBound { + fn ty_param_bound(&self, path: ast::Path) -> ast::GenericBound { ast::Trait(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None) } @@ -476,7 +476,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, ident: ast::Ident, attrs: Vec, - bounds: ast::ParamBounds) + bounds: ast::GenericBounds) -> ast::GenericParam { let lifetime = self.lifetime(span, ident); ast::GenericParam { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 290607a702b..5db5d0781ea 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -268,15 +268,15 @@ pub trait Folder : Sized { noop_fold_interpolated(nt, self) } - fn fold_opt_bounds(&mut self, b: Option) -> Option { + fn fold_opt_bounds(&mut self, b: Option) -> Option { noop_fold_opt_bounds(b, self) } - fn fold_bounds(&mut self, b: ParamBounds) -> ParamBounds { + fn fold_bounds(&mut self, b: GenericBounds) -> GenericBounds { noop_fold_bounds(b, self) } - fn fold_param_bound(&mut self, tpb: ParamBound) -> ParamBound { + fn fold_param_bound(&mut self, tpb: GenericBound) -> GenericBound { noop_fold_param_bound(tpb, self) } @@ -676,7 +676,7 @@ pub fn noop_fold_fn_decl(decl: P, fld: &mut T) -> P { }) } -pub fn noop_fold_param_bound(pb: ParamBound, fld: &mut T) -> ParamBound where T: Folder { +pub fn noop_fold_param_bound(pb: GenericBound, fld: &mut T) -> GenericBound where T: Folder { match pb { Trait(ty, modifier) => { Trait(fld.fold_poly_trait_ref(ty), modifier) @@ -847,13 +847,13 @@ pub fn noop_fold_mt(MutTy {ty, mutbl}: MutTy, folder: &mut T) -> MutT } } -pub fn noop_fold_opt_bounds(b: Option, folder: &mut T) - -> Option { +pub fn noop_fold_opt_bounds(b: Option, folder: &mut T) + -> Option { b.map(|bounds| folder.fold_bounds(bounds)) } -fn noop_fold_bounds(bounds: ParamBounds, folder: &mut T) - -> ParamBounds { +fn noop_fold_bounds(bounds: GenericBounds, folder: &mut T) + -> GenericBounds { bounds.move_map(|bound| folder.fold_param_bound(bound)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 75eefb84432..8588f4c492f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -36,7 +36,7 @@ use ast::{VariantData, StructField}; use ast::StrStyle; use ast::SelfKind; use ast::{TraitItem, TraitRef, TraitObjectSyntax}; -use ast::{Ty, TyKind, TypeBinding, ParamBounds}; +use ast::{Ty, TyKind, TypeBinding, GenericBounds}; use ast::{Visibility, VisibilityKind, WhereClause, CrateSugar}; use ast::{UseTree, UseTreeKind}; use ast::{BinOpKind, UnOp}; @@ -4735,7 +4735,7 @@ impl<'a> Parser<'a> { // LT_BOUND = LIFETIME (e.g. `'a`) // TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) // TY_BOUND_NOPAREN = [?] [for] SIMPLE_PATH (e.g. `?for<'a: 'b> m::Trait<'a>`) - fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, ParamBounds> { + fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, GenericBounds> { let mut bounds = Vec::new(); loop { // This needs to be syncronized with `Token::can_begin_bound`. @@ -4784,16 +4784,16 @@ impl<'a> Parser<'a> { return Ok(bounds); } - fn parse_ty_param_bounds(&mut self) -> PResult<'a, ParamBounds> { + fn parse_ty_param_bounds(&mut self) -> PResult<'a, GenericBounds> { self.parse_ty_param_bounds_common(true) } // 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) -> ParamBounds { + fn parse_lt_param_bounds(&mut self) -> GenericBounds { let mut lifetimes = Vec::new(); while self.check_lifetime() { - lifetimes.push(ast::ParamBound::Outlives(self.expect_lifetime())); + lifetimes.push(ast::GenericBound::Outlives(self.expect_lifetime())); if !self.eat_plus() { break @@ -4833,7 +4833,7 @@ impl<'a> Parser<'a> { } /// Parses the following grammar: - /// TraitItemAssocTy = Ident ["<"...">"] [":" [ParamBounds]] ["where" ...] ["=" Ty] + /// TraitItemAssocTy = Ident ["<"...">"] [":" [GenericBounds]] ["where" ...] ["=" Ty] fn parse_trait_item_assoc_ty(&mut self) -> PResult<'a, (Ident, TraitItemKind, ast::Generics)> { let ident = self.parse_ident()?; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 38229fa4998..1e0b107ef6e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -292,7 +292,7 @@ pub fn ty_to_string(ty: &ast::Ty) -> String { to_string(|s| s.print_type(ty)) } -pub fn bounds_to_string(bounds: &[ast::ParamBound]) -> String { +pub fn bounds_to_string(bounds: &[ast::GenericBound]) -> String { to_string(|s| s.print_type_bounds("", bounds)) } @@ -1177,7 +1177,7 @@ impl<'a> State<'a> { fn print_associated_type(&mut self, ident: ast::Ident, - bounds: Option<&ast::ParamBounds>, + bounds: Option<&ast::GenericBounds>, ty: Option<&ast::Ty>) -> io::Result<()> { self.word_space("type")?; @@ -2810,7 +2810,7 @@ impl<'a> State<'a> { pub fn print_type_bounds(&mut self, prefix: &str, - bounds: &[ast::ParamBound]) + bounds: &[ast::GenericBound]) -> io::Result<()> { if !bounds.is_empty() { self.s.word(prefix)?; @@ -2843,7 +2843,7 @@ impl<'a> State<'a> { self.print_name(lifetime.ident.name) } - pub fn print_lifetime_bounds(&mut self, lifetime: ast::Lifetime, bounds: &ast::ParamBounds) + pub fn print_lifetime_bounds(&mut self, lifetime: ast::Lifetime, bounds: &ast::GenericBounds) -> io::Result<()> { self.print_lifetime(lifetime)?; @@ -2854,7 +2854,7 @@ impl<'a> State<'a> { self.s.word(" + ")?; } match bound { - ast::ParamBound::Outlives(lt) => self.print_lifetime(*lt)?, + ast::GenericBound::Outlives(lt) => self.print_lifetime(*lt)?, _ => panic!(), } } diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index 2d92f4b9531..ebb3081c1fd 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -95,7 +95,7 @@ impl<'ast> Visitor<'ast> for NodeCounter { self.count += 1; walk_trait_ref(self, t) } - fn visit_param_bound(&mut self, bounds: &ParamBound) { + fn visit_param_bound(&mut self, bounds: &GenericBound) { self.count += 1; walk_param_bound(self, bounds) } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 6beaabd03de..71b606f08a5 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -86,7 +86,7 @@ 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_param_bound(&mut self, bounds: &'ast ParamBound) { + fn visit_param_bound(&mut self, bounds: &'ast GenericBound) { walk_param_bound(self, bounds) } fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) { @@ -479,7 +479,7 @@ pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) { // Empty! } -pub fn walk_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 GenericBound) { match *bound { Trait(ref typ, ref modifier) => { visitor.visit_poly_trait_ref(typ, modifier); diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 89b50044129..0922e7cd800 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -553,7 +553,7 @@ impl<'a> TraitDef<'a> { GenericParamKind::Lifetime { .. } => param.clone(), GenericParamKind::Type { .. } => { // I don't think this can be moved out of the loop, since - // a ParamBound requires an ast id + // a GenericBound requires an ast id let mut bounds: Vec<_> = // extra restrictions on the generics parameters to the // type being derived upon diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 99b6398160e..edb901e1f3c 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -261,7 +261,7 @@ impl<'a> LifetimeBounds<'a> { .iter() .map(|&(lt, ref bounds)| { let bounds = bounds.iter() - .map(|b| ast::ParamBound::Outlives(cx.lifetime(span, Ident::from_str(b)))); + .map(|b| ast::GenericBound::Outlives(cx.lifetime(span, Ident::from_str(b)))); cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds.collect()) }) .chain(self.bounds -- cgit 1.4.1-3-g733a5 From 95f1866a4df85e815886901a7b64d8dd64709872 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 14 Jun 2018 12:23:46 +0100 Subject: Make GenericBound explicit --- src/librustc/hir/lowering.rs | 6 +++--- src/librustc_passes/ast_validation.rs | 6 +++--- src/librustc_save_analysis/dump_visitor.rs | 8 +++----- src/librustdoc/clean/inline.rs | 10 +++++----- src/librustdoc/clean/mod.rs | 23 ++++++++++++----------- src/librustdoc/clean/simplify.rs | 4 ++-- src/librustdoc/html/format.rs | 4 ++-- src/libsyntax/ast.rs | 9 ++++----- src/libsyntax/ext/build.rs | 3 ++- src/libsyntax/fold.rs | 8 +++++--- src/libsyntax/parse/parser.rs | 10 +++++----- src/libsyntax/print/pprust.rs | 10 +++++----- src/libsyntax/visit.rs | 8 ++------ 13 files changed, 53 insertions(+), 56 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index b725432eb5c..7628504ba0d 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1109,11 +1109,11 @@ impl<'a> LoweringContext<'a> { let bounds = bounds .iter() .filter_map(|bound| match *bound { - Trait(ref ty, TraitBoundModifier::None) => { + GenericBound::Trait(ref ty, TraitBoundModifier::None) => { Some(self.lower_poly_trait_ref(ty, itctx)) } - Trait(_, TraitBoundModifier::Maybe) => None, - Outlives(ref lifetime) => { + GenericBound::Trait(_, TraitBoundModifier::Maybe) => None, + GenericBound::Outlives(ref lifetime) => { if lifetime_bound.is_none() { lifetime_bound = Some(self.lower_lifetime(lifetime)); } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 4f04ad89698..fc54d323b0f 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -101,7 +101,7 @@ impl<'a> AstValidator<'a> { fn no_questions_in_bounds(&self, bounds: &GenericBounds, where_: &str, is_trait: bool) { for bound in bounds { - if let Trait(ref poly, TraitBoundModifier::Maybe) = *bound { + if let GenericBound::Trait(ref poly, TraitBoundModifier::Maybe) = *bound { let mut err = self.err_handler().struct_span_err(poly.span, &format!("`?Trait` is not permitted in {}", where_)); if is_trait { @@ -190,7 +190,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { TyKind::TraitObject(ref bounds, ..) => { let mut any_lifetime_bounds = false; for bound in bounds { - if let Outlives(ref lifetime) = *bound { + if let GenericBound::Outlives(ref lifetime) = *bound { if any_lifetime_bounds { span_err!(self.session, lifetime.ident.span, E0226, "only a single explicit lifetime bound is permitted"); @@ -203,7 +203,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } TyKind::ImplTrait(ref bounds) => { if !bounds.iter() - .any(|b| if let Trait(..) = *b { true } else { false }) { + .any(|b| if let GenericBound::Trait(..) = *b { true } else { false }) { self.err_handler().span_err(ty.span, "at least one trait must be specified"); } } diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 0f0f3f6e789..7da5b1668b3 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -761,10 +761,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // super-traits for super_bound in trait_refs.iter() { let trait_ref = match *super_bound { - ast::Trait(ref trait_ref, _) => trait_ref, - ast::Outlives(..) => { - continue; - } + ast::GenericBound::Trait(ref trait_ref, _) => trait_ref, + ast::GenericBound::Outlives(..) => continue, }; let trait_ref = &trait_ref.trait_ref; @@ -1489,7 +1487,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc ast::GenericParamKind::Lifetime { .. } => {} ast::GenericParamKind::Type { ref default, .. } => { for bound in ¶m.bounds { - if let ast::Trait(ref trait_ref, _) = *bound { + if let ast::GenericBound::Trait(ref trait_ref, _) = *bound { self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) } } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index f3a833bad8f..114cb0e455d 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -374,8 +374,8 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { let polarity = tcx.impl_polarity(did); let trait_ = associated_trait.clean(cx).map(|bound| { match bound { - clean::TraitBound(polyt, _) => polyt.trait_, - clean::Outlives(..) => unreachable!(), + clean::GenericBound::TraitBound(polyt, _) => polyt.trait_, + clean::GenericBound::Outlives(..) => unreachable!(), } }); if trait_.def_id() == tcx.lang_items().deref_trait() { @@ -387,9 +387,9 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { let provided = trait_.def_id().map(|did| { tcx.provided_trait_methods(did) - .into_iter() - .map(|meth| meth.name.to_string()) - .collect() + .into_iter() + .map(|meth| meth.name.to_string()) + .collect() }).unwrap_or(FxHashSet()); ret.push(clean::Item { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 031a948fe80..0979c3d8558 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -14,7 +14,6 @@ pub use self::Type::*; pub use self::Mutability::*; pub use self::ItemEnum::*; -pub use self::GenericBound::*; pub use self::SelfTy::*; pub use self::FunctionRetTy::*; pub use self::Visibility::{Public, Inherited}; @@ -1470,7 +1469,7 @@ impl GenericBound { let path = external_path(cx, &cx.tcx.item_name(did).as_str(), Some(did), false, vec![], empty); inline::record_extern_fqn(cx, did, TypeKind::Trait); - TraitBound(PolyTrait { + GenericBound::TraitBound(PolyTrait { trait_: ResolvedPath { path, typarams: None, @@ -1510,8 +1509,10 @@ impl GenericBound { impl Clean for hir::GenericBound { fn clean(&self, cx: &DocContext) -> GenericBound { match *self { - hir::GenericBound::Outlives(lt) => Outlives(lt.clean(cx)), - hir::GenericBound::Trait(ref t, modifier) => TraitBound(t.clean(cx), modifier), + hir::GenericBound::Outlives(lt) => GenericBound::Outlives(lt.clean(cx)), + hir::GenericBound::Trait(ref t, modifier) => { + GenericBound::TraitBound(t.clean(cx), modifier) + } } } } @@ -1599,7 +1600,7 @@ impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec } } - TraitBound( + GenericBound::TraitBound( PolyTrait { trait_: ResolvedPath { path, @@ -1623,9 +1624,8 @@ impl<'tcx> Clean for ty::TraitRef<'tcx> { 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(GenericBound::Outlives)); - v.extend(self.types().map(|t| TraitBound(PolyTrait { + v.extend(self.regions().filter_map(|r| r.clean(cx)).map(GenericBound::Outlives)); + v.extend(self.types().map(|t| GenericBound::TraitBound(PolyTrait { trait_: t.clean(cx), generic_params: Vec::new(), }, hir::TraitBoundModifier::None))); @@ -2978,10 +2978,11 @@ impl Clean for hir::Ty { match bounds[0].clean(cx).trait_ { ResolvedPath { path, typarams: None, did, is_generic } => { let mut bounds: Vec = bounds[1..].iter().map(|bound| { - TraitBound(bound.clean(cx), hir::TraitBoundModifier::None) + self::GenericBound::TraitBound(bound.clean(cx), + hir::TraitBoundModifier::None) }).collect(); if !lifetime.is_elided() { - bounds.push(self::Outlives(lifetime.clean(cx))); + bounds.push(self::GenericBound::Outlives(lifetime.clean(cx))); } ResolvedPath { path, typarams: Some(bounds), did, is_generic, } } @@ -3086,7 +3087,7 @@ impl<'tcx> Clean for Ty<'tcx> { let path = external_path(cx, &cx.tcx.item_name(did).as_str(), Some(did), false, vec![], empty); inline::record_extern_fqn(cx, did, TypeKind::Trait); - let bound = TraitBound(PolyTrait { + let bound = GenericBound::TraitBound(PolyTrait { trait_: ResolvedPath { path, typarams: None, diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index a54eb64443b..30a55bf0d18 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -83,8 +83,8 @@ 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::Outlives(..) => return false, + clean::GenericBound::TraitBound(ref mut tr, _) => tr, + clean::GenericBound::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 987821d2e30..3d360f2f344 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -270,10 +270,10 @@ impl fmt::Display for clean::PolyTrait { impl fmt::Display for clean::GenericBound { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - clean::Outlives(ref lt) => { + clean::GenericBound::Outlives(ref lt) => { write!(f, "{}", *lt) } - clean::TraitBound(ref ty, modifier) => { + clean::GenericBound::TraitBound(ref ty, modifier) => { let modifier_str = match modifier { hir::TraitBoundModifier::None => "", hir::TraitBoundModifier::Maybe => "?", diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9dc13fab2d6..76d19ce0ac5 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::GenericBound::*; pub use self::UnsafeSource::*; pub use self::GenericArgs::*; pub use symbol::{Ident, Symbol as Name}; @@ -290,8 +289,8 @@ pub enum GenericBound { impl GenericBound { pub fn span(&self) -> Span { match self { - &Trait(ref t, ..) => t.span, - &Outlives(ref l) => l.ident.span, + &GenericBound::Trait(ref t, ..) => t.span, + &GenericBound::Outlives(ref l) => l.ident.span, } } } @@ -930,8 +929,8 @@ impl Expr { fn to_bound(&self) -> Option { match &self.node { ExprKind::Path(None, path) => - Some(Trait(PolyTraitRef::new(Vec::new(), path.clone(), self.span), - TraitBoundModifier::None)), + Some(GenericBound::Trait(PolyTraitRef::new(Vec::new(), path.clone(), self.span), + TraitBoundModifier::None)), _ => None, } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 9de6e14fbeb..40d45306149 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -465,7 +465,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn ty_param_bound(&self, path: ast::Path) -> ast::GenericBound { - ast::Trait(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None) + ast::GenericBound::Trait(self.poly_trait_ref(path.span, path), + ast::TraitBoundModifier::None) } fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 5db5d0781ea..03668cc279a 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -678,10 +678,12 @@ pub fn noop_fold_fn_decl(decl: P, fld: &mut T) -> P { pub fn noop_fold_param_bound(pb: GenericBound, fld: &mut T) -> GenericBound where T: Folder { match pb { - Trait(ty, modifier) => { - Trait(fld.fold_poly_trait_ref(ty), modifier) + GenericBound::Trait(ty, modifier) => { + GenericBound::Trait(fld.fold_poly_trait_ref(ty), modifier) + } + GenericBound::Outlives(lifetime) => { + GenericBound::Outlives(noop_fold_lifetime(lifetime, fld)) } - Outlives(lifetime) => Outlives(noop_fold_lifetime(lifetime, fld)), } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8588f4c492f..675849c8a5c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -10,7 +10,7 @@ use rustc_target::spec::abi::{self, Abi}; use ast::{AngleBracketedArgs, ParenthesizedArgData, AttrStyle, BareFnTy}; -use ast::{Outlives, Trait, TraitBoundModifier}; +use ast::{GenericBound, TraitBoundModifier}; use ast::Unsafety; use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use ast::Block; @@ -1444,7 +1444,7 @@ impl<'a> Parser<'a> { TyKind::TraitObject(ref bounds, TraitObjectSyntax::None) if maybe_bounds && bounds.len() == 1 && !trailing_plus => { let path = match bounds[0] { - Trait(ref pt, ..) => pt.trait_ref.path.clone(), + GenericBound::Trait(ref pt, ..) => pt.trait_ref.path.clone(), _ => self.bug("unexpected lifetime bound"), }; self.parse_remaining_bounds(Vec::new(), path, lo, true)? @@ -1566,7 +1566,7 @@ impl<'a> Parser<'a> { fn parse_remaining_bounds(&mut self, generic_params: Vec, path: ast::Path, lo: Span, parse_plus: bool) -> PResult<'a, TyKind> { let poly_trait_ref = PolyTraitRef::new(generic_params, path, lo.to(self.prev_span)); - let mut bounds = vec![Trait(poly_trait_ref, TraitBoundModifier::None)]; + let mut bounds = vec![GenericBound::Trait(poly_trait_ref, TraitBoundModifier::None)]; if parse_plus { self.eat_plus(); // `+`, or `+=` gets split and `+` is discarded bounds.append(&mut self.parse_ty_param_bounds()?); @@ -4752,7 +4752,7 @@ impl<'a> Parser<'a> { self.span_err(question_span, "`?` may only modify trait bounds, not lifetime bounds"); } - bounds.push(Outlives(self.expect_lifetime())); + bounds.push(GenericBound::Outlives(self.expect_lifetime())); if has_parens { self.expect(&token::CloseDelim(token::Paren))?; self.span_err(self.prev_span, @@ -4770,7 +4770,7 @@ impl<'a> Parser<'a> { } else { TraitBoundModifier::None }; - bounds.push(Trait(poly_trait, modifier)); + bounds.push(GenericBound::Trait(poly_trait, modifier)); } } else { break diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1e0b107ef6e..7a55919f422 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -12,7 +12,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::{self, Abi}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; -use ast::{SelfKind, Outlives, Trait, TraitBoundModifier}; +use ast::{SelfKind, GenericBound, TraitBoundModifier}; use ast::{Attribute, MacDelimiter, GenericArg}; use util::parser::{self, AssocOp, Fixity}; use attr; @@ -1364,7 +1364,7 @@ impl<'a> State<'a> { self.print_generic_params(&generics.params)?; let mut real_bounds = Vec::with_capacity(bounds.len()); for b in bounds.iter() { - if let Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b { + if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -1390,7 +1390,7 @@ impl<'a> State<'a> { let mut real_bounds = Vec::with_capacity(bounds.len()); // FIXME(durka) this seems to be some quite outdated syntax for b in bounds.iter() { - if let Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b { + if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b { self.s.space()?; self.word_space("for ?")?; self.print_trait_ref(&ptr.trait_ref)?; @@ -2826,13 +2826,13 @@ impl<'a> State<'a> { } match bound { - Trait(tref, modifier) => { + GenericBound::Trait(tref, modifier) => { if modifier == &TraitBoundModifier::Maybe { self.s.word("?")?; } self.print_poly_trait_ref(tref)?; } - Outlives(lt) => self.print_lifetime(*lt)?, + GenericBound::Outlives(lt) => self.print_lifetime(*lt)?, } } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 71b606f08a5..5476a3f0d2a 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -481,12 +481,8 @@ pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) { pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) { match *bound { - Trait(ref typ, ref modifier) => { - visitor.visit_poly_trait_ref(typ, modifier); - } - Outlives(ref lifetime) => { - visitor.visit_lifetime(lifetime); - } + GenericBound::Trait(ref typ, ref modifier) => visitor.visit_poly_trait_ref(typ, modifier), + GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime), } } -- cgit 1.4.1-3-g733a5 From 7a829273bf67999838cb14e6ff9ce6fd3a14a5e7 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 16 Jun 2018 11:14:07 +0100 Subject: Rename ty_param_bound to generic_bound --- src/librustc_privacy/lib.rs | 8 ++++---- src/libsyntax/parse/parser.rs | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 3b865e6ce0f..de087049267 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1037,7 +1037,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { self.access_levels.is_public(trait_id) } - fn check_ty_param_bound(&mut self, bound: &hir::GenericBound) { + fn check_generic_bound(&mut self, bound: &hir::GenericBound) { if let hir::GenericBound::Trait(ref trait_ref, _) = *bound { if self.path_is_private_type(&trait_ref.trait_ref.path) { self.old_error_set.insert(trait_ref.trait_ref.ref_id); @@ -1100,7 +1100,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } for bound in bounds.iter() { - self.check_ty_param_bound(bound) + self.check_generic_bound(bound) } } @@ -1271,7 +1271,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { GenericParamKind::Lifetime { .. } => {} GenericParamKind::Type { .. } => { for bound in ¶m.bounds { - self.check_ty_param_bound(bound); + self.check_generic_bound(bound); } } }); @@ -1279,7 +1279,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { match predicate { &hir::WherePredicate::BoundPredicate(ref bound_pred) => { for bound in bound_pred.bounds.iter() { - self.check_ty_param_bound(bound) + self.check_generic_bound(bound) } } &hir::WherePredicate::RegionPredicate(_) => {} diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 675849c8a5c..2bb8fff4037 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1509,7 +1509,7 @@ impl<'a> Parser<'a> { } } else if self.eat_keyword(keywords::Impl) { // Always parse bounds greedily for better error recovery. - let bounds = self.parse_ty_param_bounds()?; + let bounds = self.parse_generic_bounds()?; impl_dyn_multi = bounds.len() > 1 || self.prev_token_kind == PrevTokenKind::Plus; TyKind::ImplTrait(bounds) } else if self.check_keyword(keywords::Dyn) && @@ -1517,13 +1517,13 @@ impl<'a> Parser<'a> { !can_continue_type_after_non_fn_ident(t)) { self.bump(); // `dyn` // Always parse bounds greedily for better error recovery. - let bounds = self.parse_ty_param_bounds()?; + let bounds = self.parse_generic_bounds()?; impl_dyn_multi = bounds.len() > 1 || self.prev_token_kind == PrevTokenKind::Plus; TyKind::TraitObject(bounds, TraitObjectSyntax::Dyn) } else if self.check(&token::Question) || self.check_lifetime() && self.look_ahead(1, |t| t.is_like_plus()) { // Bound list (trait object type) - TyKind::TraitObject(self.parse_ty_param_bounds_common(allow_plus)?, + TyKind::TraitObject(self.parse_generic_bounds_common(allow_plus)?, TraitObjectSyntax::None) } else if self.eat_lt() { // Qualified path @@ -1569,7 +1569,7 @@ impl<'a> Parser<'a> { let mut bounds = vec![GenericBound::Trait(poly_trait_ref, TraitBoundModifier::None)]; if parse_plus { self.eat_plus(); // `+`, or `+=` gets split and `+` is discarded - bounds.append(&mut self.parse_ty_param_bounds()?); + bounds.append(&mut self.parse_generic_bounds()?); } Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None)) } @@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> { } self.bump(); // `+` - let bounds = self.parse_ty_param_bounds()?; + let bounds = self.parse_generic_bounds()?; let sum_span = ty.span.to(self.prev_span); let mut err = struct_span_err!(self.sess.span_diagnostic, sum_span, E0178, @@ -4735,7 +4735,7 @@ impl<'a> Parser<'a> { // LT_BOUND = LIFETIME (e.g. `'a`) // TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) // TY_BOUND_NOPAREN = [?] [for] SIMPLE_PATH (e.g. `?for<'a: 'b> m::Trait<'a>`) - fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, GenericBounds> { + fn parse_generic_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, GenericBounds> { let mut bounds = Vec::new(); loop { // This needs to be syncronized with `Token::can_begin_bound`. @@ -4784,8 +4784,8 @@ impl<'a> Parser<'a> { return Ok(bounds); } - fn parse_ty_param_bounds(&mut self) -> PResult<'a, GenericBounds> { - self.parse_ty_param_bounds_common(true) + fn parse_generic_bounds(&mut self) -> PResult<'a, GenericBounds> { + self.parse_generic_bounds_common(true) } // Parse bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`. @@ -4810,7 +4810,7 @@ impl<'a> Parser<'a> { // Parse optional colon and param bounds. let bounds = if self.eat(&token::Colon) { - self.parse_ty_param_bounds()? + self.parse_generic_bounds()? } else { Vec::new() }; @@ -4841,7 +4841,7 @@ impl<'a> Parser<'a> { // Parse optional colon and param bounds. let bounds = if self.eat(&token::Colon) { - self.parse_ty_param_bounds()? + self.parse_generic_bounds()? } else { Vec::new() }; @@ -5036,7 +5036,7 @@ impl<'a> Parser<'a> { // or with mandatory equality sign and the second type. let ty = self.parse_ty()?; if self.eat(&token::Colon) { - let bounds = self.parse_ty_param_bounds()?; + let bounds = self.parse_generic_bounds()?; where_clause.predicates.push(ast::WherePredicate::BoundPredicate( ast::WhereBoundPredicate { span: lo.to(self.prev_span), @@ -5536,14 +5536,14 @@ impl<'a> Parser<'a> { // Parse optional colon and supertrait bounds. let bounds = if self.eat(&token::Colon) { - self.parse_ty_param_bounds()? + self.parse_generic_bounds()? } else { Vec::new() }; if self.eat(&token::Eq) { // it's a trait alias - let bounds = self.parse_ty_param_bounds()?; + let bounds = self.parse_generic_bounds()?; tps.where_clause = self.parse_where_clause()?; self.expect(&token::Semi)?; if unsafety != Unsafety::Normal { -- cgit 1.4.1-3-g733a5 From 21136b8ab408a71c9f275f6ddcb9838a74c43a0c Mon Sep 17 00:00:00 2001 From: varkor Date: Sun, 17 Jun 2018 16:04:10 +0100 Subject: Rename ParenthesizedArgData to ParenthesisedArgs --- src/librustc/hir/lowering.rs | 4 ++-- src/libsyntax/ast.rs | 6 +++--- src/libsyntax/fold.rs | 12 ++++++------ src/libsyntax/parse/parser.rs | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 7628504ba0d..4e9bf8047e9 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1747,7 +1747,7 @@ impl<'a> LoweringContext<'a> { fn lower_parenthesized_parameter_data( &mut self, - data: &ParenthesizedArgData, + data: &ParenthesisedArgs, ) -> (hir::GenericArgs, bool) { // Switch to `PassThrough` mode for anonymous lifetimes: this // means that we permit things like `&Ref`, where `Ref` has @@ -1758,7 +1758,7 @@ impl<'a> LoweringContext<'a> { AnonymousLifetimeMode::PassThrough, |this| { const DISALLOWED: ImplTraitContext = ImplTraitContext::Disallowed; - let &ParenthesizedArgData { ref inputs, ref output, span } = data; + let &ParenthesisedArgs { ref inputs, ref output, span } = data; let inputs = inputs.iter().map(|ty| this.lower_ty(ty, DISALLOWED)).collect(); let mk_tup = |this: &mut Self, tys, span| { let LoweredNodeId { node_id, hir_id } = this.next_id(); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 76d19ce0ac5..c6de2c4da39 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -146,7 +146,7 @@ pub enum GenericArgs { /// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>` AngleBracketed(AngleBracketedArgs), /// The `(A,B)` and `C` in `Foo(A,B) -> C` - Parenthesized(ParenthesizedArgData), + Parenthesized(ParenthesisedArgs), } impl GenericArgs { @@ -183,7 +183,7 @@ impl Into>> for AngleBracketedArgs { } } -impl Into>> for ParenthesizedArgData { +impl Into>> for ParenthesisedArgs { fn into(self) -> Option> { Some(P(GenericArgs::Parenthesized(self))) } @@ -191,7 +191,7 @@ impl Into>> for ParenthesizedArgData { /// A path like `Foo(A,B) -> C` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub struct ParenthesizedArgData { +pub struct ParenthesisedArgs { /// Overall span pub span: Span, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 03668cc279a..93248fe3bfa 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -193,8 +193,8 @@ pub trait Folder : Sized { noop_fold_angle_bracketed_parameter_data(p, self) } - fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedArgData) - -> ParenthesizedArgData + fn fold_parenthesized_parameter_data(&mut self, p: ParenthesisedArgs) + -> ParenthesisedArgs { noop_fold_parenthesized_parameter_data(p, self) } @@ -483,12 +483,12 @@ pub fn noop_fold_angle_bracketed_parameter_data(data: AngleBracketedA } } -pub fn noop_fold_parenthesized_parameter_data(data: ParenthesizedArgData, +pub fn noop_fold_parenthesized_parameter_data(data: ParenthesisedArgs, fld: &mut T) - -> ParenthesizedArgData + -> ParenthesisedArgs { - let ParenthesizedArgData { inputs, output, span } = data; - ParenthesizedArgData { + let ParenthesisedArgs { inputs, output, span } = data; + ParenthesisedArgs { inputs: inputs.move_map(|ty| fld.fold_ty(ty)), output: output.map(|ty| fld.fold_ty(ty)), span: fld.new_span(span) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2bb8fff4037..6f78ae9ebca 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -9,7 +9,7 @@ // except according to those terms. use rustc_target::spec::abi::{self, Abi}; -use ast::{AngleBracketedArgs, ParenthesizedArgData, AttrStyle, BareFnTy}; +use ast::{AngleBracketedArgs, ParenthesisedArgs, AttrStyle, BareFnTy}; use ast::{GenericBound, TraitBoundModifier}; use ast::Unsafety; use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind}; @@ -1988,7 +1988,7 @@ impl<'a> Parser<'a> { None }; let span = lo.to(self.prev_span); - ParenthesizedArgData { inputs, output, span }.into() + ParenthesisedArgs { inputs, output, span }.into() }; PathSegment { ident, args } -- cgit 1.4.1-3-g733a5