-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix a error suggestion of situation when using placeholder _
as return types on function signature.
#126017
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
Closed
Closed
Fix a error suggestion of situation when using placeholder _
as return types on function signature.
#126017
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
33 changes: 33 additions & 0 deletions
33
tests/ui/return/infer-return-ty-for-fn-sig-issue-125488.fixed
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,33 @@ | ||
//@ run-rustfix | ||
|
||
#[allow(dead_code)] | ||
|
||
fn main() { | ||
struct S<'a>(&'a ()); | ||
|
||
fn f1(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
s | ||
} | ||
|
||
fn f2(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let x = true; | ||
if x { | ||
s | ||
} else { | ||
s | ||
} | ||
} | ||
|
||
fn f3(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
return s; | ||
} | ||
|
||
fn f4(s: S<'_>) -> S<'_> { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let _x = 1; | ||
return s; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/ui/return/infer-return-ty-for-fn-sig-issue-125488.rs
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,33 @@ | ||
//@ run-rustfix | ||
|
||
#[allow(dead_code)] | ||
|
||
fn main() { | ||
struct S<'a>(&'a ()); | ||
|
||
fn f1(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
s | ||
} | ||
|
||
fn f2(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let x = true; | ||
if x { | ||
s | ||
} else { | ||
s | ||
} | ||
} | ||
|
||
fn f3(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
return s; | ||
} | ||
|
||
fn f4(s: S<'_>) -> _ { | ||
//~^ ERROR the placeholder `_` is not allowed | ||
let _x = 1; | ||
return s; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/ui/return/infer-return-ty-for-fn-sig-issue-125488.stderr
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,39 @@ | ||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:8:24 | ||
| | ||
LL | fn f1(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:13:24 | ||
| | ||
LL | fn f2(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:23:24 | ||
| | ||
LL | fn f3(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types | ||
--> $DIR/infer-return-ty-for-fn-sig-issue-125488.rs:28:24 | ||
| | ||
LL | fn f4(s: S<'_>) -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `S<'_>` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0121`. |
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
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.
I'm probably missing something obvious... but I'll ask the dumb question anyway:
Is there a reason we cannot just always use the
keep_erased_ret_ty
here (i.e. always use the ret ty prior to replacing ReErased with ReStatic), rather than doing the work above to compute the value ofkeep_erased_lifetime
and then conditionally choosing whether toret_ty
orkeep_erased_ret_ty
?(I'll give a local build a spin and see if I can find the answer to this myself.)
(if we do need to keep this logic, then I think I might have an easier time digesting this if the
keep_erased_lifetime
computation were factored out into a separate method rather than being defined inline...)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.
Thank you.
Because the changes here only involve a suggestion from E0121.
I did not try understand the subsequent processing process carefully. If keeping the erased lifetime, it will panic in rustc_borrowck.
It seems unreasonable to continue to transfer backwards lifetime
'static
which is not the suggest lifetime'_
. I think this is indeed an issue worthy of further understanding.Uh oh!
There was an error while loading. Please reload this page.
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 seems like the important detail here. I had forgotten about this constraint in rustc_borrowck.
However, I'm not sure that implies that we cannot simplify the logic here. I'm finally following through on making a local build that includes the variation I spoke of above, so hopefully i'll have my answer soon.
Uh oh!
There was an error while loading. Please reload this page.
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.
So, just so I can be concrete about what I am talking about: Here is a diff on your PR that tried out locally:
Felix's attempt to eliminate the `keep_erased_lifetime` boolean
WIth that diff in place, I didn't see any new borrow check failures (I think).
Here's what I did see, in terms of changes to the UI tests:
with these associated deltas to the UI output with my patch applied:
and
So, my question: which is right? What should these two tests be suggesting here?
Uh oh!
There was an error while loading. Please reload this page.
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.
(Also, in case its not clear: I'm not suggesting you just blindly adopt the diff I posted in the previous comment. It was meant as a sketch while I am trying to understand the significance of the different control flow branches in your PR, and it was not meant as an idealized form of the code.)
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.
(a further note: If I go one step further with the diff I posted above, and attempt to actually use the result of
keep_erased_ret_ty.make_suggestable(tcx, false, None)
as the new value that we write intorecovered_ret_ty
, then I do see an ICE during borrowck saying "cannot convert'{erased}
to a region vid". So yes, I do entirely believe that borrowck failures are witnessable here. I'm just trying to make sure we don't overindex on that point....)