about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-11-10 23:44:44 -0800
committerGitHub <noreply@github.com>2016-11-10 23:44:44 -0800
commit280362a02df97670dd08ed19557c81b504b395c3 (patch)
tree17941eae11c710c6924e6879c1967a48171e3a9d
parent3ac9ec7dfdd3839f03b94e70d7187a30e7b7f759 (diff)
parent12f0b6f2fb5ab0bdad539fc28b12d6161901103f (diff)
downloadrust-280362a02df97670dd08ed19557c81b504b395c3.tar.gz
rust-280362a02df97670dd08ed19557c81b504b395c3.zip
Auto merge of #36615 - sinkuu:e0243_0244, r=nrc
Make E0243/E0244 message consistent with E0107

E0243/E0233 prints `expected {}, found {}` on the span note, while E0107 prints it on the first line. This is confusing when both error occur simultaneously.

This PR makes E0243/E0233 print `expected {}, found {}` on the first line.

Code:

``` rust
struct Foo<'a, 'b> {
    s: &'a str,
    t: &'b str,
}

type Bar<T, U> = Foo<T, U>;
```

rustc output (before):

```
error[E0107]: wrong number of lifetime parameters: expected 2, found 0
 --> test.rs:6:18
  |
6 | type Bar<T, U> = Foo<T, U>;
  |                  ^^^^^^^^^ expected 2 lifetime parameters

error[E0244]: wrong number of type arguments
 --> test.rs:6:18
  |
6 | type Bar<T, U> = Foo<T, U>;
  |                  ^^^^^^^^^ expected no type arguments, found 2
```

rustc output (after):

```
error[E0107]: wrong number of lifetime parameters: expected 2, found 0
 --> /tmp/test.rs:6:18
  |
6 | type Bar<T, U> = Foo<T, U>;
  |                  ^^^^^^^^^ expected 2 lifetime parameters

error[E0244]: wrong number of type arguments: expected 0, found 2
 --> /tmp/test.rs:6:18
  |
6 | type Bar<T, U> = Foo<T, U>;
  |                  ^^^^^^^^^ expected no type arguments
```
-rw-r--r--src/librustc_typeck/astconv.rs27
-rw-r--r--src/librustc_typeck/diagnostics.rs2
-rw-r--r--src/test/compile-fail/E0243.rs4
-rw-r--r--src/test/compile-fail/E0244.rs4
-rw-r--r--src/test/compile-fail/generic-type-less-params-with-defaults.rs4
-rw-r--r--src/test/compile-fail/generic-type-more-params-with-defaults.rs4
-rw-r--r--src/test/compile-fail/issue-14092.rs4
-rw-r--r--src/test/compile-fail/issue-23024.rs2
-rw-r--r--src/test/compile-fail/typeck-builtin-bound-type-parameters.rs16
-rw-r--r--src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs4
-rw-r--r--src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs4
-rw-r--r--src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs4
12 files changed, 42 insertions, 37 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 513b4860d5e..352de11d22d 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -2152,27 +2152,32 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
             "expected"
         };
         let arguments_plural = if required == 1 { "" } else { "s" };
