From 7693bb9e1d122bea1b0645dcc201c6ed79c910e2 Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Mon, 2 Dec 2019 21:52:04 -0500 Subject: [PATCH] Add long error for E0631 and update ui tests. --- src/librustc_error_codes/error_codes.rs | 2 +- src/librustc_error_codes/error_codes/E0631.md | 29 +++++++++++++++++++ .../anonymous-higher-ranked-lifetime.stderr | 1 + .../expect-fn-supply-fn.stderr | 3 +- .../expect-infer-var-appearing-twice.stderr | 1 + src/test/ui/closures/issue-41366.stderr | 3 +- src/test/ui/issues/issue-43623.stderr | 3 +- src/test/ui/issues/issue-60283.stderr | 3 +- src/test/ui/mismatched_types/E0631.stderr | 1 + .../closure-arg-type-mismatch.stderr | 3 +- .../mismatched_types/closure-mismatch.stderr | 3 +- .../ui/mismatched_types/fn-variance-1.stderr | 1 + .../ui/mismatched_types/issue-36053-2.stderr | 3 +- .../unboxed-closures-vtable-mismatch.stderr | 1 + 14 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/librustc_error_codes/error_codes/E0631.md diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 7f111b42403..9e4b704170b 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -347,6 +347,7 @@ E0622: include_str!("./error_codes/E0622.md"), E0623: include_str!("./error_codes/E0623.md"), E0624: include_str!("./error_codes/E0624.md"), E0626: include_str!("./error_codes/E0626.md"), +E0631: include_str!("./error_codes/E0631.md"), E0633: include_str!("./error_codes/E0633.md"), E0635: include_str!("./error_codes/E0635.md"), E0636: include_str!("./error_codes/E0636.md"), @@ -580,7 +581,6 @@ E0745: include_str!("./error_codes/E0745.md"), // rustc_const_unstable attribute must be paired with stable/unstable // attribute E0630, - E0631, // type mismatch in closure arguments E0632, // cannot provide explicit generic arguments when `impl Trait` is // used in argument position E0634, // type has conflicting packed representaton hints diff --git a/src/librustc_error_codes/error_codes/E0631.md b/src/librustc_error_codes/error_codes/E0631.md new file mode 100644 index 00000000000..ad419f82250 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0631.md @@ -0,0 +1,29 @@ +This error indicates a type mismatch in closure arguments. + +Erroneous code example: + +```compile_fail,E0631 +fn test_strings(string_vec: Vec) -> Vec { + string_vec + .iter() + .map(|arg: &i32| arg.eq("Test String")) + .collect() +} +``` + +The closure passed to `map` expects a `&String` argument, since `some_vec` +has the type `Vec`. +However, the closure argument is annotated as an `&i32`, which does not match +the type of the iterable. + +This can be resolved by changing the type annotation or removing it entirely +if it can be inferred. + +``` +fn test_strings(string_vec: Vec) -> Vec { + string_vec + .iter() + .map(|arg| arg.eq("Test String")) + .collect() +} +``` diff --git a/src/test/ui/anonymous-higher-ranked-lifetime.stderr b/src/test/ui/anonymous-higher-ranked-lifetime.stderr index 9be44c7f448..c6d9a61bdd9 100644 --- a/src/test/ui/anonymous-higher-ranked-lifetime.stderr +++ b/src/test/ui/anonymous-higher-ranked-lifetime.stderr @@ -121,3 +121,4 @@ LL | fn h2(_: F) where F: for<'t0> Fn(&(), Box, &'t0 (), fn(&(), error: aborting due to 11 previous errors +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr index a15444207f5..00333958468 100644 --- a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr +++ b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr @@ -77,4 +77,5 @@ LL | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| { error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0308, E0631. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr b/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr index 9fbe95a9c39..1c6564ee426 100644 --- a/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr +++ b/src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr @@ -13,3 +13,4 @@ LL | with_closure(|x: u32, y: i32| { error: aborting due to previous error +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/closures/issue-41366.stderr b/src/test/ui/closures/issue-41366.stderr index 91d26efbc4f..2f2871e9f0e 100644 --- a/src/test/ui/closures/issue-41366.stderr +++ b/src/test/ui/closures/issue-41366.stderr @@ -19,4 +19,5 @@ LL | (&|_|()) as &dyn for<'x> Fn(>::V); error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/issues/issue-43623.stderr b/src/test/ui/issues/issue-43623.stderr index 2c57b8585d9..d90eb53f900 100644 --- a/src/test/ui/issues/issue-43623.stderr +++ b/src/test/ui/issues/issue-43623.stderr @@ -25,4 +25,5 @@ LL | break_me::; error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr index 69c1d85e4e1..d13dcd54a47 100644 --- a/src/test/ui/issues/issue-60283.stderr +++ b/src/test/ui/issues/issue-60283.stderr @@ -27,4 +27,5 @@ LL | foo((), drop) error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/mismatched_types/E0631.stderr b/src/test/ui/mismatched_types/E0631.stderr index 88c1efdbb90..06f5c058f81 100644 --- a/src/test/ui/mismatched_types/E0631.stderr +++ b/src/test/ui/mismatched_types/E0631.stderr @@ -46,3 +46,4 @@ LL | bar(f); error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr index 85cad61210e..ed502824712 100644 --- a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr +++ b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr @@ -45,4 +45,5 @@ LL | baz(f); error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/mismatched_types/closure-mismatch.stderr b/src/test/ui/mismatched_types/closure-mismatch.stderr index fd2b9f3c66b..f3874c0907b 100644 --- a/src/test/ui/mismatched_types/closure-mismatch.stderr +++ b/src/test/ui/mismatched_types/closure-mismatch.stderr @@ -24,4 +24,5 @@ LL | baz(|_| ()); error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0271`. +Some errors have detailed explanations: E0271, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/mismatched_types/fn-variance-1.stderr b/src/test/ui/mismatched_types/fn-variance-1.stderr index 1a82dd53edc..88c92661994 100644 --- a/src/test/ui/mismatched_types/fn-variance-1.stderr +++ b/src/test/ui/mismatched_types/fn-variance-1.stderr @@ -24,3 +24,4 @@ LL | apply(&mut 3, takes_imm); error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index 72f3220cc1a..da018aa8948 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -18,4 +18,5 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0599`. +Some errors have detailed explanations: E0599, E0631. +For more information about an error, try `rustc --explain E0599`. diff --git a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr index 2daf4781c7e..3c999f200d9 100644 --- a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr +++ b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr @@ -12,3 +12,4 @@ LL | let z = call_it(3, f); error: aborting due to previous error +For more information about this error, try `rustc --explain E0631`.