Skip to content

Prevent explicitly specifiying lifetime arguments to functions when the parameters are not visible in the type signature. - #160581

Open
addiesh wants to merge 1 commit into
rust-lang:mainfrom
addiesh:infishible
Open

Prevent explicitly specifiying lifetime arguments to functions when the parameters are not visible in the type signature.#160581
addiesh wants to merge 1 commit into
rust-lang:mainfrom
addiesh:infishible

Conversation

@addiesh

@addiesh addiesh commented Aug 5, 2026

Copy link
Copy Markdown

This is meant to fix #154490:

trait Trait {
    type Assoc<'a>;
}

// zero explicit generic lifetimes
fn do_thing<T: Trait>(_: Option<<T as Trait>::Assoc<'_>>) -> &i32 {
    todo!()
}

fn foo<T: Trait>() {
    // Previously, this would NOT cause any errors.
    // this PR makes it error out.
    do_thing::<'static, T>(None);
}

This started as a larger PR (#160471) but these changes work on their own.
Eventually, that PR should introduce the same checks for late-bound lifetimes.

…he parameters are not visible in the type signature.
@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 Aug 5, 2026
@addiesh
addiesh marked this pull request as ready for review August 5, 2026 17:10
@rustbot

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

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

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @mejrs (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 18 candidates

@mejrs

mejrs commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Isn't this a breaking change?

@addiesh

addiesh commented Aug 5, 2026

Copy link
Copy Markdown
Author

I don't think so? Afaik, the only way that this can happen is through a bug.

It may be worth a crater run to check to see if anyone is relying on this behavior though?

@mejrs

mejrs commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Well, that depends on how breaking it is :)

@addiesh

This comment has been minimized.

@oli-obk

oli-obk commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 5, 2026
Prevent explicitly specifiying lifetime arguments to functions when the parameters are not visible in the type signature.
@rust-bors

rust-bors Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 36e0a7e (36e0a7eac2392bdd51fab6e7ff1d8c0e42d33bf6)
Base parent: 22950ab (22950ab9e29e11620a10905f027f141ea126966e)

@oli-obk

oli-obk commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@craterbot check

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-160581 created and queued.
🤖 Automatically detected try build 36e0a7e
🔍 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 Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-crater Status: Waiting on a crater run to be completed. 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.

Elided early-bound lifetime parameters (due to associated types) can be turbofished

5 participants