From 79d32e99481c1eb77f84edc21825aa608fa7ca8a Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Fri, 10 Feb 2017 21:09:54 -0500 Subject: [PATCH 1/2] Remove duplicated "parameter" in E0089 text Closes #39732 --- src/librustc_typeck/check/mod.rs | 7 ++----- src/test/compile-fail/E0089.rs | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 8329d3eeed9e5..fd8bd37e4781c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4566,14 +4566,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } else if !infer_types && types.len() < required_len { let adjust = |len| if len > 1 { "parameters" } else { "parameter" }; let required_param_str = adjust(required_len); - let actual_param_str = adjust(types.len()); struct_span_err!(self.tcx.sess, span, E0089, "too few type parameters provided: \ - expected {} {}, found {} {}", + expected {}, found {}", count(required_len), - required_param_str, - count(types.len()), - actual_param_str) + count(types.len())) .span_label(span, &format!("expected {} type {}", required_len, required_param_str)) .emit(); } diff --git a/src/test/compile-fail/E0089.rs b/src/test/compile-fail/E0089.rs index 9ce36523709e5..b767f129b727c 100644 --- a/src/test/compile-fail/E0089.rs +++ b/src/test/compile-fail/E0089.rs @@ -11,7 +11,6 @@ fn foo() {} fn main() { - foo::(); -//~^ ERROR E0089 -//~| NOTE expected 2 type parameters + foo::(); //~ ERROR expected 2 parameters, found 1 parameter [E0089] + //~| NOTE expected 2 type parameters } From 1c998416ee1eed8c7377c081668651b364cb738e Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Sun, 12 Feb 2017 20:29:51 -0500 Subject: [PATCH 2/2] Standardize lifetime and type parameter count mismatch errors They now always say how many lifetime / type parameters were expected and are explicit about stating "lifetime" or "type" instead of just "parameter". --- src/librustc_typeck/check/mod.rs | 43 +++++++++++-------- src/test/compile-fail/E0087.rs | 10 +++-- src/test/compile-fail/E0088.rs | 10 +++-- src/test/compile-fail/E0089.rs | 2 +- src/test/compile-fail/E0090.rs | 5 ++- .../compile-fail/ufcs-qpath-missing-params.rs | 2 +- 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fd8bd37e4781c..4b36e682f1e82 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4510,28 +4510,32 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } }; - let count = |n| { - format!("{} parameter{}", n, if n == 1 { "" } else { "s" }) + let count_lifetime_params = |n| { + format!("{} lifetime parameter{}", n, if n == 1 { "" } else { "s" }) + }; + let count_type_params = |n| { + format!("{} type parameter{}", n, if n == 1 { "" } else { "s" }) }; // Check provided lifetime parameters. let lifetime_defs = segment.map_or(&[][..], |(_, generics)| &generics.regions); if lifetimes.len() > lifetime_defs.len() { + let expected_text = count_lifetime_params(lifetime_defs.len()); + let actual_text = count_lifetime_params(lifetimes.len()); struct_span_err!(self.tcx.sess, span, E0088, "too many lifetime parameters provided: \ - expected {}, found {}", - count(lifetime_defs.len()), - count(lifetimes.len())) - .span_label(span, &format!("unexpected lifetime parameter{}", - match lifetimes.len() { 1 => "", _ => "s" })) + expected at most {}, found {}", + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) .emit(); } else if lifetimes.len() > 0 && lifetimes.len() < lifetime_defs.len() { + let expected_text = count_lifetime_params(lifetime_defs.len()); + let actual_text = count_lifetime_params(lifetimes.len()); struct_span_err!(self.tcx.sess, span, E0090, "too few lifetime parameters provided: \ - expected {}, found {}", - count(lifetime_defs.len()), - count(lifetimes.len())) - .span_label(span, &format!("too few lifetime parameters")) + expected {}, found {}", + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) .emit(); } @@ -4552,26 +4556,27 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .count(); if types.len() > type_defs.len() { let span = types[type_defs.len()].span; + let expected_text = count_type_params(type_defs.len()); + let actual_text = count_type_params(types.len()); struct_span_err!(self.tcx.sess, span, E0087, "too many type parameters provided: \ expected at most {}, found {}", - count(type_defs.len()), - count(types.len())) - .span_label(span, &format!("too many type parameters")).emit(); + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) + .emit(); // To prevent derived errors to accumulate due to extra // type parameters, we force instantiate_value_path to // use inference variables instead of the provided types. *segment = None; } else if !infer_types && types.len() < required_len { - let adjust = |len| if len > 1 { "parameters" } else { "parameter" }; - let required_param_str = adjust(required_len); + let expected_text = count_type_params(required_len); + let actual_text = count_type_params(types.len()); struct_span_err!(self.tcx.sess, span, E0089, "too few type parameters provided: \ expected {}, found {}", - count(required_len), - count(types.len())) - .span_label(span, &format!("expected {} type {}", required_len, required_param_str)) + expected_text, actual_text) + .span_label(span, &format!("expected {}", expected_text)) .emit(); } diff --git a/src/test/compile-fail/E0087.rs b/src/test/compile-fail/E0087.rs index 7c98de59e2797..0b8150affc0c0 100644 --- a/src/test/compile-fail/E0087.rs +++ b/src/test/compile-fail/E0087.rs @@ -8,9 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo() {} +fn foo() {} +fn bar() {} fn main() { - foo::(); //~ ERROR E0087 - //~^ NOTE too many type parameters + foo::(); //~ ERROR expected at most 0 type parameters, found 1 type parameter [E0087] + //~^ NOTE expected 0 type parameters + + bar::(); //~ ERROR expected at most 1 type parameter, found 2 type parameters [E0087] + //~^ NOTE expected 1 type parameter } diff --git a/src/test/compile-fail/E0088.rs b/src/test/compile-fail/E0088.rs index 9ec0960322410..de188677a1121 100644 --- a/src/test/compile-fail/E0088.rs +++ b/src/test/compile-fail/E0088.rs @@ -12,9 +12,11 @@ fn f() {} fn g<'a>() {} fn main() { - f::<'static>(); //~ ERROR E0088 - //~^ unexpected lifetime parameter + f::<'static>(); + //~^ ERROR expected at most 0 lifetime parameters, found 1 lifetime parameter [E0088] + //~| NOTE expected 0 lifetime parameters - g::<'static, 'static>(); //~ ERROR E0088 - //~^ unexpected lifetime parameters + g::<'static, 'static>(); + //~^ ERROR expected at most 0 lifetime parameters, found 2 lifetime parameters [E0088] + //~| NOTE expected 0 lifetime parameters } diff --git a/src/test/compile-fail/E0089.rs b/src/test/compile-fail/E0089.rs index b767f129b727c..986630d818fff 100644 --- a/src/test/compile-fail/E0089.rs +++ b/src/test/compile-fail/E0089.rs @@ -11,6 +11,6 @@ fn foo() {} fn main() { - foo::(); //~ ERROR expected 2 parameters, found 1 parameter [E0089] + foo::(); //~ ERROR expected 2 type parameters, found 1 type parameter [E0089] //~| NOTE expected 2 type parameters } diff --git a/src/test/compile-fail/E0090.rs b/src/test/compile-fail/E0090.rs index 4600d2d63856a..c37f37031add6 100644 --- a/src/test/compile-fail/E0090.rs +++ b/src/test/compile-fail/E0090.rs @@ -9,7 +9,8 @@ // except according to those terms. fn foo<'a: 'b, 'b: 'a>() {} + fn main() { - foo::<'static>();//~ ERROR E0090 - //~^ too few lifetime parameters + foo::<'static>(); //~ ERROR expected 2 lifetime parameters, found 1 lifetime parameter [E0090] + //~^ NOTE expected 2 lifetime parameters } diff --git a/src/test/compile-fail/ufcs-qpath-missing-params.rs b/src/test/compile-fail/ufcs-qpath-missing-params.rs index a24515c516098..5c108e052160c 100644 --- a/src/test/compile-fail/ufcs-qpath-missing-params.rs +++ b/src/test/compile-fail/ufcs-qpath-missing-params.rs @@ -22,5 +22,5 @@ impl<'a> IntoCow<'a, str> for String { fn main() { ::into_cow("foo".to_string()); - //~^ ERROR too few type parameters provided: expected 1 parameter + //~^ ERROR too few type parameters provided: expected 1 type parameter }