forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#106752 - sulami:master, r=estebank
Emit a hint for bad call return types due to generic arguments When the return type of a function call depends on the type of an argument, e.g. ``` fn foo<T>(x: T) -> T { x } ``` and the expected type is set due to either an explicitly typed binding, or because the call to the function is in a tail position without semicolon, the current error implies that the argument in the call has the wrong type. This new hint highlights that the expected type doesn't match the returned type, which matches the argument type, and that that's why we're flagging the argument type. Fixes rust-lang#43608.
- Loading branch information
Showing
13 changed files
with
338 additions
and
0 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 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 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
28 changes: 28 additions & 0 deletions
28
tests/ui/type/wrong-call-return-type-due-to-generic-arg.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
fn function<T>(x: T, y: bool) -> T { | ||
x | ||
} | ||
|
||
struct S {} | ||
impl S { | ||
fn method<T>(&self, x: T) -> T { | ||
x | ||
} | ||
} | ||
|
||
fn wrong_arg_type(x: u32) -> u32 { | ||
x | ||
} | ||
|
||
fn main() { | ||
// Should not trigger. | ||
let x = wrong_arg_type(0u16); //~ ERROR mismatched types | ||
let x: u16 = function(0, 0u8); //~ ERROR mismatched types | ||
|
||
// Should trigger exactly once for the first argument. | ||
let x: u16 = function(0u32, 0u8); //~ ERROR arguments to this function are incorrect | ||
|
||
// Should trigger. | ||
let x: u16 = function(0u32, true); //~ ERROR mismatched types | ||
let x: u16 = (S {}).method(0u32); //~ ERROR mismatched types | ||
function(0u32, 8u8) //~ ERROR arguments to this function are incorrect | ||
} |
Oops, something went wrong.