Skip to content

Allow explicit lifetime arguments (behind new #![feature(late_bound_turbofishing)]) and prevent explicit lifetime arguments where they do not appear in a function signature - #160471

Open
addiesh wants to merge 6 commits into
rust-lang:mainfrom
addiesh:fishymandias

Conversation

@addiesh

@addiesh addiesh commented Aug 3, 2026

Copy link
Copy Markdown

r? oli-obk

note: commit dd17e77 is part of another PR (#159403) and needs to be merged before this does (I'll rebase the commit out when it gets merged, which should be soon)

This PR is a little bit big (and probably super messy). here's what it changes/adds:

addie's checklist:

  • make sure that the late-bound lifetime specification makes sense and isn't just failing silently
    • i do not know how to do this!!! this is some type system wizardry that escapes me. I will need help with this
    • i added one (1) test case to check and it fails (here)
  • fix the the turbofishing doesn't work because late-bound lifetimes aren't being counted right now

so what:

  1. this will now compile:
#![feature(late_bound_turbofishing)]

fn foo<'a>(b: &'a u32) -> &'a u32 { b }

fn main() {
    let f = foo::<'static>;
}

...and if the feature gate is missing, a diagnostic will be reported.

  1. this snippet (taken from this issue) will now fail to compile:
trait Trait {
    type Assoc<'a>;
}

fn do_thing<'b, T: Trait>(_: Option<<T as Trait>::Assoc<'_>>) -> (&i32, &'b i64) {
    todo!()
}

fn foo<T: Trait>() {
    do_thing::<'static, 'static, T>(None);
}

...although its diagnostic probably could stand to be improved.

ty :3

And on the pull request these words appear:
"My name is Fishymandias, fish of fish:
Look on my Rust, ye Reviewer, and despair!"

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 3, 2026
@rustbot

rustbot commented Aug 3, 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 @oli-obk (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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.


fn bar<'a>(_: &'a u32) {
let f = foo_late::<'a>;
require_static(f);

@addiesh addiesh Aug 4, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this needs to fail, but currently it's not... don't know how to fix

View changes since the review

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.

isn't this just the usual FnDef outlives issue that already exists without your PR?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oops- I think so? But I;m not sure. the following (which is early-bound afaik) compiles when it shouldn't(?) in the rust playground

fn require_static<T: 'static>(_: T) {}

fn foo<'a: 'a>(b: &'a u32) -> &'a u32 { b }

fn bar<'a>(_: &'a u32) {
    let f = foo::<'a>;
    require_static(f);
}

fn main() {
    let x = 4;
    {
        bar(&x);
    }
}

@rust-log-analyzer

This comment has been minimized.

@addiesh

addiesh commented Aug 4, 2026

Copy link
Copy Markdown
Author

that CI run didn't give a good backtrace so to save future me from agony, the problem is here

param_counts.lifetimes - hidden_lifetimes + late_bound_lt_count;

@rust-log-analyzer

This comment has been minimized.

@addiesh

addiesh commented Aug 5, 2026

Copy link
Copy Markdown
Author

this is gonna be rough:

@addiesh
addiesh marked this pull request as ready for review August 5, 2026 16:05
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 5, 2026
@rustbot

rustbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

HIR ty lowering was modified

cc @fmease

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 5, 2026
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-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants