Skip to content
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

wrong "borrowed value does not live long enough" for singleton struct #13887

Closed
stepancheg opened this issue May 2, 2014 · 4 comments
Closed
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@stepancheg
Copy link
Contributor

Code:

trait Foo {}

struct Bar;

impl Foo for Bar {}

fn main() {
    &'static Bar as &'static Foo;
}

Compiler incorrectly reports that values does not live long enough:

tmp2.rs:8:5: 8:17 error: borrowed value does not live long enough
tmp2.rs:8     &'static Bar as &'static Foo;
              ^~~~~~~~~~~~
note: reference must be valid for the static lifetime...
tmp2.rs:8:5: 8:33 note: ...but borrowed value is only valid for the statement at 8:4
tmp2.rs:8     &'static Bar as &'static Foo;
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
@alexcrichton
Copy link
Member

cc @nikomatsakis

@Aatch
Copy link
Contributor

Aatch commented May 2, 2014

From my perspective, it seem that the real bug is that we allow lifetimes as part of the addr-of expression. According to the parser, we don't actually use the lifetime.

@sfackler
Copy link
Member

sfackler commented May 2, 2014

Looks like it's related to #11640.

@ghost
Copy link

ghost commented Nov 11, 2014

Lifetimes can no longer appear in expressions, closing.

@ghost ghost closed this as completed Nov 11, 2014
arcnmx pushed a commit to arcnmx/rust that referenced this issue Jan 9, 2023
Only set machine-applicable rustc diagnostics as preferred

If they aren't machine applicable, then they might not be what the user wants, disrupting the workflow.
Example being:
![image](https://user-images.githubusercontent.com/3757771/210380233-ae25aa04-954e-4634-8dd1-4377cc2bd837.png)
Prior to the PR this the diagnostic quickfix was at the top, but usually isn't what the user wants.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

4 participants