diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 831a689a349..d00792be4eb 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1726,7 +1726,7 @@ impl<'a> LoweringContext<'a> { hir::PathSegment::new( self.lower_ident(segment.ident), generic_args, - infer_types + infer_types, ) } @@ -1738,7 +1738,7 @@ impl<'a> LoweringContext<'a> { ) -> (hir::GenericArgs, bool) { let &AngleBracketedArgs { ref args, ref bindings, .. } = data; (hir::GenericArgs { - args: args.iter().map(|p| self.lower_generic_arg(p, itctx)).collect(), + args: args.iter().map(|a| self.lower_generic_arg(a, itctx)).collect(), bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(), parenthesized: false, }, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 729ac17ae09..d4785e40b1f 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -360,7 +360,7 @@ impl PathSegment { // FIXME: hack required because you can't create a static // GenericArgs, so you can't just return a &GenericArgs. - pub fn with_args(&self, f: F) -> R + pub fn with_generic_args(&self, f: F) -> R where F: FnOnce(&GenericArgs) -> R { let dummy = GenericArgs::none(); diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index c12d258b6c7..5420be64ca4 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_args(|args| { - if !args.args.is_empty() || - !args.bindings.is_empty() + segment.with_generic_args(|generic_args| { + if !generic_args.args.is_empty() || + !generic_args.bindings.is_empty() { - self.print_generic_args(&args, segment.infer_types, true) + self.print_generic_args(&generic_args, segment.infer_types, true) } else { Ok(()) } @@ -1641,10 +1641,10 @@ impl<'a> State<'a> { if segment.name != keywords::CrateRoot.name() && segment.name != keywords::DollarCrate.name() { self.print_name(segment.name)?; - segment.with_args(|parameters| { - self.print_generic_args(parameters, - segment.infer_types, - colons_before_params) + segment.with_generic_args(|generic_args| { + self.print_generic_args(generic_args, + segment.infer_types, + colons_before_params) })?; } } @@ -1673,10 +1673,10 @@ impl<'a> State<'a> { if segment.name != keywords::CrateRoot.name() && segment.name != keywords::DollarCrate.name() { self.print_name(segment.name)?; - segment.with_args(|parameters| { - self.print_generic_args(parameters, - segment.infer_types, - colons_before_params) + segment.with_generic_args(|generic_args| { + self.print_generic_args(generic_args, + segment.infer_types, + colons_before_params) })?; } } @@ -1685,10 +1685,10 @@ impl<'a> State<'a> { self.s.word("::")?; let item_segment = path.segments.last().unwrap(); self.print_name(item_segment.name)?; - item_segment.with_args(|parameters| { - self.print_generic_args(parameters, - item_segment.infer_types, - colons_before_params) + item_segment.with_generic_args(|generic_args| { + self.print_generic_args(generic_args, + item_segment.infer_types, + colons_before_params) }) } hir::QPath::TypeRelative(ref qself, ref item_segment) => { @@ -1697,10 +1697,10 @@ impl<'a> State<'a> { self.s.word(">")?; self.s.word("::")?; self.print_name(item_segment.name)?; - item_segment.with_args(|parameters| { - self.print_generic_args(parameters, - item_segment.infer_types, - colons_before_params) + item_segment.with_generic_args(|generic_args| { + self.print_generic_args(generic_args, + item_segment.infer_types, + colons_before_params) }) } } @@ -1734,11 +1734,11 @@ 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.args, |s, p| { - match p { + self.commasep(Inconsistent, &generic_args.args, |s, generic_arg| { + match generic_arg { GenericArg::Lifetime(lt) => s.print_lifetime(lt), GenericArg::Type(ty) => s.print_type(ty), - } + } })?; } else if generic_args.types().count() != 0 { start_or_comma(self)?; diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 39dfa77ea67..8f1cd9bb30e 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1601,20 +1601,21 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { &mut self, def: Def, depth: usize, - args: &'tcx hir::GenericArgs, + generic_args: &'tcx hir::GenericArgs, ) { - if args.parenthesized { + if generic_args.parenthesized { let was_in_fn_syntax = self.is_in_fn_syntax; self.is_in_fn_syntax = true; - self.visit_fn_like_elision(args.inputs(), Some(&args.bindings[0].ty)); + self.visit_fn_like_elision(generic_args.inputs(), + Some(&generic_args.bindings[0].ty)); self.is_in_fn_syntax = was_in_fn_syntax; return; } - if args.lifetimes().all(|l| l.is_elided()) { - self.resolve_elided_lifetimes(args.lifetimes().collect(), true); + if generic_args.lifetimes().all(|l| l.is_elided()) { + self.resolve_elided_lifetimes(generic_args.lifetimes().collect(), true); } else { - for l in args.lifetimes() { + for l in generic_args.lifetimes() { self.visit_lifetime(l); } } @@ -1686,13 +1687,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } else { Some(Region::Static) }, - Set1::One(r) => r.subst(args.lifetimes(), map), + Set1::One(r) => r.subst(generic_args.lifetimes(), map), Set1::Many => None, }) .collect() }); - for (i, ty) in args.types().enumerate() { + for (i, ty) in generic_args.types().enumerate() { if let Some(<) = object_lifetime_defaults.get(i) { let scope = Scope::ObjectLifetimeDefault { lifetime: lt, @@ -1704,7 +1705,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } } - for b in &args.bindings { + for b in &generic_args.bindings { self.visit_assoc_type_binding(b); } } diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 8b1c31deb13..66edbeff749 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -10,7 +10,6 @@ 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/subst.rs b/src/librustc/ty/subst.rs index 932f082c87c..2e3c6df9754 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -105,10 +105,6 @@ impl<'tcx> From> for Kind<'tcx> { } } -impl<'tcx> Into> for ty::Region<'tcx> {} - -impl<'tcx> Into> for Ty<'tcx> {} - impl<'tcx> Kind<'tcx> { #[inline] pub fn unpack(self) -> UnpackedKind<'tcx> { diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 7c8ba63c15e..322924535d1 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -40,7 +40,6 @@ 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 7468f01de70..0ea2832bf80 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.args.as_ref().map(|p| &**p) { + match seg.args.as_ref().map(|generic_arg| &**generic_arg) { None => false, Some(&ast::GenericArgs::AngleBracketed(ref data)) => any_involves_impl_trait(data.types().into_iter()) || diff --git a/src/librustc_mir/monomorphize/mod.rs b/src/librustc_mir/monomorphize/mod.rs index 3afe9991c68..bf544e5120c 100644 --- a/src/librustc_mir/monomorphize/mod.rs +++ b/src/librustc_mir/monomorphize/mod.rs @@ -13,7 +13,6 @@ 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 63c8bd3d1f7..211a45bc3c5 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -523,21 +523,21 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> { } fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) { match *generic_args { - GenericArgs::AngleBracketed(ref params) => { - for type_ in params.types() { + GenericArgs::AngleBracketed(ref generic_args) => { + for type_ in generic_args.types() { self.visit_ty(type_); } - for type_binding in ¶ms.bindings { + for type_binding in &generic_args.bindings { // Type bindings such as `Item=impl Debug` in `Iterator` // are allowed to contain nested `impl Trait`. self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty)); } } - GenericArgs::Parenthesized(ref params) => { - for type_ in ¶ms.inputs { + GenericArgs::Parenthesized(ref generic_args) => { + for type_ in &generic_args.inputs { self.visit_ty(type_); } - if let Some(ref type_) = params.output { + if let Some(ref type_) = generic_args.output { // `-> Foo` syntax is essentially an associated type binding, // so it is also allowed to contain nested `impl Trait`. self.with_impl_trait(None, |this| visit::walk_ty(this, type_)); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index fa055d246f3..055d58f0b1f 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -820,8 +820,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // Type arguments for seg in &path.segments { - if let Some(ref args) = seg.args { - match **args { + if let Some(ref generic_args) = seg.args { + match **generic_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 args) = seg.args { - if let ast::GenericArgs::AngleBracketed(ref data) = **args { + if let Some(ref generic_args) = seg.args { + if let ast::GenericArgs::AngleBracketed(ref data) = **generic_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 4f03698d9b1..8a44f271055 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 args) = path.segments[0].args { - if let ast::GenericArgs::Parenthesized(_) = **args { + if let Some(ref generic_args) = path.segments[0].args { + if let ast::GenericArgs::Parenthesized(_) = **generic_args { return true; } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index be4c423e959..e4b3b4e6041 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_args(|args| { + item_segment.with_generic_args(|generic_args| { self.create_substs_for_ast_path( span, def_id, - args, + generic_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, - args: &hir::GenericArgs, + generic_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={:?}, \ - args={:?})", - def_id, self_ty, args); + generic_args={:?})", + def_id, self_ty, generic_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 = args.types().count(); - let lt_provided = args.lifetimes().count(); + let ty_provided = generic_args.types().count(); + let lt_provided = generic_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) = args.lifetimes().nth(i) { + if let Some(lifetime) = generic_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(&args.types().nth(i).unwrap()).into() + self.ast_ty_to_ty(&generic_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 = args.bindings.iter().map(|binding| { + let assoc_bindings = generic_args.bindings.iter().map(|binding| { ConvertedBinding { item_name: binding.name, ty: self.ast_ty_to_ty(&binding.ty), @@ -451,7 +451,8 @@ 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_args(|p| p.parenthesized) != trait_def.paren_sugar { + trait_segment.with_generic_args(|generic_args| generic_args.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,10 +464,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { span, GateIssue::Language, msg); } - trait_segment.with_args(|parameters| { + trait_segment.with_generic_args(|generic_args| { self.create_substs_for_ast_path(span, trait_def_id, - parameters, + generic_args, trait_segment.infer_types, Some(self_ty)) }) @@ -970,27 +971,36 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) { for segment in segments { - segment.with_args(|params| { - for p in ¶ms.args { - let (mut span_err, span, kind) = match p { + segment.with_generic_args(|generic_args| { + let mut err_for_lifetime = false; + let mut err_for_type = false; + for arg in &generic_args.args { + let (mut span_err, span, kind) = match arg { hir::GenericArg::Lifetime(lt) => { + if err_for_lifetime { continue } + err_for_lifetime = true; (struct_span_err!(self.tcx().sess, lt.span, E0110, - "lifetime parameters are not allowed on this type"), + "lifetime parameters are not allowed on \ + this type"), lt.span, "lifetime") } hir::GenericArg::Type(ty) => { + if err_for_type { continue } + err_for_type = true; (struct_span_err!(self.tcx().sess, ty.span, E0109, - "type parameters are not allowed on this type"), + "type parameters are not allowed on this type"), ty.span, "type") } }; span_err.span_label(span, format!("{} parameter not allowed", kind)) .emit(); - break; + if err_for_lifetime && err_for_type { + break; + } } - for binding in ¶ms.bindings { + for binding in &generic_args.bindings { self.prohibit_projection(binding.span); break; } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 5af3d2fc42c..c0779235e89 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.args.as_ref().map_or(vec![], |p| p.lifetimes().collect()) + s.args.as_ref().map_or(vec![], |arg| arg.lifetimes().collect()) }); if let Some(lifetime) = lifetimes.get(i) { @@ -4845,7 +4845,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } GenericParamDefKind::Type {..} => { let (types, infer_types) = segment.map_or((vec![], true), |(s, _)| { - (s.args.as_ref().map_or(vec![], |p| p.types().collect()), s.infer_types) + (s.args.as_ref().map_or(vec![], |arg| { + arg.types().collect() + }), s.infer_types) }); // Skip over the lifetimes in the same segment. @@ -4956,16 +4958,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Report errors if the provided parameters are too few or too many. fn check_generic_arg_count(&self, - span: Span, - segment: &mut Option<(&hir::PathSegment, &ty::Generics)>, - is_method_call: bool, - supress_mismatch_error: bool) { + span: Span, + segment: &mut Option<(&hir::PathSegment, &ty::Generics)>, + is_method_call: bool, + supress_mismatch_error: bool) { let (lifetimes, types, infer_types, bindings) = segment.map_or( (vec![], vec![], true, &[][..]), - |(s, _)| s.args.as_ref().map_or( - (vec![], vec![], s.infer_types, &[][..]), - |p| (p.lifetimes().collect(), p.types().collect(), - s.infer_types, &p.bindings[..]))); + |(s, _)| { + s.args.as_ref().map_or( + (vec![], vec![], s.infer_types, &[][..]), + |arg| { + (arg.lifetimes().collect(), + arg.types().collect(), + s.infer_types, + &arg.bindings[..]) + } + ) + }); let infer_lifetimes = lifetimes.len() == 0; let count_lifetime_params = |n| { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 793a8a7f110..0d44c583cff 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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_args(|provided_params| { + provided_params.with_generic_args(|generic_args| { let mut indices = GenericParamCount { lifetimes: 0, types: 0 @@ -2859,7 +2859,7 @@ 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() + if let Some(lt) = generic_args.lifetimes() .nth(indices.lifetimes).cloned() { if !lt.is_elided() { let lt_def_id = @@ -2872,7 +2872,7 @@ 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() + if let Some(ty) = generic_args.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() { @@ -3497,9 +3497,9 @@ impl Clean for hir::GenericArgs { lifetimes: if self.lifetimes().all(|lt| lt.is_elided()) { vec![] } else { - self.lifetimes().map(|lp| lp.clean(cx)).collect() + self.lifetimes().map(|lt| lt.clean(cx)).collect() }, - types: self.types().map(|tp| tp.clean(cx)).collect(), + types: self.types().map(|ty| ty.clean(cx)).collect(), bindings: self.bindings.clean(cx), } } @@ -3516,7 +3516,7 @@ impl Clean for hir::PathSegment { fn clean(&self, cx: &DocContext) -> PathSegment { PathSegment { name: self.name.clean(cx), - args: self.with_args(|args| args.clean(cx)) + args: self.with_generic_args(|generic_args| generic_args.clean(cx)) } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7ff00123624..5ae520050e5 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -188,8 +188,8 @@ pub struct AngleBracketedArgs { impl AngleBracketedArgs { pub fn lifetimes(&self) -> impl DoubleEndedIterator { - self.args.iter().filter_map(|p| { - if let GenericArg::Lifetime(lt) = p { + self.args.iter().filter_map(|arg| { + if let GenericArg::Lifetime(lt) = arg { Some(lt) } else { None @@ -198,8 +198,8 @@ impl AngleBracketedArgs { } pub fn types(&self) -> impl DoubleEndedIterator> { - self.args.iter().filter_map(|p| { - if let GenericArg::Type(ty) = p { + self.args.iter().filter_map(|arg| { + if let GenericArg::Type(ty) = arg { Some(ty) } else { None diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 05a345fb2a1..c544adb5c1c 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, + 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, - parameters: Vec, + args: Vec, bindings: Vec) -> (ast::QSelf, ast::Path); @@ -302,13 +302,13 @@ pub trait AstBuilder { impl<'a> AstBuilder for ExtCtxt<'a> { fn path(&self, span: Span, strs: Vec ) -> ast::Path { - self.path_all(span, false, strs, Vec::new(), Vec::new()) + self.path_all(span, false, strs, vec![], vec![]) } fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path { self.path(span, vec![id]) } fn path_global(&self, span: Span, strs: Vec ) -> ast::Path { - self.path_all(span, true, strs, Vec::new(), Vec::new()) + self.path_all(span, true, strs, vec![], vec![]) } fn path_all(&self, span: Span, @@ -318,7 +318,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { bindings: Vec ) -> ast::Path { let last_ident = idents.pop().unwrap(); - let mut segments: Vec = Vec::new(); + let mut segments: Vec = vec![]; segments.extend(idents.into_iter().map(|ident| { ast::PathSegment::from_ident(ident.with_span_pos(span)) @@ -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::GenericArg::Type(ty)], Vec::new())) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index dc23ed19d1b..f74fe1feb40 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -132,10 +132,9 @@ pub trait Folder : Sized { noop_fold_exprs(es, self) } - fn fold_param(&mut self, p: GenericArg) -> GenericArg { - match p { - GenericArg::Lifetime(lt) => - GenericArg::Lifetime(self.fold_lifetime(lt)), + fn fold_generic_arg(&mut self, arg: GenericArg) -> GenericArg { + match arg { + GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.fold_lifetime(lt)), GenericArg::Type(ty) => GenericArg::Type(self.fold_ty(ty)), } } @@ -441,9 +440,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, args}| PathSegment { + segments: segments.move_map(|PathSegment { ident, args }| PathSegment { ident: fld.fold_ident(ident), - args: args.map(|ps| ps.map(|ps| fld.fold_generic_args(ps))), + args: args.map(|args| args.map(|args| fld.fold_generic_args(args))), }), span: fld.new_span(span) } @@ -462,14 +461,15 @@ pub fn noop_fold_qpath(qself: Option, (qself, fld.fold_path(path)) } -pub fn noop_fold_generic_args(generic_args: GenericArgs, fld: &mut T) - -> GenericArgs +pub fn noop_fold_generic_args(generic_args: GenericArgs, fld: &mut T) -> GenericArgs { match generic_args { - GenericArgs::AngleBracketed(data) => - GenericArgs::AngleBracketed(fld.fold_angle_bracketed_parameter_data(data)), - GenericArgs::Parenthesized(data) => - GenericArgs::Parenthesized(fld.fold_parenthesized_parameter_data(data)), + GenericArgs::AngleBracketed(data) => { + GenericArgs::AngleBracketed(fld.fold_angle_bracketed_parameter_data(data)) + } + GenericArgs::Parenthesized(data) => { + GenericArgs::Parenthesized(fld.fold_parenthesized_parameter_data(data)) + } } } @@ -478,9 +478,11 @@ pub fn noop_fold_angle_bracketed_parameter_data(data: AngleBracketedA -> AngleBracketedArgs { 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) } + AngleBracketedArgs { + args: args.move_map(|arg| fld.fold_generic_arg(arg)), + bindings: bindings.move_map(|b| fld.fold_ty_binding(b)), + span: fld.new_span(span) + } } pub fn noop_fold_parenthesized_parameter_data(data: ParenthesizedArgData, @@ -488,9 +490,11 @@ pub fn noop_fold_parenthesized_parameter_data(data: ParenthesizedArgD -> ParenthesizedArgData { 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) } + ParenthesizedArgData { + inputs: inputs.move_map(|ty| fld.fold_ty(ty)), + output: output.map(|ty| fld.fold_ty(ty)), + span: fld.new_span(span) + } } pub fn noop_fold_local(l: P, fld: &mut T) -> P { @@ -1191,8 +1195,8 @@ pub fn noop_fold_expr(Expr {id, node, span, attrs}: Expr, folder: &mu ExprKind::MethodCall( PathSegment { ident: folder.fold_ident(seg.ident), - args: seg.args.map(|ps| { - ps.map(|ps| folder.fold_generic_args(ps)) + args: seg.args.map(|args| { + args.map(|args| folder.fold_generic_args(args)) }), }, folder.fold_exprs(args)) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 3b487430c52..3e0e533bc08 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1017,8 +1017,8 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_param(&mut self, param: &GenericArg) -> io::Result<()> { - match param { + pub fn print_generic_arg(&mut self, generic_arg: &GenericArg) -> io::Result<()> { + match generic_arg { GenericArg::Lifetime(lt) => self.print_lifetime(lt), GenericArg::Type(ty) => self.print_type(ty), } @@ -2469,9 +2469,9 @@ impl<'a> State<'a> { } fn print_generic_args(&mut self, - args: &ast::GenericArgs, - colons_before_params: bool) - -> io::Result<()> + args: &ast::GenericArgs, + colons_before_params: bool) + -> io::Result<()> { if colons_before_params { self.s.word("::")? @@ -2481,7 +2481,9 @@ impl<'a> State<'a> { ast::GenericArgs::AngleBracketed(ref data) => { self.s.word("<")?; - self.commasep(Inconsistent, &data.args, |s, p| s.print_param(p))?; + self.commasep(Inconsistent, &data.args, |s, generic_arg| { + s.print_generic_arg(generic_arg) + })?; let mut comma = data.args.len() != 0; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 906f1941cd6..5ac33701baf 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -131,8 +131,8 @@ 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 GenericArg) { - match param { + fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) { + match generic_arg { GenericArg::Lifetime(lt) => self.visit_lifetime(lt), GenericArg::Type(ty) => self.visit_ty(ty), } @@ -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.args); + walk_list!(visitor, visit_generic_arg, &data.args); walk_list!(visitor, visit_assoc_type_binding, &data.bindings); } GenericArgs::Parenthesized(ref data) => { diff --git a/src/test/ui/error-codes/E0110.stderr b/src/test/ui/error-codes/E0110.stderr index 10e06ee6d02..7f5b78684fb 100644 --- a/src/test/ui/error-codes/E0110.stderr +++ b/src/test/ui/error-codes/E0110.stderr @@ -2,7 +2,7 @@ error[E0110]: lifetime parameters are not allowed on this type --> $DIR/E0110.rs:11:14 | LL | type X = u32<'static>; //~ ERROR E0110 - | ^^^^^^^ lifetime parameter not allowed on this type + | ^^^^^^^ lifetime parameter not allowed error: aborting due to previous error diff --git a/src/test/ui/rfc1598-generic-associated-types/collections.stderr b/src/test/ui/rfc1598-generic-associated-types/collections.stderr index ed96570583f..8c31ab2ca88 100644 --- a/src/test/ui/rfc1598-generic-associated-types/collections.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/collections.stderr @@ -20,13 +20,13 @@ error[E0110]: lifetime parameters are not allowed on this type --> $DIR/collections.rs:33:50 | LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>; - | ^^^^^ lifetime parameter not allowed on this type + | ^^^^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/collections.rs:59:50 | LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> { - | ^^^^^ lifetime parameter not allowed on this type + | ^^^^^ lifetime parameter not allowed error: aborting due to 5 previous errors diff --git a/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr b/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr index 764a0db2478..1746122eb49 100644 --- a/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/construct_with_other_type.stderr @@ -2,19 +2,19 @@ error[E0110]: lifetime parameters are not allowed on this type --> $DIR/construct_with_other_type.rs:26:46 | LL | type Baa<'a>: Deref as Foo>::Bar<'a, 'static>>; - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/construct_with_other_type.rs:26:63 | LL | type Baa<'a>: Deref as Foo>::Bar<'a, 'static>>; - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/construct_with_other_type.rs:34:40 | LL | type Baa<'a> = &'a ::Bar<'a, 'static>; - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error: aborting due to 3 previous errors diff --git a/src/test/ui/rfc1598-generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr b/src/test/ui/rfc1598-generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr index 64e82c0d109..d48c21477b3 100644 --- a/src/test/ui/rfc1598-generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/generic_associated_type_undeclared_lifetimes.stderr @@ -14,19 +14,19 @@ error[E0110]: lifetime parameters are not allowed on this type --> $DIR/generic_associated_type_undeclared_lifetimes.rs:20:47 | LL | type Iter<'a>: Iterator> - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/generic_associated_type_undeclared_lifetimes.rs:22:37 | LL | + Deref>; - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/generic_associated_type_undeclared_lifetimes.rs:26:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>; - | ^^^^^^^^^^^ lifetime parameter not allowed on this type + | ^^^^^^^^^^^ lifetime parameter not allowed error: aborting due to 5 previous errors diff --git a/src/test/ui/rfc1598-generic-associated-types/iterable.stderr b/src/test/ui/rfc1598-generic-associated-types/iterable.stderr index 0e251300e45..737a29ec2c8 100644 --- a/src/test/ui/rfc1598-generic-associated-types/iterable.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/iterable.stderr @@ -2,37 +2,37 @@ error[E0110]: lifetime parameters are not allowed on this type --> $DIR/iterable.rs:20:47 | LL | type Iter<'a>: Iterator>; - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/iterable.rs:49:53 | LL | fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> { - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/iterable.rs:54:60 | LL | fn get_first<'a, I: Iterable>(it: &'a I) -> Option> { - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/iterable.rs:23:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'a>; - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/iterable.rs:32:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/iterable.rs:43:41 | LL | fn iter<'a>(&'a self) -> Self::Iter<'a> { - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error: aborting due to 6 previous errors diff --git a/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr b/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr index df83fdaad5b..c8d37a51fa9 100644 --- a/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/parameter_number_and_kind.stderr @@ -1,20 +1,26 @@ +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/parameter_number_and_kind.rs:26:27 + | +LL | type FOk = Self::E<'static, T>; + | ^^^^^^^ lifetime parameter not allowed + error[E0109]: type parameters are not allowed on this type --> $DIR/parameter_number_and_kind.rs:26:36 | LL | type FOk = Self::E<'static, T>; | ^ type parameter not allowed -error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/parameter_number_and_kind.rs:26:27 - | -LL | type FOk = Self::E<'static, T>; - | ^^^^^^^ lifetime parameter not allowed on this type - error[E0110]: lifetime parameters are not allowed on this type --> $DIR/parameter_number_and_kind.rs:29:26 | LL | type FErr1 = Self::E<'static, 'static>; // Error - | ^^^^^^^ lifetime parameter not allowed on this type + | ^^^^^^^ lifetime parameter not allowed + +error[E0110]: lifetime parameters are not allowed on this type + --> $DIR/parameter_number_and_kind.rs:31:29 + | +LL | type FErr2 = Self::E<'static, T, u32>; // Error + | ^^^^^^^ lifetime parameter not allowed error[E0109]: type parameters are not allowed on this type --> $DIR/parameter_number_and_kind.rs:31:38 @@ -22,12 +28,6 @@ error[E0109]: type parameters are not allowed on this type LL | type FErr2 = Self::E<'static, T, u32>; // Error | ^ type parameter not allowed -error[E0110]: lifetime parameters are not allowed on this type - --> $DIR/parameter_number_and_kind.rs:31:29 - | -LL | type FErr2 = Self::E<'static, T, u32>; // Error - | ^^^^^^^ lifetime parameter not allowed on this type - error: aborting due to 5 previous errors Some errors occurred: E0109, E0110. diff --git a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs index 3f69de3de83..522ddb5dc13 100644 --- a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs +++ b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.rs @@ -10,7 +10,7 @@ #![feature(generic_associated_types)] -//FIXME(#44265): "lifetime parameter not allowed" errors will be addressed in a +//FIXME(#44265): "lifetime parameter not allowed on this type" errors will be addressed in a // follow-up PR use std::fmt::Display; diff --git a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr index 607a4b8d579..12e206cbd47 100644 --- a/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr +++ b/src/test/ui/rfc1598-generic-associated-types/streaming_iterator.stderr @@ -2,31 +2,31 @@ error[E0110]: lifetime parameters are not allowed on this type --> $DIR/streaming_iterator.rs:27:41 | LL | bar: ::Item<'static>, - | ^^^^^^^ lifetime parameter not allowed on this type + | ^^^^^^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/streaming_iterator.rs:35:64 | LL | fn foo(iter: T) where T: StreamingIterator, for<'a> T::Item<'a>: Display { /* ... */ } - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/streaming_iterator.rs:21:48 | LL | fn next<'a>(&'a self) -> Option>; - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/streaming_iterator.rs:47:37 | LL | type Item<'a> = (usize, I::Item<'a>); - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error[E0110]: lifetime parameters are not allowed on this type --> $DIR/streaming_iterator.rs:49:48 | LL | fn next<'a>(&'a self) -> Option> { - | ^^ lifetime parameter not allowed on this type + | ^^ lifetime parameter not allowed error: aborting due to 5 previous errors