-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #44735 - tirr-c:issue-42143, r=arielb1
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: `[[email protected]: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
- Loading branch information
Showing
14 changed files
with
245 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error[E0631]: type mismatch in closure arguments | ||
--> $DIR/E0631.rs:17:5 | ||
| | ||
17 | foo(|_: isize| {}); | ||
| ^^^ ------------- found signature of `fn(isize) -> _` | ||
| | | ||
| expected signature of `fn(usize) -> _` | ||
| | ||
= note: required by `foo` | ||
|
||
error[E0631]: type mismatch in closure arguments | ||
--> $DIR/E0631.rs:18:5 | ||
| | ||
18 | bar(|_: isize| {}); | ||
| ^^^ ------------- found signature of `fn(isize) -> _` | ||
| | | ||
| expected signature of `fn(usize) -> _` | ||
| | ||
= note: required by `bar` | ||
|
||
error[E0631]: type mismatch in function arguments | ||
--> $DIR/E0631.rs:19:5 | ||
| | ||
19 | foo(f); | ||
| ^^^ | ||
| | | ||
| expected signature of `fn(usize) -> _` | ||
| found signature of `fn(u64) -> _` | ||
| | ||
= note: required by `foo` | ||
|
||
error[E0631]: type mismatch in function arguments | ||
--> $DIR/E0631.rs:20:5 | ||
| | ||
20 | bar(f); | ||
| ^^^ | ||
| | | ||
| expected signature of `fn(usize) -> _` | ||
| found signature of `fn(u64) -> _` | ||
| | ||
= note: required by `bar` | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
error[E0593]: closure takes 0 arguments but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:12:15 | ||
--> $DIR/closure-arg-count.rs:15:15 | ||
| | ||
12 | [1, 2, 3].sort_by(|| panic!()); | ||
15 | [1, 2, 3].sort_by(|| panic!()); | ||
| ^^^^^^^ ----------- takes 0 arguments | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error[E0593]: closure takes 1 argument but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:13:15 | ||
--> $DIR/closure-arg-count.rs:16:15 | ||
| | ||
13 | [1, 2, 3].sort_by(|tuple| panic!()); | ||
16 | [1, 2, 3].sort_by(|tuple| panic!()); | ||
| ^^^^^^^ ---------------- takes 1 argument | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/closure-arg-count.rs:14:24 | ||
--> $DIR/closure-arg-count.rs:17:24 | ||
| | ||
14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
17 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
| ^^^^^^^^^^^^^^^ expected &{integer}, found tuple | ||
| | ||
= note: expected type `&{integer}` | ||
found type `(_, _)` | ||
|
||
error[E0593]: closure takes 1 argument but 2 arguments are required | ||
--> $DIR/closure-arg-count.rs:14:15 | ||
--> $DIR/closure-arg-count.rs:17:15 | ||
| | ||
14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
17 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); | ||
| ^^^^^^^ -------------------------- takes 1 argument | ||
| | | ||
| expected closure that takes 2 arguments | ||
|
||
error: aborting due to 4 previous errors | ||
error[E0593]: closure takes 0 arguments but 1 argument is required | ||
--> $DIR/closure-arg-count.rs:18:5 | ||
| | ||
18 | f(|| panic!()); | ||
| ^ ----------- takes 0 arguments | ||
| | | ||
| expected closure that takes 1 argument | ||
| | ||
= note: required by `f` | ||
|
||
error: aborting due to 5 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
let a = [(1u32, 2u32)]; | ||
a.iter().map(|_: (u32, u32)| 45); | ||
a.iter().map(|_: &(u16, u16)| 45); | ||
a.iter().map(|_: (u16, u16)| 45); | ||
} | ||
|
||
fn baz<F: Fn(*mut &u32)>(_: F) {} | ||
fn _test<'a>(f: fn(*mut &'a u32)) { | ||
baz(f); | ||
} |
Oops, something went wrong.