Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add long error for E0631 and update ui tests. #66979

Merged
merged 3 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/librustc_error_codes/error_codes/E0631.md
Original file line number Diff line number Diff line change
@@ -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<String>) -> Vec<bool> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using map on a String, what about using a "simpler" code like this one:

fn foo<F: Fn(i32)>(f: F) {
}

fn main() {
    foo(|x: &str| {});
}

?

string_vec
.iter()
.map(|arg: &i32| arg.eq("Test String"))
.collect()
}
```

The closure passed to `map` expects a `&String` argument, since `some_vec`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd make this explanation simpler to follow as well.

has the type `Vec<String>`.
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<String>) -> Vec<bool> {
string_vec
.iter()
.map(|arg| arg.eq("Test String"))
.collect()
}
```
1 change: 1 addition & 0 deletions src/test/ui/anonymous-higher-ranked-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ LL | fn h2<F>(_: F) where F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(),

error: aborting due to 11 previous errors

For more information about this error, try `rustc --explain E0631`.
3 changes: 2 additions & 1 deletion src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
3 changes: 2 additions & 1 deletion src/test/ui/closures/issue-41366.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ LL | (&|_|()) as &dyn for<'x> Fn(<u32 as T<'x>>::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`.
3 changes: 2 additions & 1 deletion src/test/ui/issues/issue-43623.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ LL | break_me::<Type, fn(_)>;

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`.
3 changes: 2 additions & 1 deletion src/test/ui/issues/issue-60283.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/mismatched_types/E0631.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ LL | bar(f);

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0631`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
3 changes: 2 additions & 1 deletion src/test/ui/mismatched_types/closure-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/mismatched_types/fn-variance-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
3 changes: 2 additions & 1 deletion src/test/ui/mismatched_types/issue-36053-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.