-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Taking an argument hides lifetime error #77912
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
Comments
To be clear, I believe the bug occurs in the first example; I think the error in the second is correct. |
When did this regress? |
Both cases look correct to me. The first one uses lifetime elision. |
Just finished bisecting :) searched nightlies: from nightly-2019-01-01 to nightly-2020-10-13 bisected with cargo-bisect-rustc v0.5.2Host triple: x86_64-apple-darwin cargo bisect-rustc --preserve --regress=success --start=2019-01-01 |
How so? They should be no different in the errors they produce. This is the diff between them: -fn foo(s: &i32) -> &i32 {
+fn foo() -> &i32 {
&0
} |
Also the bitcode commit :/ |
What was the behavior before that PR? This documents the behavior: https://doc.rust-lang.org/reference/lifetime-elision.html?highlight=lifetime,elision#lifetime-elision-in-functions |
I'm not sure; Godbolt is showing the same behavior throughout but bisect-rustc found a spot where it changed. Not sure what's going on... |
Oops, this is why: $ cargo +bisector-nightly-2020-05-02-x86_64-apple-darwin rustc
Compiling rust-issue-77912-a v0.1.0 (/Users/user/rust-issue-77912-a)
error: unknown codegen option: `embed-bitcode`
error: could not compile `rust-issue-77912-a`
To learn more, run the command again with --verbose. |
I also think this behavior is expected, so I don't feel like there is a bug here |
Sorry @alexcrichton I think that was a false positive. |
Why would this be expected? |
Example A takes one argument (but does not use it) and does not error, while Example B takes no arguments and does error. |
Yeah, this is clearly working as specified in the reference (linked above), as well as here: https://rust-lang.github.io/rfcs/0141-lifetime-elision.html#examples |
example a is desugared to fn foo<'a>(s: &'a i32) -> &'a i32 {
&0
} while we currently do not apply any desugarings in the second example. We may want to change this behavior in the future, but as of now the compiler agrees with the language specification here |
Huh, yes I find that behavior very confusing. I guess this can be closed then. Thank you for walking me through this! It was really hurting my brain :) |
This compiles without error:
(Playground)
Errors:
But this errors, even though there shouldn't be a difference as
s
is not used in the previous example:(Playground)
Errors:
Potentially related to #77910.
The text was updated successfully, but these errors were encountered: