Skip to content

E0794 has a seemingly incorrect definition of "late bound lifetime parameter" #139652

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

Open
lolbinarycat opened this issue Apr 10, 2025 · 2 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.

Comments

@lolbinarycat
Copy link
Contributor

Location

https://doc.rust-lang.org/stable/error_codes/E0794.html

Summary

The docs say that a lifetime parameter must appear in an argument to be considered "late bound", but the following snippet emits E0794:

fn foo<'a>() {
    
}

fn bar() {
    let _ = foo::<'static>();
}
@lolbinarycat lolbinarycat added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Apr 10, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 10, 2025
@Jules-Bertholet
Copy link
Contributor

IIUC it should be “appears in an argument type, or does not appear in the return type”.

@QuineDot
Copy link

I agree the E0794 definition is incomplete.

Here are some conditions for being late bound. However, note that the "constrained" section is (AFAICT) talking about lifetimes that appear in the output type, so doesn't apply to the OP.

// I.e. this lifetime is still late bound
fn unused_param<'a>() {}

Also note that "constrained" is not as simple as "appears in".

trait Trait {
    type Gat<'a>;
    // Lifetimes in projections do not constrain
    fn both_are_early_bound<'s:'s, 'a>(&'s self, _: Self::Gat<'a>) -> Self::Gat<'a>;
    // Unconstrained but not in output type so still late bound
    // (similar to `unused_param`)             vv
    fn both_are_late_bound(&self, _: Self::Gat<'_>);
}

And "appear in the output type" includes elided lifetimes, including those implicitly captured by opaque types.

pub trait Trait {
    type Gat<'a>;
    fn first_lt_late_bound_second_lt_early_bound(&self, _: Self::Gat<'_>) -> impl Sized;
}

Which leads to confusing errors when eschewing aliases or using refinement: see #87803, #109476, #135350.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.
Projects
None yet
Development

No branches or pull requests

4 participants