Skip to content

Regression with lifetimes when using Foo as Trait and Trait has an associated lifetime #99949

Closed
@Eijebong

Description

@Eijebong

This code:

struct Sqlite {}

trait HasArguments<'q> {
    type Arguments;
}

impl<'q> HasArguments<'q> for Sqlite {
    type Arguments = std::marker::PhantomData<&'q ()>;
}

#[allow(dead_code)]
fn foo() {
    let _ = <Sqlite as HasArguments>::Arguments::default();
}

compiles on stable but not on nightly.

Error:

error[E0107]: missing generics for trait `HasArguments`
  --> lol.rs:13:24
   |
13 |     let _ = <Sqlite as HasArguments>::Arguments::default();
   |                        ^^^^^^^^^^^^ expected 1 lifetime argument
   |
note: trait defined here, with 1 lifetime parameter: `'q`
  --> lol.rs:3:7
   |
3  | trait HasArguments<'q> {
   |       ^^^^^^^^^^^^ --
help: add missing lifetime argument
   |
13 |     let _ = <Sqlite as HasArguments<'q>>::Arguments::default();
   |                        ~~~~~~~~~~~~~~~~

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.

I bisected it to 2643b16 and then refined it; reverting
a2254d5 fixes the issue.

This is the cause for launchbadge/sqlx#2004

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions