Skip to content

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

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

Closed
Eijebong opened this issue Jul 30, 2022 · 3 comments · Fixed by #99953
Closed
Labels
P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@Eijebong
Copy link
Contributor

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

@Eijebong
Copy link
Contributor Author

ping @cjgillot since you're the author of the commit

@lqd lqd added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Aug 3, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 3, 2022
@apiraino
Copy link
Contributor

apiraino commented Aug 3, 2022

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-critical

@rustbot rustbot added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 3, 2022
@lqd
Copy link
Member

lqd commented Aug 3, 2022

note: there's a fix in #99953 ready for review

@bors bors closed this as completed in 6f18f0a Aug 4, 2022
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 20, 2024
Always create elided lifetimes, even if inferred.

`PathSource` gives the context in which a path is encountered.  The same `PathSource` is used for the full path and the `QSelf` part.

Therefore, we can only rely on `PathSource` to know whether typechecking will be able to infer the lifetimes, not whether we need to insert them at all.

Fixes rust-lang/rust#99949
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Always create elided lifetimes, even if inferred.

`PathSource` gives the context in which a path is encountered.  The same `PathSource` is used for the full path and the `QSelf` part.

Therefore, we can only rely on `PathSource` to know whether typechecking will be able to infer the lifetimes, not whether we need to insert them at all.

Fixes rust-lang/rust#99949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants