about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_ast_lowering/path.rs6
-rw-r--r--src/librustc_ast_passes/ast_validation.rs6
-rw-r--r--src/librustc_parse/parser/path.rs14
-rw-r--r--src/test/ui/parser/issue-32214.rs2
-rw-r--r--src/test/ui/parser/issue-32214.stderr9
-rw-r--r--src/test/ui/parser/recover-assoc-const-constraint.stderr8
-rw-r--r--src/test/ui/parser/recover-assoc-eq-missing-term.rs2
-rw-r--r--src/test/ui/parser/recover-assoc-eq-missing-term.stderr12
-rw-r--r--src/test/ui/suggestions/suggest-move-types.rs16
-rw-r--r--src/test/ui/suggestions/suggest-move-types.stderr88
10 files changed, 68 insertions, 95 deletions
diff --git a/src/librustc_ast_lowering/path.rs b/src/librustc_ast_lowering/path.rs
index f15a4555e5f..dde73475651 100644
--- a/src/librustc_ast_lowering/path.rs
+++ b/src/librustc_ast_lowering/path.rs
@@ -367,9 +367,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         mut itctx: ImplTraitContext<'_, 'hir>,
     ) -> (GenericArgsCtor<'hir>, bool) {
         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,
+            AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
+            | AngleBracketedArg::Constraint(_) => false,
+            AngleBracketedArg::Arg(ast::GenericArg::Type(_) | ast::GenericArg::Const(_)) => true,
         });
         let args = data
             .args
diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs
index e6f09a3a6cb..592d3bf2e05 100644
--- a/src/librustc_ast_passes/ast_validation.rs
+++ b/src/librustc_ast_passes/ast_validation.rs
@@ -660,12 +660,8 @@ impl<'a> AstValidator<'a> {
         // ...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",
+                "generic arguments must come before the first constraint",
             )
             .span_label(first.unwrap(), "the first constraint is provided here")
             .emit();
diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs
index d23adf4ffe3..9fa7bc027b8 100644
--- a/src/librustc_parse/parser/path.rs
+++ b/src/librustc_parse/parser/path.rs
@@ -439,8 +439,8 @@ impl<'a> Parser<'a> {
             Some(GenericArg::Type(ty)) => return Ok(ty),
             Some(GenericArg::Const(expr)) => {
                 self.struct_span_err(span, "cannot constrain an associated constant to a value")
-                    .span_label(ident.span, "the value constrains this associated constant")
-                    .span_label(expr.value.span, "the value is given in this expression")
+                    .span_label(ident.span, "this associated constant...")
+                    .span_label(expr.value.span, "...cannot be constrained to this value")
                     .emit();
             }
             Some(GenericArg::Lifetime(lt)) => {
@@ -450,15 +450,17 @@ impl<'a> Parser<'a> {
                     .emit();
             }
             None => {
-                self.struct_span_err(span, "missing type to the right of `=`")
+                let after_eq = eq.shrink_to_hi();
+                let before_next = self.token.span.shrink_to_lo();
+                self.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`")
                     .span_suggestion(
-                        span,
+                        self.sess.source_map().next_point(eq).to(before_next),
                         "to constrain the associated type, add a type after `=`",
-                        format!("{} = TheType", ident),
+                        " TheType".to_string(),
                         Applicability::HasPlaceholders,
                     )
                     .span_suggestion(
-                        eq,
+                        eq.to(before_next),
                         &format!("remove the `=` if `{}` is a type", ident),
                         String::new(),
                         Applicability::MaybeIncorrect,
diff --git a/src/test/ui/parser/issue-32214.rs b/src/test/ui/parser/issue-32214.rs
index ca30f5f1329..1379eeb58e6 100644
--- a/src/test/ui/parser/issue-32214.rs
+++ b/src/test/ui/parser/issue-32214.rs
@@ -1,6 +1,6 @@
 trait Trait<T> { type Item; }
 
 pub fn test<W, I: Trait<Item=(), W> >() {}
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
 
 fn main() { }
diff --git a/src/test/ui/parser/issue-32214.stderr b/src/test/ui/parser/issue-32214.stderr
index ee99fe70811..d25d3a09633 100644
--- a/src/test/ui/parser/issue-32214.stderr
+++ b/src/test/ui/parser/issue-32214.stderr
@@ -1,10 +1,9 @@
-error: constraints in a path segment must come after generic arguments
-  --> $DIR/issue-32214.rs:3:24
+error: generic arguments must come before the first constraint
+  --> $DIR/issue-32214.rs:3:34
    |
 LL | pub fn test<W, I: Trait<Item=(), W> >() {}
-   |                        ^-------^^-^
-   |                         |        |
-   |                         |        this generic argument must come before the first constraint
+   |                         -------  ^
+   |                         |
    |                         the first constraint is provided here
 
 error: aborting due to previous error
diff --git a/src/test/ui/parser/recover-assoc-const-constraint.stderr b/src/test/ui/parser/recover-assoc-const-constraint.stderr
index bf617207936..c6733b33faa 100644
--- a/src/test/ui/parser/recover-assoc-const-constraint.stderr
+++ b/src/test/ui/parser/recover-assoc-const-constraint.stderr
@@ -4,8 +4,8 @@ error: cannot constrain an associated constant to a value
 LL |     bar::<Item = 42>();
    |           ----^^^--
    |           |      |
-   |           |      the value is given in this expression
-   |           the value constrains this associated constant
+   |           |      ...cannot be constrained to this value
+   |           this associated constant...
 
 error: cannot constrain an associated constant to a value
   --> $DIR/recover-assoc-const-constraint.rs:4:11
@@ -13,8 +13,8 @@ error: cannot constrain an associated constant to a value
 LL |     bar::<Item = { 42 }>();
    |           ----^^^------
    |           |      |
-   |           |      the value is given in this expression
-   |           the value constrains this associated constant
+   |           |      ...cannot be constrained to this value
+   |           this associated constant...
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/parser/recover-assoc-eq-missing-term.rs b/src/test/ui/parser/recover-assoc-eq-missing-term.rs
index d800df8236b..4b42c44dc64 100644
--- a/src/test/ui/parser/recover-assoc-eq-missing-term.rs
+++ b/src/test/ui/parser/recover-assoc-eq-missing-term.rs
@@ -1,6 +1,6 @@
 #[cfg(FALSE)]
 fn syntax() {
-    bar::<Item = >(); //~ ERROR missing type to the right of `=`
+    bar::<Item =   >(); //~ ERROR missing type to the right of `=`
 }
 
 fn main() {}
diff --git a/src/test/ui/parser/recover-assoc-eq-missing-term.stderr b/src/test/ui/parser/recover-assoc-eq-missing-term.stderr
index 5eb5d6879e9..6e41e139220 100644
--- a/src/test/ui/parser/recover-assoc-eq-missing-term.stderr
+++ b/src/test/ui/parser/recover-assoc-eq-missing-term.stderr
@@ -1,16 +1,16 @@
 error: missing type to the right of `=`
-  --> $DIR/recover-assoc-eq-missing-term.rs:3:11
+  --> $DIR/recover-assoc-eq-missing-term.rs:3:17
    |
-LL |     bar::<Item = >();
-   |           ^^^^^^
+LL |     bar::<Item =   >();
+   |                 ^^^
    |
 help: to constrain the associated type, add a type after `=`
    |
-LL |     bar::<Item = TheType >();
-   |           ^^^^^^^^^^^^^^
+LL |     bar::<Item = TheType>();
+   |                  ^^^^^^^
 help: remove the `=` if `Item` is a type
    |
-LL |     bar::<Item  >();
+LL |     bar::<Item >();
    |               --
 
 error: aborting due to previous error
diff --git a/src/test/ui/suggestions/suggest-move-types.rs b/src/test/ui/suggestions/suggest-move-types.rs
index d9d5351b5c2..27930626a62 100644
--- a/src/test/ui/suggestions/suggest-move-types.rs
+++ b/src/test/ui/suggestions/suggest-move-types.rs
@@ -24,21 +24,21 @@ trait ThreeWithLifetime<'a, 'b, 'c, T, U, V> {
 }
 
 struct A<T, M: One<A=(), T>> {
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
     m: M,
     t: T,
 }
 
 
 struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
 //~^^ 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 constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
     m: M,
     t: T,
     u: U,
@@ -46,7 +46,7 @@ struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
 }
 
 struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
 //~^^ ERROR type provided when a lifetime was expected
     m: M,
     t: &'a T,
@@ -55,7 +55,7 @@ struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, '
 }
 
 struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
     m: M,
     t: T,
     u: U,
@@ -63,7 +63,7 @@ struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
 }
 
 struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
 //~^^ ERROR lifetime provided when a type was expected
     m: M,
     t: &'a T,
@@ -72,7 +72,7 @@ struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U,
 }
 
 struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
     m: M,
     t: T,
     u: U,
@@ -80,7 +80,7 @@ struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
 }
 
 struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
-//~^ ERROR constraints in a path segment must come after generic arguments
+//~^ ERROR generic arguments must come before the first constraint
 //~^^ ERROR lifetime provided when a type was expected
     m: M,
     t: &'a T,
diff --git a/src/test/ui/suggestions/suggest-move-types.stderr b/src/test/ui/suggestions/suggest-move-types.stderr
index 0225546b9e3..a0a8c3fc3ba 100644
--- a/src/test/ui/suggestions/suggest-move-types.stderr
+++ b/src/test/ui/suggestions/suggest-move-types.stderr
@@ -1,89 +1,65 @@
-error: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:26:19
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:26:26
    |
 LL | struct A<T, M: One<A=(), T>> {
-   |                   ^----^^-^
-   |                    |     |
-   |                    |     this generic argument must come before the first constraint
+   |                    ----  ^
+   |                    |
    |                    the first constraint is provided here
 
-error: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:33:36
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:33:43
    |
 LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
-   |                                    ^----^^-^^--^
-   |                                     |     |  |
-   |                                     |     |  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: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:40:27
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:40:46
    |
 LL | struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> {
-   |                           ^----^^^^^^^^^^^^^^-^^-^^-^
-   |                            |                 |  |  |
-   |                            |                 |  |  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: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:48:52
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:48:71
    |
 LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
-   |                                                    ^----^^^^^^^^^^^^^^-^^-^^-^^--^^--^^--^
-   |                                                     |                 |  |  |  |   |   |
-   |                                                     |                 |  |  |  |   |   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: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:57:27
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:57:49
    |
 LL | struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> {
-   |                           ^^^^----^^^^^^^^^^^^^^-^^-^
-   |                               |                 |  |
-   |                               |                 |  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: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:65:52
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:65:78
    |
 LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
-   |                                                    ^^^^^^^^----^^^^^^^^^^^^^^-^^--^^-^^--^
-   |                                                            |                 |  |   |  |
-   |                                                            |                 |  |   |  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: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:74:27
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:74:43
    |
 LL | struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> {
-   |                           ^^^^----^^^^^^^^-^^^^^^^^-^
-   |                               |           |        |
-   |                               |           |        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: constraints in a path segment must come after generic arguments
-  --> $DIR/suggest-move-types.rs:82:52
+error: generic arguments must come before the first constraint
+  --> $DIR/suggest-move-types.rs:82:72
    |
 LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
-   |                                                    ^^^^^^^^----^^^^^^^^-^^--^^^^^^^^-^^--^
-   |                                                            |           |  |         |  |
-   |                                                            |           |  |         |  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