Skip to content

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

Open

Description

@lolbinarycat

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>();
}

Activity

  1. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Apr 10, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 10, 2025
  3. Jules-Bertholet commented on Apr 11, 2025

    @Jules-Bertholet
    Contributor

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

  4. QuineDot commented on Apr 26, 2025

    @QuineDot

    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.

  5. added
    T-langRelevant to the language team
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions