-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Wrong error message with closures on nightly #42143
Comments
How does one fix this? I have run into this problem as well, and have tried all 8 variants of It looked like, at some point, that |
Introduced in #41488. |
I would like to tackle this if no one already has begun doing it. |
@Emilgardis go ahead! You should add a new test for this case, and you'll need to add an extra check somewhere in |
@estebank Do I add a type_mismatch .rs test or add to an existing test file? |
pr on #42270 |
Also adds test for this case.
ref is expected but not found Fixes rust-lang#42143 Adds E0604 for closure argument type mismatch
when a ref is expected but not found. Adds new error E0622 Fixes rust-lang#42143
Fixes rust-lang#42143. E0281 is totally replaced by E0631. UI tests are updated accordingly.
Friendlier error message for closure argument type mismatch Rebased #42270. Fixes #42143. --- `test.rs`: ```rust fn main() { foo(|_: i32, _: usize| ()); } fn foo<F>(_: F) where F: Fn(&str, usize) {} ``` Before: ``` error[E0281]: type mismatch: `[closure@test.rs:2:9: 2:30]` implements the trait `std::ops::Fn<(i32, usize)>`, but the trait `for<'r> std::ops::Fn<(&'r str, usize)>` is required --> test.rs:2:5 | 2 | foo(|_: i32, _: usize| ()); | ^^^ --------------------- implements `std::ops::Fn<(i32, usize)>` | | | expected &str, found i32 | requires `for<'r> std::ops::Fn<(&'r str, usize)>` | = note: required by `foo` ``` After (early): ``` error[E0631]: type mismatch in closure arguments --> test.rs:2:5 | 2 | foo(|_: i32, _: usize| ()); | ^^^ --------------------- takes arguments of type `i32` and `usize` | | | expected arguments of type `&str` and `usize` | = note: required by `foo` ``` After (current): ``` error[E0631]: type mismatch in closure arguments --> test.rs:2:5 | 2 | foo(|_: i32, _: usize| ()); | ^^^ --------------------- found signature of `fn(i32, usize) -> _` | | | expected signature of `for<'r> fn(&'r str, usize) -> _` | = note: required by `foo` ``` ~~Compiler output has been changed, and a few tests are failing. Help me writing/fixing tests!~~ r? @nikomatsakis
The following example
gives the following error on nightly:
which is wrong (
map
is expecting a function with one argument, which is what this closure is) and the following correct message on stable/beta:The text was updated successfully, but these errors were encountered: