Skip to content

Commit 24ddca0

Browse files
author
Vincent Prouillet
committed
Update error message for E0243 and E0244
1 parent 4c02363 commit 24ddca0

11 files changed

+55
-25
lines changed

src/librustc_typeck/astconv.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -2248,20 +2248,27 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
22482248
} else {
22492249
"expected"
22502250
};
2251-
span_err!(tcx.sess, span, E0243,
2252-
"wrong number of type arguments: {} {}, found {}",
2253-
expected, required, supplied);
2251+
struct_span_err!(tcx.sess, span, E0243, "wrong number of type arguments")
2252+
.span_label(
2253+
span,
2254+
&format!("{} {} type arguments, found {}", expected, required, supplied)
2255+
)
2256+
.emit();
22542257
} else if supplied > accepted {
2255-
let expected = if required < accepted {
2256-
"expected at most"
2258+
let expected = if required == 0 {
2259+
"expected no".to_string()
2260+
} else if required < accepted {
2261+
format!("expected at most {}", accepted)
22572262
} else {
2258-
"expected"
2263+
format!("expected {}", accepted)
22592264
};
2260-
span_err!(tcx.sess, span, E0244,
2261-
"wrong number of type arguments: {} {}, found {}",
2262-
expected,
2263-
accepted,
2264-
supplied);
2265+
2266+
struct_span_err!(tcx.sess, span, E0244, "wrong number of type arguments")
2267+
.span_label(
2268+
span,
2269+
&format!("{} type arguments, found {}", expected, supplied)
2270+
)
2271+
.emit();
22652272
}
22662273
}
22672274

src/test/compile-fail/E0243.rs

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

1111
struct Foo<T> { x: T }
12-
struct Bar { x: Foo } //~ ERROR E0243
12+
struct Bar { x: Foo }
13+
//~^ ERROR E0243
14+
//~| NOTE expected 1 type arguments, found 0
1315

1416
fn main() {
1517
}

src/test/compile-fail/E0244.rs

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

1111
struct Foo { x: bool }
12-
struct Bar<S, T> { x: Foo<S, T> } //~ ERROR E0244
12+
struct Bar<S, T> { x: Foo<S, T> }
13+
//~^ ERROR E0244
14+
//~| NOTE expected no type arguments, found 2
15+
1316

1417
fn main() {
1518
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ struct Vec<T, A = Heap>(
1616
marker::PhantomData<(T,A)>);
1717

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

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

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

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

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

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

1315
fn main() {}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ 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 wrong number of type arguments: expected 1, found 0
21+
//~| ERROR E0243
22+
//~| NOTE expected 1 type arguments, found 0
2223
//~| ERROR the value of the associated type `Output` (from the trait `std::ops::FnOnce`)
24+
//~| NOTE in this expansion of println!
25+
//~| NOTE in this expansion of println!
26+
//~| NOTE in this expansion of println!
27+
//~| NOTE in this expansion of println!
2328
}

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

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

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

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

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

2023
struct MyStruct2<'a, T: Copy<'a>>;
2124
//~^ ERROR: wrong number of lifetime parameters: expected 0, found 1
2225

26+
2327
fn foo2<'a, T:Copy<'a, U>, U>(x: T) {}
24-
//~^ ERROR: wrong number of type arguments: expected 0, found 1
25-
//~^^ ERROR: wrong number of lifetime parameters: expected 0, found 1
28+
//~^ ERROR E0244
29+
//~| NOTE expected no type arguments, found 1
30+
//~| ERROR: wrong number of lifetime parameters: expected 0, found 1
2631

2732
fn main() {
2833
}

src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs

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

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

src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs

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

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

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

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

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

1920
fn main() {}

0 commit comments

Comments
 (0)