]> git.lizzy.rs Git - rust.git/commitdiff
parse: move constraint/arg restriction to ast_validation.
authorMazdak Farrokhzad <twingoow@gmail.com>
Sun, 22 Mar 2020 03:40:05 +0000 (04:40 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Fri, 27 Mar 2020 06:39:14 +0000 (07:39 +0100)
17 files changed:
src/librustc_ast/ast.rs
src/librustc_ast/mut_visit.rs
src/librustc_ast/visit.rs
src/librustc_ast_lowering/lib.rs
src/librustc_ast_lowering/path.rs
src/librustc_ast_passes/ast_validation.rs
src/librustc_ast_passes/lib.rs
src/librustc_ast_pretty/pprust.rs
src/librustc_expand/build.rs
src/librustc_interface/util.rs
src/librustc_parse/parser/path.rs
src/librustc_save_analysis/dump_visitor.rs
src/test/ui/parser/constraints-before-generic-args-syntactic-pass.rs [new file with mode: 0644]
src/test/ui/parser/issue-32214.rs
src/test/ui/parser/issue-32214.stderr
src/test/ui/suggestions/suggest-move-types.rs
src/test/ui/suggestions/suggest-move-types.stderr

index 646294a7cca7871801a49db77a392fbef11ab9cb..6586280d21454aa63aa5e2a8fcbfdc46cf5235d5 100644 (file)
@@ -214,11 +214,18 @@ pub fn span(&self) -> Span {
 pub struct AngleBracketedArgs {
     /// The overall span.
     pub span: Span,
-    /// The arguments for this path segment.
-    pub args: Vec<GenericArg>,
-    /// Constraints on associated types, if any.
-    /// E.g., `Foo<A = Bar, B: Baz>`.
-    pub constraints: Vec<AssocTyConstraint>,
+    /// The comma separated parts in the `<...>`.
+    pub args: Vec<AngleBracketedArg>,
+}
+
+/// Either an argument for a parameter e.g., `'a`, `Vec<u8>`, `0`,
+/// or a constraint on an associated item, e.g., `Item = String` or `Item: Bound`.
+#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
+pub enum AngleBracketedArg {
+    /// Argument for a generic parameter.
+    Arg(GenericArg),
+    /// Constraint for an associated item.
+    Constraint(AssocTyConstraint),
 }
 
 impl Into<Option<P<GenericArgs>>> for AngleBracketedArgs {
@@ -248,11 +255,13 @@ pub struct ParenthesizedArgs {
 
 impl ParenthesizedArgs {
     pub fn as_angle_bracketed_args(&self) -> AngleBracketedArgs {
-        AngleBracketedArgs {
-            span: self.span,
-            args: self.inputs.iter().cloned().map(GenericArg::Type).collect(),
-            constraints: vec![],
-        }
+        let args = self
+            .inputs
+            .iter()
+            .cloned()
+            .map(|input| AngleBracketedArg::Arg(GenericArg::Type(input)))
+            .collect();
+        AngleBracketedArgs { span: self.span, args }
     }
 }
 
index 67f7764d5bb27bf94a8f3923abd04060a8f6f300..a72a60c30b28a049dec4f28b47cb42368534cecd 100644 (file)
@@ -546,9 +546,11 @@ pub fn noop_visit_angle_bracketed_parameter_data<T: MutVisitor>(
     data: &mut AngleBracketedArgs,
     vis: &mut T,
 ) {
-    let AngleBracketedArgs { args, constraints, span } = data;
-    visit_vec(args, |arg| vis.visit_generic_arg(arg));
-    visit_vec(constraints, |constraint| vis.visit_ty_constraint(constraint));
+    let AngleBracketedArgs { args, span } = data;
+    visit_vec(args, |arg| match arg {
+        AngleBracketedArg::Arg(arg) => vis.visit_generic_arg(arg),
+        AngleBracketedArg::Constraint(constraint) => vis.visit_ty_constraint(constraint),
+    });
     vis.visit_span(span);
 }
 
index cc2b1c48b51acc093fda84303c9a2ae618a3c23c..51863350a8cf38f3508a1ede7e9616741a41d3f7 100644 (file)
@@ -464,8 +464,12 @@ pub fn walk_generic_args<'a, V>(visitor: &mut V, _path_span: Span, generic_args:
 {
     match *generic_args {
         GenericArgs::AngleBracketed(ref data) => {
-            walk_list!(visitor, visit_generic_arg, &data.args);
-            walk_list!(visitor, visit_assoc_ty_constraint, &data.constraints);
+            for arg in &data.args {
+                match arg {
+                    AngleBracketedArg::Arg(a) => visitor.visit_generic_arg(a),
+                    AngleBracketedArg::Constraint(c) => visitor.visit_assoc_ty_constraint(c),
+                }
+            }
         }
         GenericArgs::Parenthesized(ref data) => {
             walk_list!(visitor, visit_ty, &data.inputs);
index 68cb1f8585fc721e7dc76aebde1de89f18bbf993..45ee7265c15fcb2b6124bb21dad05fb7ee0391db 100644 (file)
@@ -34,6 +34,7 @@
 #![feature(crate_visibility_modifier)]
 #![feature(marker_trait_attr)]
 #![feature(specialization)]
+#![feature(or_patterns)]
 #![recursion_limit = "256"]
 
 use rustc_ast::ast;
index e996bdac7cb370c7e9813495e06001b600abf352..f15a4555e5f133e4d10a72486de491f4dca70e17 100644 (file)
@@ -366,22 +366,27 @@ fn lower_angle_bracketed_parameter_data(
         param_mode: ParamMode,
         mut itctx: ImplTraitContext<'_, 'hir>,
     ) -> (GenericArgsCtor<'hir>, bool) {
-        let &AngleBracketedArgs { ref args, ref constraints, .. } = data;
-        let has_non_lt_args = args.iter().any(|arg| match arg {
-            ast::GenericArg::Lifetime(_) => false,
-            ast::GenericArg::Type(_) => true,
-            ast::GenericArg::Const(_) => true,
+        let has_non_lt_args = data.args.iter().any(|arg| match arg {
+            AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_)) => false,
+            AngleBracketedArg::Arg(ast::GenericArg::Type(_) | ast::GenericArg::Const(_))
+            | AngleBracketedArg::Constraint(_) => true,
         });
-        (
-            GenericArgsCtor {
-                args: args.iter().map(|a| self.lower_generic_arg(a, itctx.reborrow())).collect(),
-                bindings: self.arena.alloc_from_iter(
-                    constraints.iter().map(|b| self.lower_assoc_ty_constraint(b, itctx.reborrow())),
-                ),
-                parenthesized: false,
-            },
-            !has_non_lt_args && param_mode == ParamMode::Optional,
-        )
+        let args = data
+            .args
+            .iter()
+            .filter_map(|arg| match arg {
+                AngleBracketedArg::Arg(arg) => Some(self.lower_generic_arg(arg, itctx.reborrow())),
+                AngleBracketedArg::Constraint(_) => None,
+            })
+            .collect();
+        let bindings = self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
+            AngleBracketedArg::Constraint(c) => {
+                Some(self.lower_assoc_ty_constraint(c, itctx.reborrow()))
+            }
+            AngleBracketedArg::Arg(_) => None,
+        }));
+        let ctor = GenericArgsCtor { args, bindings, parenthesized: false };
+        (ctor, !has_non_lt_args && param_mode == ParamMode::Optional)
     }
 
     fn lower_parenthesized_parameter_data(
index 885f2f939a653d2f060721c67de747cc933fff45..e6f09a3a6cba55bb0d3373264170fa5112ac4b79 100644 (file)
@@ -639,6 +639,37 @@ fn deny_items(&self, trait_items: &[P<AssocItem>], ident_span: Span) {
             .emit();
         }
     }
+
+    /// Enforce generic args coming before constraints in `<...>` of a path segment.
+    fn check_generic_args_before_constraints(&self, data: &AngleBracketedArgs) {
+        // Early exit in case it's partitioned as it should be.
+        if data.args.iter().is_partitioned(|arg| matches!(arg, AngleBracketedArg::Arg(_))) {
+            return;
+        }
+        // Find all generic argument coming after the first constraint...
+        let mut misplaced_args = Vec::new();
+        let mut first = None;
+        for arg in &data.args {
+            match (arg, first) {
+                (AngleBracketedArg::Arg(a), Some(_)) => misplaced_args.push(a.span()),
+                (AngleBracketedArg::Constraint(c), None) => first = Some(c.span),
+                (AngleBracketedArg::Arg(_), None) | (AngleBracketedArg::Constraint(_), Some(_)) => {
+                }
+            }
+        }
+        // ...and then error:
+        self.err_handler()
+            .struct_span_err(
+                data.span,
+                "constraints in a path segment must come after generic arguments",
+            )
+            .span_labels(
+                misplaced_args,
+                "this generic argument must come before the first constraint",
+            )
+            .span_label(first.unwrap(), "the first constraint is provided here")
+            .emit();
+    }
 }
 
 /// Checks that generic parameters are in the correct order,
@@ -1008,17 +1039,20 @@ fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
     fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
         match *generic_args {
             GenericArgs::AngleBracketed(ref data) => {
-                walk_list!(self, visit_generic_arg, &data.args);
-
-                // Type bindings such as `Item = impl Debug` in `Iterator<Item = Debug>`
-                // are allowed to contain nested `impl Trait`.
-                self.with_impl_trait(None, |this| {
-                    walk_list!(
-                        this,
-                        visit_assoc_ty_constraint_from_generic_args,
-                        &data.constraints
-                    );
-                });
+                self.check_generic_args_before_constraints(data);
+
+                for arg in &data.args {
+                    match arg {
+                        AngleBracketedArg::Arg(arg) => self.visit_generic_arg(arg),
+                        // Type bindings such as `Item = impl Debug` in `Iterator<Item = Debug>`
+                        // are allowed to contain nested `impl Trait`.
+                        AngleBracketedArg::Constraint(constraint) => {
+                            self.with_impl_trait(None, |this| {
+                                this.visit_assoc_ty_constraint_from_generic_args(constraint);
+                            });
+                        }
+                    }
+                }
             }
             GenericArgs::Parenthesized(ref data) => {
                 walk_list!(self, visit_ty, &data.inputs);
index 10081d36754ba43f652593ee3ab13e91a69fdcf4..bfe304419801d5f2c7833170ceb6eaa5012ce23b 100644 (file)
@@ -1,10 +1,12 @@
-#![feature(bindings_after_at)]
 //! The `rustc_ast_passes` crate contains passes which validate the AST in `syntax`
 //! parsed by `rustc_parse` and then lowered, after the passes in this crate,
 //! by `rustc_ast_lowering`.
 //!
 //! The crate also contains other misc AST visitors, e.g. `node_count` and `show_span`.
 
+#![feature(bindings_after_at)]
+#![feature(iter_is_partitioned)]
+
 pub mod ast_validation;
 pub mod feature_gate;
 pub mod node_count;
index 2d6932ffbeedff3bae25e8906837162a165a9041..4aabbe7efbef456866710ed954d93109d96d219d 100644 (file)
@@ -796,31 +796,10 @@ fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params:
         match *args {
             ast::GenericArgs::AngleBracketed(ref data) => {
                 self.s.word("<");
-
-                self.commasep(Inconsistent, &data.args, |s, generic_arg| {
-                    s.print_generic_arg(generic_arg)
+                self.commasep(Inconsistent, &data.args, |s, arg| match arg {
+                    ast::AngleBracketedArg::Arg(a) => s.print_generic_arg(a),
+                    ast::AngleBracketedArg::Constraint(c) => s.print_assoc_constraint(c),
                 });
-
-                let mut comma = !data.args.is_empty();
-
-                for constraint in data.constraints.iter() {
-                    if comma {
-                        self.word_space(",")
-                    }
-                    self.print_ident(constraint.ident);
-                    self.s.space();
-                    match constraint.kind {
-                        ast::AssocTyConstraintKind::Equality { ref ty } => {
-                            self.word_space("=");
-                            self.print_type(ty);
-                        }
-                        ast::AssocTyConstraintKind::Bound { ref bounds } => {
-                            self.print_type_bounds(":", &*bounds);
-                        }
-                    }
-                    comma = true;
-                }
-
                 self.s.word(">")
             }
 
@@ -891,6 +870,20 @@ pub fn print_opt_lifetime(&mut self, lifetime: &Option<ast::Lifetime>) {
         }
     }
 
+    fn print_assoc_constraint(&mut self, constraint: &ast::AssocTyConstraint) {
+        self.print_ident(constraint.ident);
+        self.s.space();
+        match &constraint.kind {
+            ast::AssocTyConstraintKind::Equality { ty } => {
+                self.word_space("=");
+                self.print_type(ty);
+            }
+            ast::AssocTyConstraintKind::Bound { bounds } => {
+                self.print_type_bounds(":", &*bounds);
+            }
+        }
+    }
+
     crate fn print_generic_arg(&mut self, generic_arg: &GenericArg) {
         match generic_arg {
             GenericArg::Lifetime(lt) => self.print_lifetime(*lt),
index 48ceaf5fccd8efb089a57e88dfa324ec8ebd0295..4d89bf79e7c67e16d2171ee3796cda2e3f31a707 100644 (file)
@@ -36,7 +36,8 @@ pub fn path_all(
             idents.into_iter().map(|ident| ast::PathSegment::from_ident(ident.with_span_pos(span))),
         );
         let args = if !args.is_empty() {
-            ast::AngleBracketedArgs { args, constraints: Vec::new(), span }.into()
+            let args = args.into_iter().map(ast::AngleBracketedArg::Arg).collect();
+            ast::AngleBracketedArgs { args, span }.into()
         } else {
             None
         };
index c6f2d1b82fcf484da7c4cc4293d01106edd03d11..eff7dacef7953f21b0ae753d51d8990b27f51985 100644 (file)
@@ -634,17 +634,19 @@ fn involves_impl_trait(ty: &ast::Ty) -> bool {
                         match seg.args.as_ref().map(|generic_arg| &**generic_arg) {
                             None => false,
                             Some(&ast::GenericArgs::AngleBracketed(ref data)) => {
-                                let types = data.args.iter().filter_map(|arg| match arg {
-                                    ast::GenericArg::Type(ty) => Some(ty),
-                                    _ => None,
-                                });
-                                any_involves_impl_trait(types)
-                                    || data.constraints.iter().any(|c| match c.kind {
+                                data.args.iter().any(|arg| match arg {
+                                    ast::AngleBracketedArg::Arg(arg) => match arg {
+                                        ast::GenericArg::Type(ty) => involves_impl_trait(ty),
+                                        ast::GenericArg::Lifetime(_)
+                                        | ast::GenericArg::Const(_) => false,
+                                    },
+                                    ast::AngleBracketedArg::Constraint(c) => match c.kind {
                                         ast::AssocTyConstraintKind::Bound { .. } => true,
                                         ast::AssocTyConstraintKind::Equality { ref ty } => {
                                             involves_impl_trait(ty)
                                         }
-                                    })
+                                    },
+                                })
                             }
                             Some(&ast::GenericArgs::Parenthesized(ref data)) => {
                                 any_involves_impl_trait(data.inputs.iter())
index f88b4fe6ff0a8dfedec357ab9a8802e6797599ce..2320dcba33c97a2f4b02ef5dc3dfee851b8be1f0 100644 (file)
@@ -1,12 +1,9 @@
 use super::ty::{AllowPlus, RecoverQPath};
 use super::{Parser, TokenType};
 use crate::maybe_whole;
-use rustc_ast::ast::{
-    self, AngleBracketedArgs, Ident, ParenthesizedArgs, Path, PathSegment, QSelf,
-};
-use rustc_ast::ast::{
-    AnonConst, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode, GenericArg,
-};
+use rustc_ast::ast::{self, AngleBracketedArg, AngleBracketedArgs, GenericArg, ParenthesizedArgs};
+use rustc_ast::ast::{AnonConst, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode};
+use rustc_ast::ast::{Ident, Path, PathSegment, QSelf};
 use rustc_ast::token::{self, Token};
 use rustc_errors::{pluralize, Applicability, PResult};
 use rustc_span::source_map::{BytePos, Span};
@@ -218,11 +215,11 @@ pub(super) fn parse_path_segment(&mut self, style: PathStyle) -> PResult<'a, Pat
                 let lo = self.token.span;
                 let args = if self.eat_lt() {
                     // `<'a, T, A = U>`
-                    let (args, constraints) =
-                        self.parse_generic_args_with_leading_angle_bracket_recovery(style, lo)?;
+                    let args =
+                        self.parse_angle_args_with_leading_angle_bracket_recovery(style, lo)?;
                     self.expect_gt()?;
                     let span = lo.to(self.prev_token.span);
-                    AngleBracketedArgs { args, constraints, span }.into()
+                    AngleBracketedArgs { args, span }.into()
                 } else {
                     // `(T, U) -> R`
                     let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?;
@@ -251,18 +248,18 @@ pub(super) fn parse_path_segment_ident(&mut self) -> PResult<'a, Ident> {
 
     /// Parses generic args (within a path segment) with recovery for extra leading angle brackets.
     /// For the purposes of understanding the parsing logic of generic arguments, this function
-    /// can be thought of being the same as just calling `self.parse_generic_args()` if the source
+    /// can be thought of being the same as just calling `self.parse_angle_args()` if the source
     /// had the correct amount of leading angle brackets.
     ///
     /// ```ignore (diagnostics)
     /// bar::<<<<T as Foo>::Output>();
     ///      ^^ help: remove extra angle brackets
     /// ```
-    fn parse_generic_args_with_leading_angle_bracket_recovery(
+    fn parse_angle_args_with_leading_angle_bracket_recovery(
         &mut self,
         style: PathStyle,
         lo: Span,
-    ) -> PResult<'a, (Vec<GenericArg>, Vec<AssocTyConstraint>)> {
+    ) -> PResult<'a, Vec<AngleBracketedArg>> {
         // We need to detect whether there are extra leading left angle brackets and produce an
         // appropriate error and suggestion. This cannot be implemented by looking ahead at
         // upcoming tokens for a matching `>` character - if there are unmatched `<` tokens
@@ -337,8 +334,8 @@ fn parse_generic_args_with_leading_angle_bracket_recovery(
         let snapshot = if is_first_invocation { Some(self.clone()) } else { None };
 
         debug!("parse_generic_args_with_leading_angle_bracket_recovery: (snapshotting)");
-        match self.parse_generic_args() {
-            Ok(value) => Ok(value),
+        match self.parse_angle_args() {
+            Ok(args) => Ok(args),
             Err(ref mut e) if is_first_invocation && self.unmatched_angle_bracket_count > 0 => {
                 // Cancel error from being unable to find `>`. We know the error
                 // must have been this due to a non-zero unmatched angle bracket
@@ -381,29 +378,22 @@ fn parse_generic_args_with_leading_angle_bracket_recovery(
                 .emit();
 
                 // Try again without unmatched angle bracket characters.
-                self.parse_generic_args()
+                self.parse_angle_args()
             }
             Err(e) => Err(e),
         }
     }
 
-    /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings,
+    /// Parses (possibly empty) list of generic arguments / associated item constraints,
     /// possibly including trailing comma.
-    fn parse_generic_args(&mut self) -> PResult<'a, (Vec<GenericArg>, Vec<AssocTyConstraint>)> {
+    fn parse_angle_args(&mut self) -> PResult<'a, Vec<AngleBracketedArg>> {
         let mut args = Vec::new();
-        let mut constraints = Vec::new();
-        let mut misplaced_assoc_ty_constraints: Vec<Span> = Vec::new();
-        let mut assoc_ty_constraints: Vec<Span> = Vec::new();
-
-        let args_lo = self.token.span;
-
         loop {
             if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
                 // Parse lifetime argument.
-                args.push(GenericArg::Lifetime(self.expect_lifetime()));
-                misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints);
+                args.push(AngleBracketedArg::Arg(GenericArg::Lifetime(self.expect_lifetime())));
             } else if self.check_ident()
-                && self.look_ahead(1, |t| t == &token::Eq || t == &token::Colon)
+                && self.look_ahead(1, |t| matches!(t.kind, token::Eq | token::Colon))
             {
                 // Parse associated type constraint.
                 let lo = self.token.span;
@@ -411,9 +401,8 @@ fn parse_generic_args(&mut self) -> PResult<'a, (Vec<GenericArg>, Vec<AssocTyCon
                 let kind = if self.eat(&token::Eq) {
                     AssocTyConstraintKind::Equality { ty: self.parse_ty()? }
                 } else if self.eat(&token::Colon) {
-                    AssocTyConstraintKind::Bound {
-                        bounds: self.parse_generic_bounds(Some(self.prev_token.span))?,
-                    }
+                    let bounds = self.parse_generic_bounds(Some(self.prev_token.span))?;
+                    AssocTyConstraintKind::Bound { bounds }
                 } else {
                     unreachable!();
                 };
@@ -425,8 +414,8 @@ fn parse_generic_args(&mut self) -> PResult<'a, (Vec<GenericArg>, Vec<AssocTyCon
                     self.sess.gated_spans.gate(sym::associated_type_bounds, span);
                 }
 
-                constraints.push(AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, kind, span });
-                assoc_ty_constraints.push(span);
+                let constraint = AssocTyConstraint { id: ast::DUMMY_NODE_ID, ident, kind, span };
+                args.push(AngleBracketedArg::Constraint(constraint));
             } else if self.check_const_arg() {
                 // Parse const argument.
                 let expr = if let token::OpenDelim(token::Brace) = self.token.kind {
@@ -453,12 +442,10 @@ fn parse_generic_args(&mut self) -> PResult<'a, (Vec<GenericArg>, Vec<AssocTyCon
                     self.parse_literal_maybe_minus()?
                 };
                 let value = AnonConst { id: ast::DUMMY_NODE_ID, value: expr };
-                args.push(GenericArg::Const(value));
-                misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints);
+                args.push(AngleBracketedArg::Arg(GenericArg::Const(value)));
             } else if self.check_type() {
                 // Parse type argument.
-                args.push(GenericArg::Type(self.parse_ty()?));
-                misplaced_assoc_ty_constraints.append(&mut assoc_ty_constraints);
+                args.push(AngleBracketedArg::Arg(GenericArg::Type(self.parse_ty()?)));
             } else {
                 break;
             }
@@ -468,23 +455,6 @@ fn parse_generic_args(&mut self) -> PResult<'a, (Vec<GenericArg>, Vec<AssocTyCon
             }
         }
 
-        // FIXME: we would like to report this in ast_validation instead, but we currently do not
-        // preserve ordering of generic parameters with respect to associated type binding, so we
-        // lose that information after parsing.
-        if !misplaced_assoc_ty_constraints.is_empty() {
-            let mut err = self.struct_span_err(
-                args_lo.to(self.prev_token.span),
-                "associated type bindings must be declared after generic parameters",
-            );
-            for span in misplaced_assoc_ty_constraints {
-                err.span_label(
-                    span,
-                    "this associated type binding should be moved after the generic parameters",
-                );
-            }
-            err.emit();
-        }
-
-        Ok((args, constraints))
+        Ok(args)
     }
 }
index a80c3b72044ef8319d0752a198011a3a5d4d4358..0829a82b932c377af7a06480143d1f1cd8f0be75 100644 (file)
@@ -783,7 +783,7 @@ fn process_path(&mut self, id: NodeId, path: &'l ast::Path) {
                 match **generic_args {
                     ast::GenericArgs::AngleBracketed(ref data) => {
                         for arg in &data.args {
-                            if let ast::GenericArg::Type(ty) = arg {
+                            if let ast::AngleBracketedArg::Arg(ast::GenericArg::Type(ty)) = arg {
                                 self.visit_ty(ty);
                             }
                         }
@@ -849,7 +849,7 @@ fn process_method_call(
             if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
                 for arg in &data.args {
                     match arg {
-                        ast::GenericArg::Type(ty) => self.visit_ty(ty),
+                        ast::AngleBracketedArg::Arg(ast::GenericArg::Type(ty)) => self.visit_ty(ty),
                         _ => {}
                     }
                 }
diff --git a/src/test/ui/parser/constraints-before-generic-args-syntactic-pass.rs b/src/test/ui/parser/constraints-before-generic-args-syntactic-pass.rs
new file mode 100644 (file)
index 0000000..afbd13e
--- /dev/null
@@ -0,0 +1,9 @@
+// check-pass
+
+#[cfg(FALSE)]
+fn syntax() {
+    foo::<T = u8, T: Ord, String>();
+    foo::<T = u8, 'a, T: Ord>();
+}
+
+fn main() {}
index 82f7ce62b9457804dc80c7c30a9c6d942ec3aaa2..ca30f5f1329d878670a6c63d6ad8035e001bbc15 100644 (file)
@@ -1,6 +1,6 @@
 trait Trait<T> { type Item; }
 
 pub fn test<W, I: Trait<Item=(), W> >() {}
-//~^ ERROR associated type bindings must be declared after generic parameters
+//~^ ERROR constraints in a path segment must come after generic arguments
 
 fn main() { }
index 08b230a14f50ebc8ba6213b4fb9997548a029da4..ee99fe70811dec3d5c61a065a6e903c524cc17f9 100644 (file)
@@ -1,10 +1,11 @@
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/issue-32214.rs:3:25
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/issue-32214.rs:3:24
    |
 LL | pub fn test<W, I: Trait<Item=(), W> >() {}
-   |                         -------^^^
-   |                         |
-   |                         this associated type binding should be moved after the generic parameters
+   |                        ^-------^^-^
+   |                         |        |
+   |                         |        this generic argument must come before the first constraint
+   |                         the first constraint is provided here
 
 error: aborting due to previous error
 
index 6505a97de6e4bfcbb8c556fd01d9476b133e0be5..d9d5351b5c2d401f47b09391b74be06e299d2f8c 100644 (file)
@@ -1,5 +1,3 @@
-// ignore-tidy-linelength
-
 #![allow(warnings)]
 
 // This test verifies that the suggestion to move types before associated type bindings
@@ -25,20 +23,22 @@ trait ThreeWithLifetime<'a, 'b, 'c, T, U, V> {
   type C;
 }
 
-struct A<T, M: One<A=(), T>> { //~ ERROR associated type bindings must be declared after generic parameters
+struct A<T, M: One<A=(), T>> {
+//~^ ERROR constraints in a path segment must come after generic arguments
     m: M,
     t: T,
 }
 
 
 struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
-//~^ ERROR associated type bindings must be declared after generic parameters
+//~^ ERROR constraints in a path segment must come after generic arguments
 //~^^ ERROR type provided when a lifetime was expected
     m: M,
     t: &'a T,
 }
 
-struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> { //~ ERROR associated type bindings must be declared after generic parameters
+struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
+//~^ ERROR constraints in a path segment must come after generic arguments
     m: M,
     t: T,
     u: U,
@@ -46,7 +46,7 @@ struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> { //~ ERROR associated ty
 }
 
 struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
-//~^ ERROR associated type bindings must be declared after generic parameters
+//~^ ERROR constraints in a path segment must come after generic arguments
 //~^^ ERROR type provided when a lifetime was expected
     m: M,
     t: &'a T,
@@ -54,7 +54,8 @@ struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, '
     v: &'c V,
 }
 
-struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> { //~ ERROR associated type bindings must be declared after generic parameters
+struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
+//~^ ERROR constraints in a path segment must come after generic arguments
     m: M,
     t: T,
     u: U,
@@ -62,7 +63,7 @@ struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> { //~ ERROR associated ty
 }
 
 struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
-//~^ ERROR associated type bindings must be declared after generic parameters
+//~^ ERROR constraints in a path segment must come after generic arguments
 //~^^ ERROR lifetime provided when a type was expected
     m: M,
     t: &'a T,
@@ -70,7 +71,8 @@ struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U,
     v: &'c V,
 }
 
-struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> { //~ ERROR associated type bindings must be declared after generic parameters
+struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
+//~^ ERROR constraints in a path segment must come after generic arguments
     m: M,
     t: T,
     u: U,
@@ -78,7 +80,7 @@ struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> { //~ ERROR associated ty
 }
 
 struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
-//~^ ERROR associated type bindings must be declared after generic parameters
+//~^ ERROR constraints in a path segment must come after generic arguments
 //~^^ ERROR lifetime provided when a type was expected
     m: M,
     t: &'a T,
index ac91813f928396bcd5f9b7da113d02464b009520..0225546b9e37b58afdc49345e91901836390b0fa 100644 (file)
@@ -1,81 +1,93 @@
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:28:20
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:26:19
    |
 LL | struct A<T, M: One<A=(), T>> {
-   |                    ----^^^
-   |                    |
-   |                    this associated type binding should be moved after the generic parameters
+   |                   ^----^^-^
+   |                    |     |
+   |                    |     this generic argument must come before the first constraint
+   |                    the first constraint is provided here
 
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:34:37
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:33:36
    |
 LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
-   |                                     ----^^^^^^^
-   |                                     |
-   |                                     this associated type binding should be moved after the generic parameters
+   |                                    ^----^^-^^--^
+   |                                     |     |  |
+   |                                     |     |  this generic argument must come before the first constraint
+   |                                     |     this generic argument must come before the first constraint
+   |                                     the first constraint is provided here
 
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:41:28
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:40:27
    |
 LL | struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
-   |                            ----^^----^^----^^^^^^^^^
-   |                            |     |     |
-   |                            |     |     this associated type binding should be moved after the generic parameters
-   |                            |     this associated type binding should be moved after the generic parameters
-   |                            this associated type binding should be moved after the generic parameters
+   |                           ^----^^^^^^^^^^^^^^-^^-^^-^
+   |                            |                 |  |  |
+   |                            |                 |  |  this generic argument must come before the first constraint
+   |                            |                 |  this generic argument must come before the first constraint
+   |                            |                 this generic argument must come before the first constraint
+   |                            the first constraint is provided here
 
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:48:53
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:48:52
    |
 LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
-   |                                                     ----^^----^^----^^^^^^^^^^^^^^^^^^^^^
-   |                                                     |     |     |
-   |                                                     |     |     this associated type binding should be moved after the generic parameters
-   |                                                     |     this associated type binding should be moved after the generic parameters
-   |                                                     this associated type binding should be moved after the generic parameters
+   |                                                    ^----^^^^^^^^^^^^^^-^^-^^-^^--^^--^^--^
+   |                                                     |                 |  |  |  |   |   |
+   |                                                     |                 |  |  |  |   |   this generic argument must come before the first constraint
+   |                                                     |                 |  |  |  |   this generic argument must come before the first constraint
+   |                                                     |                 |  |  |  this generic argument must come before the first constraint
+   |                                                     |                 |  |  this generic argument must come before the first constraint
+   |                                                     |                 |  this generic argument must come before the first constraint
+   |                                                     |                 this generic argument must come before the first constraint
+   |                                                     the first constraint is provided here
 
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:57:28
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:57:27
    |
 LL | struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
-   |                            ^^^----^^----^^----^^^^^^
-   |                               |     |     |
-   |                               |     |     this associated type binding should be moved after the generic parameters
-   |                               |     this associated type binding should be moved after the generic parameters
-   |                               this associated type binding should be moved after the generic parameters
+   |                           ^^^^----^^^^^^^^^^^^^^-^^-^
+   |                               |                 |  |
+   |                               |                 |  this generic argument must come before the first constraint
+   |                               |                 this generic argument must come before the first constraint
+   |                               the first constraint is provided here
 
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:64:53
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:65:52
    |
 LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
-   |                                                     ^^^^^^^----^^----^^----^^^^^^^^^^^^^^
-   |                                                            |     |     |
-   |                                                            |     |     this associated type binding should be moved after the generic parameters
-   |                                                            |     this associated type binding should be moved after the generic parameters
-   |                                                            this associated type binding should be moved after the generic parameters
+   |                                                    ^^^^^^^^----^^^^^^^^^^^^^^-^^--^^-^^--^
+   |                                                            |                 |  |   |  |
+   |                                                            |                 |  |   |  this generic argument must come before the first constraint
+   |                                                            |                 |  |   this generic argument must come before the first constraint
+   |                                                            |                 |  this generic argument must come before the first constraint
+   |                                                            |                 this generic argument must come before the first constraint
+   |                                                            the first constraint is provided here
 
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:73:28
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:74:27
    |
 LL | struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
-   |                            ^^^----^^----^^^^^----^^^
-   |                               |     |        |
-   |                               |     |        this associated type binding should be moved after the generic parameters
-   |                               |     this associated type binding should be moved after the generic parameters
-   |                               this associated type binding should be moved after the generic parameters
+   |                           ^^^^----^^^^^^^^-^^^^^^^^-^
+   |                               |           |        |
+   |                               |           |        this generic argument must come before the first constraint
+   |                               |           this generic argument must come before the first constraint
+   |                               the first constraint is provided here
 
-error: associated type bindings must be declared after generic parameters
-  --> $DIR/suggest-move-types.rs:80:53
+error: constraints in a path segment must come after generic arguments
+  --> $DIR/suggest-move-types.rs:82:52
    |
 LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
-   |                                                     ^^^^^^^----^^----^^^^^^^^^----^^^^^^^
-   |                                                            |     |            |
-   |                                                            |     |            this associated type binding should be moved after the generic parameters
-   |                                                            |     this associated type binding should be moved after the generic parameters
-   |                                                            this associated type binding should be moved after the generic parameters
+   |                                                    ^^^^^^^^----^^^^^^^^-^^--^^^^^^^^-^^--^
+   |                                                            |           |  |         |  |
+   |                                                            |           |  |         |  this generic argument must come before the first constraint
+   |                                                            |           |  |         this generic argument must come before the first constraint
+   |                                                            |           |  this generic argument must come before the first constraint
+   |                                                            |           this generic argument must come before the first constraint
+   |                                                            the first constraint is provided here
 
 error[E0747]: type provided when a lifetime was expected
-  --> $DIR/suggest-move-types.rs:34:43
+  --> $DIR/suggest-move-types.rs:33:43
    |
 LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
    |                                           ^
@@ -91,7 +103,7 @@ LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U,
    = note: lifetime arguments must be provided before type arguments
 
 error[E0747]: lifetime provided when a type was expected
-  --> $DIR/suggest-move-types.rs:64:56
+  --> $DIR/suggest-move-types.rs:65:56
    |
 LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
    |                                                        ^^
@@ -99,7 +111,7 @@ LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=()
    = note: type arguments must be provided before lifetime arguments
 
 error[E0747]: lifetime provided when a type was expected
-  --> $DIR/suggest-move-types.rs:80:56
+  --> $DIR/suggest-move-types.rs:82:56
    |
 LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
    |                                                        ^^