-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
fix incomplete diagnostic notes when closure returns conflicting for genric type #84244
Merged
bors
merged 1 commit into
rust-lang:master
from
ABouttefeux:closure-return-conflict-suggest
Apr 17, 2021
Merged
Changes from all commits
Commits
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
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,16 @@ | ||
// test for issue 84128 | ||
// missing suggestion for similar ADT type with diffetent generic paramenter | ||
// on closure ReturnNoExpression | ||
|
||
struct Foo<T>(T); | ||
|
||
fn main() { | ||
|| { | ||
if false { | ||
return Foo(0); | ||
} | ||
|
||
Foo(()) | ||
//~^ ERROR mismatched types [E0308] | ||
}; | ||
} |
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,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-84128.rs:13:13 | ||
| | ||
LL | Foo(()) | ||
| ^^ expected integer, found `()` | ||
| | ||
note: return type inferred to be `{integer}` here | ||
--> $DIR/issue-84128.rs:10:20 | ||
| | ||
LL | return Foo(0); | ||
| ^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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.
It's not really the 'return type' that's being inferred here
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.
I missed that, thanks. I will fix it.
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.
Shouldn't it either be "return type inferred to be
Foo<{integer}>
here" with span ofFoo(0)
indicated; or else "{integer}
inferred here" (with the span of0
indicated)? (My personal view, FWIW, is that the former is a tad more informative but either seems fine).As it is, it's a bit confusing: essentially "
{integer}
inferred here" butFoo(0)
indicated.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.
I have some issue to solve this I am not sure how do do it. I found that the suggestions is emitted from
compiler\rustc_typeck\src\check\fn_ctxt\checks.rs: check_argument_types
compiler\rustc_typeck\src\check\demand.rs: demand_coerce
compiler\rustc_typeck\src\check\demand.rs: demand_coerce_diag
compiler\rustc_typeck\src\check\demand.rs: emit_coerce_suggestions
is there a way to get the return type from the FnCtxt ?