forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#114256 - Urgau:fix-issue-114180, r=WaffleLa…
…pkin Fix invalid suggestion for mismatched types in closure arguments This PR fixes the invalid suggestion for mismatched types in closure arguments. The invalid suggestion came from a wrongly created span in the parser for closure arguments that don't have a type specified. Specifically, the span in this case was the last token span, but in the case of tuples, the span represented the last parenthesis instead of the whole tuple, which is fixed by taking the more accurate span of the pattern. There is one unfortunate downside of this fix, it worsens even more the diagnostic for mismatched types in closure args without an explicit type. This happens because there is no correct span for implied inferred type. I tried also fixing this but it's a rabbit hole. Fixes rust-lang#114180
- Loading branch information
Showing
7 changed files
with
78 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// check-fail | ||
|
||
fn main() { | ||
let mut v = vec![(1,)]; | ||
let compare = |(a,), (e,)| todo!(); | ||
v.sort_by(compare); | ||
//~^ ERROR type mismatch in closure arguments | ||
} |
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,22 @@ | ||
error[E0631]: type mismatch in closure arguments | ||
--> $DIR/closure-ref-114180.rs:6:15 | ||
| | ||
LL | let compare = |(a,), (e,)| todo!(); | ||
| ------------ found signature defined here | ||
LL | v.sort_by(compare); | ||
| ------- ^^^^^^^ expected due to this | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: expected closure signature `for<'a, 'b> fn(&'a ({integer},), &'b ({integer},)) -> _` | ||
found closure signature `fn((_,), (_,)) -> _` | ||
note: required by a bound in `slice::<impl [T]>::sort_by` | ||
--> $SRC_DIR/alloc/src/slice.rs:LL:COL | ||
help: consider adjusting the signature so it borrows its arguments | ||
| | ||
LL | let compare = |&(a,), &(e,)| todo!(); | ||
| + + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0631`. |
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