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

Explicitly deny elided lifetimes in associated consts #114716

Closed

Conversation

compiler-errors
Copy link
Member

This seems to have regressed in #97313, after which we have begun resolving elided lifetimes in impls to anonymous early-bound lifetimes.

This PR applies an AnonymousReportError lifetime binder to both impl and trait const items to avoid this behavior. Only the former needs it, but also doing the latter for diagnostic consistency.

r? @cjgillot or @petrochenkov
Please review with whitespace changes disabled, the real diff is like 4 lines.

This probably requires a crater run anyways, but this is clearly a bug. I personally think we should use an Elided(LifetimeRes::Static) rib here, but that would require a T-lang FCP (or an RFC? idk).

cc #114706

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 10, 2023
@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Aug 10, 2023

⌛ Trying commit 7ed899bcea6314bd5cdef21721e2c3c1ab5999fb with merge 2b3cefe2517d0228c272ea52322148a40cabc88f...

Comment on lines -27 to -32
| ^^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
LL | const C<'a>: &'a str = "";
| ++++ ~~
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could probably recover this suggestion by inverting the order of the lifetime ribs... Doesn't seem particularly useful, though.

Copy link
Member

@fmease fmease Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we end up deciding on dropping these suggestion diagnostics (personally I'm fine either way, I also don't know how useful they are, mainly they're consistent with other diagnostics), then you can get rid of the revisions of this test as well as LifetimeBinderKind::ConstItem (replace it with Item) in late/diagnostics.rs and error handling code related to it since it will become unreachable.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 11, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 11, 2023
bors added a commit to rust-lang/cargo that referenced this pull request Aug 11, 2023
Fix elided lifetime in associated const

Fix an unelided lifetime in an associated const.

The old code was equivalent to:

```rust
impl<'a> RegistryConfig {
    /// File name of [`RegistryConfig`].
    const NAME: &'a str = "config.json";
}
```

and not `&'static str`, as it might be in a regular `const` item.

This "regressed" in rust-lang/rust#97313, which started allowing this behavior (inadvertently, as far as I can tell). It's not necessarily clear to me that this is sound (or at least, it's not something we intended to be able to express), but it's also preventing me from doing crater runs to investigate fallout of this issue (rust-lang/rust#114713 and rust-lang/rust#114716).
@compiler-errors
Copy link
Member Author

Blocked on a cargo sync for now.

@rustbot blocked

@rustbot rustbot added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 13, 2023
@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Aug 15, 2023

⌛ Trying commit f575aa5 with merge 19359abcd1be36c9ba1922a244cf9abf02af7a22...

@bors
Copy link
Contributor

bors commented Aug 15, 2023

☀️ Try build successful - checks-actions
Build commit: 19359abcd1be36c9ba1922a244cf9abf02af7a22 (19359abcd1be36c9ba1922a244cf9abf02af7a22)

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-114716 created and queued.
🤖 Automatically detected try build 19359abcd1be36c9ba1922a244cf9abf02af7a22
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Aug 15, 2023
@craterbot
Copy link
Collaborator

🚧 Experiment pr-114716 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-114716 is completed!
📊 658 regressed and 2 fixed (348705 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 17, 2023
@compiler-errors
Copy link
Member Author

Well of course people have begun to rely on this faulty behavior :/

@compiler-errors
Copy link
Member Author

Closing in favor of a future-compat lint: #115011

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 21, 2023
…oc-ct-lt, r=cjgillot

Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since rust-lang#97313. This is not correct behavior (see rust-lang#38831).

I originally opened rust-lang#114716 to fix this, but given the time that has passed, the crater results seem pretty bad: rust-lang#114716 (comment)

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Aug 22, 2023
…oc-ct-lt, r=cjgillot

Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since rust-lang#97313. This is not correct behavior (see rust-lang#38831).

I originally opened rust-lang#114716 to fix this, but given the time that has passed, the crater results seem pretty bad: rust-lang#114716 (comment)

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
bors pushed a commit to rust-lang/rust-analyzer that referenced this pull request Aug 23, 2023
… r=cjgillot

Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831).

I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: rust-lang/rust#114716 (comment)

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
… r=cjgillot

Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831).

I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: rust-lang/rust#114716 (comment)

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
… r=cjgillot

Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831).

I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: rust-lang/rust#114716 (comment)

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants