Skip to content

Infer all anonymous lifetimes in assoc consts as 'static#156508

Open
oli-obk wants to merge 1 commit into
rust-lang:mainfrom
oli-obk:boom
Open

Infer all anonymous lifetimes in assoc consts as 'static#156508
oli-obk wants to merge 1 commit into
rust-lang:mainfrom
oli-obk:boom

Conversation

@oli-obk

@oli-obk oli-obk commented May 12, 2026

Copy link
Copy Markdown
Contributor

View all comments

fixes #115010

This FCW has been on for almost a year, let's actually do the change that T-lang asked for now that there's no breakage to be expected anymore. I first did a crater run checking if turning it into a hard error breaks anything.

There are two cases that would be a hard error (but totally fine by defaulting to 'static), both based on an old version of minio. One is a personal crate on github with no changes in the last year (https://github.com/PapePathe/daaray_kaamil) and the other is https://github.com/gear-tech/gear, which is developed on github actively and does not have this issue anymore (also old minio dependency that was since updated). The crates.io version is 2 years outdated.

Thus we can pretty much conclude we're not going to cause anyone any confusion or subtle bugs by changing the rules. The rules for associated constants' types are now the same as the rules for free constants' types:

We now treat all anonymous lifetimes as 'static, irrespective of whether other lifetimes are in scope or not. This means the following piece of code starts compiling without warnings or errors again.

struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
    const STR: &str = "hello, world";
}

We keep the hard error on

trait Foo {
    const B: S = S { s: &() };
}

struct S<'a> {
    s: &'a (),
}

in contrast to free constant, which are orthogonal to this change and cause more breakage

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 12, 2026
@oli-obk

oli-obk commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 12, 2026
Turn elided_lifetimes_in_associated_constant FCW into a hard error
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: b28cc4e (b28cc4eb48a6415b914e8ad0308be255ff8d73ed, parent: 2aabf3ce0569dd7c8c2d2a27944850056dcf2566)

@oli-obk

oli-obk commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

@craterbot check

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-156508 created and queued.
🤖 Automatically detected try build b28cc4e
🔍 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-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 13, 2026
@rustbot rustbot added the T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. label May 13, 2026
@rust-bors

This comment has been minimized.

@craterbot

Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-156508 is now running

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

@craterbot

Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-156508 is completed!
📊 3 regressed and 10 fixed (931813 total)
📊 5201 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

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

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-156508/retry-regressed-list.txt

@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 May 23, 2026
@oli-obk

oli-obk commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-156508-1 created and queued.
🤖 Automatically detected try build b28cc4e
⚠️ Try build based on commit eaec6ce, but latest commit is a92df8e. Did you forget to make a new try build?
🔍 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-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 26, 2026
@oli-obk oli-obk changed the title Turn elided_lifetimes_in_associated_constant FCW into a hard error Infer all anonymous lifetimes in assoc consts as 'static May 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 29, 2026
Some cleanups around passing extra lifetime params from the resolver to ast lowering

No functional changes, mostly removing information that was never used at any step.

Possibly interesting to @petrochenkov and @cjgillot

I originally thought this was a necessary cleanup to be able to refactor our `extra_lifetime_params_map` handling, but it turns out that I can also just do rust-lang#156508 which removes all the ugly usage of that side table and makes it possible for that side table to be put into `PerOwnerResolverData`. The changes here still were an improvement on its own, thus this PR.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 29, 2026
Some cleanups around passing extra lifetime params from the resolver to ast lowering

No functional changes, mostly removing information that was never used at any step.

Possibly interesting to @petrochenkov and @cjgillot

I originally thought this was a necessary cleanup to be able to refactor our `extra_lifetime_params_map` handling, but it turns out that I can also just do rust-lang#156508 which removes all the ugly usage of that side table and makes it possible for that side table to be put into `PerOwnerResolverData`. The changes here still were an improvement on its own, thus this PR.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 29, 2026
Some cleanups around passing extra lifetime params from the resolver to ast lowering

No functional changes, mostly removing information that was never used at any step.

Possibly interesting to @petrochenkov and @cjgillot

I originally thought this was a necessary cleanup to be able to refactor our `extra_lifetime_params_map` handling, but it turns out that I can also just do rust-lang#156508 which removes all the ugly usage of that side table and makes it possible for that side table to be put into `PerOwnerResolverData`. The changes here still were an improvement on its own, thus this PR.
rust-timer added a commit that referenced this pull request May 30, 2026
Rollup merge of #156960 - oli-obk:push-rrmqnqvwtmsq, r=tiif

Some cleanups around passing extra lifetime params from the resolver to ast lowering

No functional changes, mostly removing information that was never used at any step.

Possibly interesting to @petrochenkov and @cjgillot

I originally thought this was a necessary cleanup to be able to refactor our `extra_lifetime_params_map` handling, but it turns out that I can also just do #156508 which removes all the ugly usage of that side table and makes it possible for that side table to be put into `PerOwnerResolverData`. The changes here still were an improvement on its own, thus this PR.
@rust-bors

This comment has been minimized.

Comment thread compiler/rustc_resolve/src/late.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

The PR description also needs an update after the last commit.
@rustbot author

@rustbot rustbot 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 Jul 7, 2026
@rustbot

rustbot commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

This comment has been minimized.

@oli-obk oli-obk added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 7, 2026
Comment thread compiler/rustc_resolve/src/late.rs Outdated
Elided(LifetimeRes),
Elided {
res: LifetimeRes,
/// Always report those lifetimes as an error

@petrochenkov petrochenkov Jul 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not always an error, it's only an error if it's in a path.

View changes since the review

@petrochenkov

Copy link
Copy Markdown
Contributor

r=me after fixing the comment and squashing commits.
@rustbot author

@rustbot rustbot 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 Jul 9, 2026
Hard error on hidden elided lifetimes (`S` instead of `S<'_>`) in assoc consts
@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@oli-obk

oli-obk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@bors r=petrochenkov

@rust-bors

rust-bors Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit c3257a5 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 9, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
Infer all anonymous lifetimes in assoc consts as `'static`

fixes rust-lang#115010

This FCW has been on for almost a year, let's actually do the change that T-lang asked for now that there's no breakage to be expected anymore. I first did a crater run checking if turning it into a hard error breaks anything.

There are two cases that would be a hard error (but totally fine by defaulting to `'static`), both based on an old version of `minio`. One is a personal crate on github with no changes in the last year (https://github.com/PapePathe/daaray_kaamil) and the other is https://github.com/gear-tech/gear, which is developed on github actively and does not have this issue anymore (also old `minio` dependency that was since updated). The crates.io version is 2 years outdated.

Thus we can pretty much conclude we're not going to cause anyone any confusion or subtle bugs by changing the rules. The rules for associated constants' types are now the same as the rules for free constants' types:

We now treat *all* anonymous lifetimes as `'static`, irrespective of whether other lifetimes are in scope or not. This means the following piece of code starts compiling without warnings or errors again.

```rust
struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
    const STR: &str = "hello, world";
}
```

We keep the hard error on

```rust
trait Foo {
    const B: S = S { s: &() };
}

struct S<'a> {
    s: &'a (),
}
```

in contrast to free constant, which are orthogonal to this change and cause more breakage
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`)
 - #155429 (Support `u128`/`i128` c-variadic arguments)
 - #156370 (Reject linked dylib EII default overrides)
 - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158859 (Improve `-Zls` diagnostic message on `.rs` files)
 - #158988 (Redo `TokenStreamIter`)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158739 (view-types: HIR lowering)
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158886 (Add documentation for the `no_std` attribute)
 - #158940 (Implement feature `char_to_u32`)
 - #158951 (Merge three `MaxUniverse`s into one)
 - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
 - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes)
 - #159005 (Use `as_lang_item` instead of repeatedly matching)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 9, 2026
Infer all anonymous lifetimes in assoc consts as `'static`

fixes rust-lang#115010

This FCW has been on for almost a year, let's actually do the change that T-lang asked for now that there's no breakage to be expected anymore. I first did a crater run checking if turning it into a hard error breaks anything.

There are two cases that would be a hard error (but totally fine by defaulting to `'static`), both based on an old version of `minio`. One is a personal crate on github with no changes in the last year (https://github.com/PapePathe/daaray_kaamil) and the other is https://github.com/gear-tech/gear, which is developed on github actively and does not have this issue anymore (also old `minio` dependency that was since updated). The crates.io version is 2 years outdated.

Thus we can pretty much conclude we're not going to cause anyone any confusion or subtle bugs by changing the rules. The rules for associated constants' types are now the same as the rules for free constants' types:

We now treat *all* anonymous lifetimes as `'static`, irrespective of whether other lifetimes are in scope or not. This means the following piece of code starts compiling without warnings or errors again.

```rust
struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
    const STR: &str = "hello, world";
}
```

We keep the hard error on

```rust
trait Foo {
    const B: S = S { s: &() };
}

struct S<'a> {
    s: &'a (),
}
```

in contrast to free constant, which are orthogonal to this change and cause more breakage
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
…uwer

Rollup of 24 pull requests

Successful merges:

 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`)
 - #156027 (Consider captured regions for opaque type region liveness.)
 - #156370 (Reject linked dylib EII default overrides)
 - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`)
 - #157561 (rustdoc: do not include extra stuff in span)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158859 (Improve `-Zls` diagnostic message on `.rs` files)
 - #158988 (Redo `TokenStreamIter`)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158384 (Allow BackwardIncompatibleDropHint in polonius legacy)
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158739 (view-types: HIR lowering)
 - #158877 (borrowck: Keep returned `path` from `best_blame_constraint()` consistent)
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158886 (Add documentation for the `no_std` attribute)
 - #158940 (Implement feature `char_to_u32`)
 - #158951 (Merge three `MaxUniverse`s into one)
 - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
 - #158995 (Use REST API in linkchecker script)
 - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 9, 2026
Infer all anonymous lifetimes in assoc consts as `'static`

fixes rust-lang#115010

This FCW has been on for almost a year, let's actually do the change that T-lang asked for now that there's no breakage to be expected anymore. I first did a crater run checking if turning it into a hard error breaks anything.

There are two cases that would be a hard error (but totally fine by defaulting to `'static`), both based on an old version of `minio`. One is a personal crate on github with no changes in the last year (https://github.com/PapePathe/daaray_kaamil) and the other is https://github.com/gear-tech/gear, which is developed on github actively and does not have this issue anymore (also old `minio` dependency that was since updated). The crates.io version is 2 years outdated.

Thus we can pretty much conclude we're not going to cause anyone any confusion or subtle bugs by changing the rules. The rules for associated constants' types are now the same as the rules for free constants' types:

We now treat *all* anonymous lifetimes as `'static`, irrespective of whether other lifetimes are in scope or not. This means the following piece of code starts compiling without warnings or errors again.

```rust
struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
    const STR: &str = "hello, world";
}
```

We keep the hard error on

```rust
trait Foo {
    const B: S = S { s: &() };
}

struct S<'a> {
    s: &'a (),
}
```

in contrast to free constant, which are orthogonal to this change and cause more breakage
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 10, 2026
Infer all anonymous lifetimes in assoc consts as `'static`

fixes rust-lang#115010

This FCW has been on for almost a year, let's actually do the change that T-lang asked for now that there's no breakage to be expected anymore. I first did a crater run checking if turning it into a hard error breaks anything.

There are two cases that would be a hard error (but totally fine by defaulting to `'static`), both based on an old version of `minio`. One is a personal crate on github with no changes in the last year (https://github.com/PapePathe/daaray_kaamil) and the other is https://github.com/gear-tech/gear, which is developed on github actively and does not have this issue anymore (also old `minio` dependency that was since updated). The crates.io version is 2 years outdated.

Thus we can pretty much conclude we're not going to cause anyone any confusion or subtle bugs by changing the rules. The rules for associated constants' types are now the same as the rules for free constants' types:

We now treat *all* anonymous lifetimes as `'static`, irrespective of whether other lifetimes are in scope or not. This means the following piece of code starts compiling without warnings or errors again.

```rust
struct Foo<'a>(&'a ());

impl<'a> Foo<'a> {
    const STR: &str = "hello, world";
}
```

We keep the hard error on

```rust
trait Foo {
    const B: S = S { s: &() };
}

struct S<'a> {
    s: &'a (),
}
```

in contrast to free constant, which are orthogonal to this change and cause more breakage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking issue for future-incompatibility lint elided_lifetimes_in_associated_constant

10 participants