-
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.
On type error of closure call argument, point at earlier calls that a…
…ffected inference Mitigate part of #71209. ``` error[E0308]: mismatched types --> $DIR/unboxed-closures-type-mismatch.rs:30:18 | LL | identity(1u16); | -------- ^^^^ expected `u8`, found `u16` | | | arguments to this function are incorrect | note: expected because the closure was earlier called with an argument of type `u8` --> $DIR/unboxed-closures-type-mismatch.rs:29:18 | LL | identity(1u8); | -------- ^^^ expected because this argument is of type `u8` | | | in this closure call note: closure parameter defined here --> $DIR/unboxed-closures-type-mismatch.rs:28:25 | LL | let identity = |x| x; | ^ help: change the type of the numeric literal from `u16` to `u8` | LL | identity(1u8); | ~~ ```
- Loading branch information
Showing
3 changed files
with
221 additions
and
5 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
32 changes: 30 additions & 2 deletions
32
tests/ui/unboxed-closures/unboxed-closures-type-mismatch.rs
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,7 +1,35 @@ | ||
use std::ops::FnMut; | ||
|
||
pub fn main() { | ||
fn main() { | ||
let mut f = |x: isize, y: isize| -> isize { x + y }; | ||
let z = f(1_usize, 2); //~ ERROR mismatched types | ||
let z = f(1_usize, 2); //~ ERROR mismatched types | ||
println!("{}", z); | ||
let mut g = |x, y| { x + y }; | ||
let y = g(1_i32, 2); | ||
let z = g(1_usize, 2); //~ ERROR mismatched types | ||
println!("{}", z); | ||
} | ||
|
||
trait T { | ||
fn bar(&self) { | ||
let identity = |x| x; | ||
identity(1u8); | ||
identity(1u16); //~ ERROR mismatched types | ||
let identity = |x| x; | ||
identity(&1u8); | ||
identity(&1u16); //~ ERROR mismatched types | ||
} | ||
} | ||
|
||
struct S; | ||
|
||
impl T for S { | ||
fn bar(&self) { | ||
let identity = |x| x; | ||
identity(1u8); | ||
identity(1u16); //~ ERROR mismatched types | ||
let identity = |x| x; | ||
identity(&1u8); | ||
identity(&1u16); //~ ERROR mismatched types | ||
} | ||
} |
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