-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Do not leak type variables from opaque type relation #99928
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
Merged
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 hidden or 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 hidden or 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,13 @@ | ||
// edition:2021 | ||
|
||
fn main() {} | ||
|
||
struct Error; | ||
struct Okay; | ||
|
||
fn foo(t: Result<Okay, Error>) { | ||
t.and_then(|t| -> _ { bar(t) }); | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
async fn bar(t: Okay) {} |
This file contains hidden or 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,21 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-99914.rs:9:27 | ||
| | ||
LL | t.and_then(|t| -> _ { bar(t) }); | ||
| ^^^^^^ expected enum `Result`, found opaque type | ||
| | ||
note: while checking the return type of the `async fn` | ||
--> $DIR/issue-99914.rs:13:23 | ||
| | ||
LL | async fn bar(t: Okay) {} | ||
| ^ checked the `Output` of this `async fn`, found opaque type | ||
= note: expected enum `Result<_, Error>` | ||
found opaque type `impl Future<Output = ()>` | ||
help: try wrapping the expression in `Ok` | ||
| | ||
LL | t.and_then(|t| -> _ { Ok(bar(t)) }); | ||
| +++ + | ||
|
||
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.
This is probably overkill, and we maybe should just do something like
.map_err(|_| TypeError::Sorts(ExpectedFound { expected: a, found: b }))
instead.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.
yea, I was just checking out all error sources in
handle_opaque_types
, and they all boil down to callinginfcx.at(...).eq(x, y)?
in some manner. The issue is that sometimes it's nota
andb
as passed, but another previously registered hidden type. Then you want to report the previous hidden type mismatching the new hidden type.So I guess I'm saying there is a version of this issue where your change will actually not catch it. Trying to produce an example now
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 was unable to reproduce the issue in the defining scope (that doesn't mean it's not possible, just that I gave up for now ^^). I found this absolutely useless diagnostic though: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b80473c86172959763c139535154c3f9
Did some more thinking and I'm wondering now if the
did.is_local()
check should actually beinfcx.opaque_type_origin(did).is_some()
so we only generate those generalized inference vars if we're actually able to handle the opaque type. I was kinda hoping to keep that isolated inhandle_opaque_type
, but that appears to have been a misplaced hope.One more thing is that we're using
eq
insidehandle_opaque_types
when it should probably be using the relation that is callinghandle_opaque_types
. So maybe we could scrap the entire generalization logic and just always invokehandle_opaque_types
by passing the relation as an argument and forwarding to that instead of usingeq
.so many possibilities to try out. Let's merge this PR for now and I'm moving this comment to an issue so we can continue there.