Skip to content

Commit 280362a

Browse files
authoredNov 11, 2016
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 ```
2 parents 3ac9ec7 + 12f0b6f commit 280362a

12 files changed

+42
-37
lines changed
 

‎src/librustc_typeck/astconv.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -2152,27 +2152,32 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
21522152
"expected"
21532153
};
21542154
let arguments_plural = if required == 1 { "" } else { "s" };
2155-
struct_span_err!(tcx.sess, span, E0243, "wrong number of type arguments")
2156-
.span_label(
2157-
span,
2158-
&format!("{} {} type argument{}, found {}",
2159-
expected, required, arguments_plural, supplied)
2160-
)
2155+
2156+
struct_span_err!(tcx.sess, span, E0243,
2157+
"wrong number of type arguments: {} {}, found {}",
2158+
expected, required, supplied)
2159+
.span_label(span,
2160+
&format!("{} {} type argument{}",
2161+
expected,
2162+
required,
2163+
arguments_plural))
21612164
.emit();
21622165
} else if supplied > accepted {
2163-
let expected = if required == 0 {
2164-
"expected no".to_string()
2165-
} else if required < accepted {
2166+
let expected = if required < accepted {
21662167
format!("expected at most {}", accepted)
21672168
} else {
21682169
format!("expected {}", accepted)
21692170
};
21702171
let arguments_plural = if accepted == 1 { "" } else { "s" };
21712172

2172-
struct_span_err!(tcx.sess, span, E0244, "wrong number of type arguments")
2173+
struct_span_err!(tcx.sess, span, E0244,
2174+
"wrong number of type arguments: {}, found {}",
2175+
expected, supplied)
21732176
.span_label(
21742177
span,
2175-
&format!("{} type argument{}, found {}", expected, arguments_plural, supplied)
2178+
&format!("{} type argument{}",
2179+
if accepted == 0 { "expected no" } else { &expected },
2180+
arguments_plural)
21762181
)
21772182
.emit();
21782183
}

‎src/librustc_typeck/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ extern "rust-intrinsic" {
13551355
}
13561356
```
13571357
1358-
Please check that you provided the right number of lifetime parameters
1358+
Please check that you provided the right number of type parameters
13591359
and verify with the function declaration in the Rust source code.
13601360
Example:
13611361

‎src/test/compile-fail/E0243.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
struct Foo<T> { x: T }
1212
struct Bar { x: Foo }
13-
//~^ ERROR E0243
14-
//~| NOTE expected 1 type argument, found 0
13+
//~^ ERROR wrong number of type arguments: expected 1, found 0 [E0243]
14+
//~| NOTE expected 1 type argument
1515

1616
fn main() {
1717
}

‎src/test/compile-fail/E0244.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
struct Foo { x: bool }
1212
struct Bar<S, T> { x: Foo<S, T> }
13-
//~^ ERROR E0244
14-
//~| NOTE expected no type arguments, found 2
13+
//~^ ERROR wrong number of type arguments: expected 0, found 2 [E0244]
14+
//~| NOTE expected no type arguments
1515

1616

1717
fn main() {

‎src/test/compile-fail/generic-type-less-params-with-defaults.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ struct Vec<T, A = Heap>(
1717

1818
fn main() {
1919
let _: Vec;
20-
//~^ ERROR E0243
21-
//~| NOTE expected at least 1 type argument, found 0
20+
//~^ ERROR wrong number of type arguments: expected at least 1, found 0 [E0243]
21+
//~| NOTE expected at least 1 type argument
2222
}

‎src/test/compile-fail/generic-type-more-params-with-defaults.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ struct Vec<T, A = Heap>(
1717

1818
fn main() {
1919
let _: Vec<isize, Heap, bool>;
20-
//~^ ERROR E0244
21-
//~| NOTE expected at most 2 type arguments, found 3
20+
//~^ ERROR wrong number of type arguments: expected at most 2, found 3 [E0244]
21+
//~| NOTE expected at most 2 type arguments
2222
}

‎src/test/compile-fail/issue-14092.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
fn fn1(0: Box) {}
12-
//~^ ERROR E0243
13-
//~| NOTE expected 1 type argument, found 0
12+
//~^ ERROR wrong number of type arguments: expected 1, found 0 [E0243]
13+
//~| NOTE expected 1 type argument
1414

1515
fn main() {}

‎src/test/compile-fail/issue-23024.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ fn main()
1818
vfnfer.push(box h);
1919
println!("{:?}",(vfnfer[0] as Fn)(3));
2020
//~^ ERROR the precise format of `Fn`-family traits'
21-
//~| ERROR E0243
21+
//~| ERROR wrong number of type arguments: expected 1, found 0 [E0243]
2222
//~| ERROR the value of the associated type `Output` (from the trait `std::ops::FnOnce`)
2323
}

‎src/test/compile-fail/typeck-builtin-bound-type-parameters.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@
99
// except according to those terms.
1010

1111
fn foo1<T:Copy<U>, U>(x: T) {}
12-
//~^ ERROR E0244
13-
//~| NOTE expected no type arguments, found 1
12+
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
13+
//~| NOTE expected no type arguments
1414

1515
trait Trait: Copy<Send> {}
16-
//~^ ERROR E0244
17-
//~| NOTE expected no type arguments, found 1
16+
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
17+
//~| NOTE expected no type arguments
1818

1919
struct MyStruct1<T: Copy<T>>;
20-
//~^ ERROR E0244
21-
//~| NOTE expected no type arguments, found 1
20+
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
21+
//~| NOTE expected no type arguments
2222

2323
struct MyStruct2<'a, T: Copy<'a>>;
2424
//~^ ERROR: wrong number of lifetime parameters: expected 0, found 1
2525
//~| NOTE unexpected lifetime parameter
2626

2727

2828
fn foo2<'a, T:Copy<'a, U>, U>(x: T) {}
29-
//~^ ERROR E0244
30-
//~| NOTE expected no type arguments, found 1
29+
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
30+
//~| NOTE expected no type arguments
3131
//~| ERROR: wrong number of lifetime parameters: expected 0, found 1
3232
//~| NOTE unexpected lifetime parameter
3333

‎src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ struct Foo<'a, T:'a> {
1717

1818
pub fn main() {
1919
let c: Foo<_, _> = Foo { r: &5 };
20-
//~^ ERROR E0244
21-
//~| NOTE expected 1 type argument, found 2
20+
//~^ ERROR wrong number of type arguments: expected 1, found 2 [E0244]
21+
//~| NOTE expected 1 type argument
2222
}

‎src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ struct Foo<'a, T:'a> {
1717

1818
pub fn main() {
1919
let c: Foo<_, usize> = Foo { r: &5 };
20-
//~^ ERROR E0244
21-
//~| NOTE expected 1 type argument, found 2
20+
//~^ ERROR wrong number of type arguments: expected 1, found 2 [E0244]
21+
//~| NOTE expected 1 type argument
2222
}

‎src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
trait Trait {}
1414

1515
fn f<F:Trait(isize) -> isize>(x: F) {}
16-
//~^ ERROR E0244
17-
//~| NOTE expected no type arguments, found 1
16+
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0244]
17+
//~| NOTE expected no type arguments
1818
//~| ERROR E0220
1919
//~| NOTE associated type `Output` not found
2020

0 commit comments

Comments
 (0)
Please sign in to comment.