-        struct_span_err!(tcx.sess, span, E0243, "wrong number of type arguments")
-            .span_label(
-                span,
-                &format!("{} {} type argument{}, found {}",
-                         expected, required, arguments_plural, supplied)
-            )
+
+        struct_span_err!(tcx.sess, span, E0243,
+                "wrong number of type arguments: {} {}, found {}",
+                expected, required, supplied)
+            .span_label(span,
+                &format!("{} {} type argument{}",
+                    expected,
+                    required,
+                    arguments_plural))
             .emit();
     } else if supplied > accepted {
-        let expected = if required == 0 {
-            "expected no".to_string()
-        } else if required < accepted {
+        let expected = if required < accepted {
             format!("expected at most {}", accepted)
         } else {
             format!("expected {}", accepted)
         };
         let arguments_plural = if accepted == 1 { "" } else { "s" };
 
-        struct_span_err!(tcx.sess, span, E0244, "wrong number of type arguments")
+        struct_span_err!(tcx.sess, span, E0244,
+                "wrong number of type arguments: {}, found {}",
+                expected, supplied)
             .span_label(
                 span,
-                &format!("{} type argument{}, found {}", expected, arguments_plural, supplied)
+                &format!("{} type argument{}",
+                    if accepted == 0 { "expected no" } else { &expected },
+                    arguments_plural)
             )
             .emit();
     }
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index be012d8976f..f5432c6e0fc 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -1355,7 +1355,7 @@ extern "rust-intrinsic" {
 }
 ```
 
-Please check that you provided the right number of lifetime parameters
+Please check that you provided the right number of type parameters
 and verify with the function declaration in the Rust source code.
 Example:
 
diff --git a/src/test/compile-fail/E0243.rs b/src/test/compile-fail/E0243.rs
index 4434723e12f..d20435a37ff 100644
--- a/src/test/compile-fail/E0243.rs
+++ b/src/test/compile-fail/E0243.rs
@@ -10,8 +10,8 @@
 
 struct Foo<T> { x: T }
 struct Bar { x: Foo }
-                //~^ ERROR E0243
-                //~| NOTE expected 1 type argument, found 0
+                //~^ ERROR wrong number of type arguments: expected 1, found 0 [E0243]
+                //~| NOTE expected 1 type argument
 
 fn main() {
 }
diff --git a/src/test/compile-fail/E0244.rs b/src/test/compile-fail/E0244.rs
index 5678a7fd450..02d4b337894 100644
--- a/src/test/compile-fail/E0244.rs
+++ b/src/test/compile-fail/E0244.rs
@@ -10,8 +10,8 @@
 
 struct Foo { x: bool }
 struct Bar<S, T> { x: Foo<S, T> }
-                      //~^ ERROR E0244
-                      //~| NOTE expected no type arguments, found 2
+                      //~^ ERROR wrong number of type arguments: expected 0, found 2 [E0244]
+                      //~| NOTE expected no type arguments
 
 
 fn main() {
diff --git a/src/test/compile-fail/generic-type-less-params-with-defaults.rs b/src/test/compile-fail/generic-type-less-params-with-defaults.rs
index 9b1f3e51647..9b19e09eeae 100644
--- a/src/test/compile-fail/generic-type-less-params-with-defaults.rs
+++ b/src/test/compile-fail/generic-type-less-params-with-defaults.rs
@@ -17,6 +17,6 @@ struct Vec<T, A = Heap>(
 
 fn main() {
     let _: Vec;
-    //~^ ERROR E0243
-    //~| NOTE expected at least 1 type argument, found 0
+    //~^ ERROR wrong number of type arguments: expected at least 1, found 0 [E0243]
+    //~| NOTE expected at least 1 type argument
 }
diff --git a/src/test/compile-fail/generic-type-more-params-with-defaults.rs b/src/test/compile-fail/generic-type-more-params-with-defaults.rs
index 8f733ddfce1..b5764ef89ab 100644
--- a/src/test/compile-fail/generic-type-more-params-with-defaults.rs
+++ b/src/test/compile-fail/generic-type-more-params-with-defaults.rs
@@ -17,6 +17,6 @@ struct Vec<T, A = Heap>(
 
 fn main() {
     let _: Vec<isize, Heap, bool>;
-    //~^ ERROR E0244
-    //~| NOTE expected at most 2 type arguments, found 3
+    //~^ ERROR wrong number of type arguments: expected at most 2, found 3 [E0244]
+    //~| NOTE expected at most 2 type arguments
 }
diff --git a/src/test/compile-fail/issue-14092.rs b/src/test/compile-fail/issue-14092.rs
index df8707ab823..85dd88e614f 100644
--- a/src/test/compile-fail/issue-14092.rs
+++ b/src/test/compile-fail/issue-14092.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 fn fn1(0: Box) {}
-        //~^ ERROR E0243
-        //~| NOTE expected 1 type argument, found 0
+        //~^ ERROR wrong number of type arguments: expected 1, found 0 [E0243]
+        //~| NOTE expected 1 type argument
 
 fn main() {}
diff --git a/src/test/compile-fail/issue-23024.rs b/src/test/compile-fail/issue-23024.rs
index e266f004317..5d9b49f486c 100644
--- a/src/test/compile-fail/issue-23024.rs
+++ b/src/test/compile-fail/issue-23024.rs
@@ -18,6 +18,6 @@ fn main()
     vfnfer.push(box h);
     println!("{:?}",(vfnfer[0] as Fn)(3));
     //~^ ERROR the precise format of `Fn`-family traits'
-    //~| ERROR E0243
+    //~| ERROR wrong number of type arguments: expected 1, found 0 [E0243]
     //~| ERROR the value of the associated type `Output` (from the trait `std::ops::FnOnce`)
 }
diff --git a/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs b/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs
index 41242a44f58..0d98e044ab0 100644
--- a/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs
+++ b/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs
@@ -9,16 +9,16 @@
 // except according to those terms.
 
 fn foo1<T:Copy<U>, U>(x: T) {}
-//~^ ERROR E0244
-//~| NOTE expected no type arguments, found 1
+//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
+//~| NOTE expected no type arguments
 
 trait Trait: Copy<Send> {}
-//~^ ERROR E0244
-//~| NOTE expected no type arguments, found 1
+//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
+//~| NOTE expected no type arguments
 
 struct MyStruct1<T: Copy<T>>;
-//~^ ERROR E0244
-//~| NOTE expected no type arguments, found 1
+//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
+//~| NOTE expected no type arguments
 
 struct MyStruct2<'a, T: Copy<'a>>;
 //~^ ERROR: wrong number of lifetime parameters: expected 0, found 1
@@ -26,8 +26,8 @@ struct MyStruct2<'a, T: Copy<'a>>;
 
 
 fn foo2<'a, T:Copy<'a, U>, U>(x: T) {}
-//~^ ERROR E0244
-//~| NOTE expected no type arguments, found 1
+//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
+//~| NOTE expected no type arguments
 //~| ERROR: wrong number of lifetime parameters: expected 0, found 1
 //~| NOTE unexpected lifetime parameter
 
diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs
index f40445a030e..ad57752b6f7 100644
--- a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs
+++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs
@@ -17,6 +17,6 @@ struct Foo<'a, T:'a> {
 
 pub fn main() {
     let c: Foo<_, _> = Foo { r: &5 };
-    //~^ ERROR E0244
-    //~| NOTE expected 1 type argument, found 2
+    //~^ ERROR wrong number of type arguments: expected 1, found 2 [E0244]
+    //~| NOTE expected 1 type argument
 }
diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs
index 47898690fcc..f1ecad0056e 100644
--- a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs
+++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs
@@ -17,6 +17,6 @@ struct Foo<'a, T:'a> {
 
 pub fn main() {
     let c: Foo<_, usize> = Foo { r: &5 };
-    //~^ ERROR E0244
-    //~| NOTE expected 1 type argument, found 2
+    //~^ ERROR wrong number of type arguments: expected 1, found 2 [E0244]
+    //~| NOTE expected 1 type argument
 }
diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs
index 50f4f3b98b3..95d78c07501 100644
--- a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs
+++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs
@@ -13,8 +13,8 @@
 trait Trait {}
 
 fn f<F:Trait(isize) -> isize>(x: F) {}
-//~^ ERROR E0244
-//~| NOTE expected no type arguments, found 1
+//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
+//~| NOTE expected no type arguments
 //~| ERROR E0220
 //~| NOTE associated type `Output` not found