-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
When encountering unexpected closure return type, point at return type/expression #132156
Open
estebank
wants to merge
5
commits into
rust-lang:master
Choose a base branch
from
estebank:closure-return
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9cfb2ff
When encountering unexpected closure return type, point at return typ…
estebank 0b489d7
On E0271 for a closure behind a binding, point at binding in call too
estebank 5198b68
Add closure labels
estebank 000d338
Remove `unwrap()`s
estebank 63ae24a
review comment: change `span` argument
estebank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -652,6 +652,7 @@ pub fn check_function_signature<'tcx>( | |
}))), | ||
err, | ||
false, | ||
None, | ||
); | ||
return Err(diag.emit()); | ||
} | ||
|
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 |
---|---|---|
|
@@ -1119,6 +1119,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
Some(self.param_env.and(trace.values)), | ||
e, | ||
true, | ||
None, | ||
); | ||
} | ||
} | ||
|
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,25 @@ | ||
use std::error::Error; | ||
use std::process::exit; | ||
|
||
fn foo<F>(f: F) -> () | ||
where | ||
F: FnOnce() -> Result<(), Box<dyn Error>>, | ||
{ | ||
f().or_else(|e| -> ! { //~ ERROR to be a closure that returns | ||
eprintln!("{:?}", e); | ||
exit(1) | ||
}); | ||
} | ||
|
||
fn bar<F>(f: F) -> () | ||
where | ||
F: FnOnce() -> Result<(), Box<dyn Error>>, | ||
{ | ||
let c = |e| -> ! { //~ ERROR to be a closure that returns | ||
eprintln!("{:?}", e); | ||
exit(1) | ||
}; | ||
f().or_else(c); | ||
} | ||
|
||
fn main() {} |
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,37 @@ | ||
error[E0271]: expected `{closure@return-type-doesnt-match-bound.rs:8:17}` to be a closure that returns `Result<(), _>`, but it returns `!` | ||
--> $DIR/return-type-doesnt-match-bound.rs:8:24 | ||
| | ||
LL | f().or_else(|e| -> ! { | ||
| ------- -------^ | ||
| | | | | ||
| | | expected `Result<(), _>`, found `!` | ||
| | this closure | ||
| required by a bound introduced by this call | ||
| | ||
= note: expected enum `Result<(), _>` | ||
found type `!` | ||
note: required by a bound in `Result::<T, E>::or_else` | ||
--> $SRC_DIR/core/src/result.rs:LL:COL | ||
|
||
error[E0271]: expected `{closure@return-type-doesnt-match-bound.rs:18:13}` to be a closure that returns `Result<(), _>`, but it returns `!` | ||
--> $DIR/return-type-doesnt-match-bound.rs:18:20 | ||
| | ||
LL | let c = |e| -> ! { | ||
| -------^ | ||
| | | | ||
| | expected `Result<(), _>`, found `!` | ||
| this closure | ||
... | ||
LL | f().or_else(c); | ||
| ------- - closure used here | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: expected enum `Result<(), _>` | ||
found type `!` | ||
note: required by a bound in `Result::<T, E>::or_else` | ||
--> $SRC_DIR/core/src/result.rs:LL:COL | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that
.span
and.span()
do different things! This is kinda what I meant when I said that these APIs are unmaintainable today.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fix the regression in spans, afaict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#132243 removes the need for that pointless/confusing method.