Skip to content
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

Missing lifetime in associated type triggers suggestion that requires generic_associated_types #75547

Open
drewkett opened this issue Aug 15, 2020 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@drewkett
Copy link

I tried this code:

struct Foo<'a,R>{
    phantom: std::marker::PhantomData<&'a R>
}
#[derive(Debug)]
pub struct FooIter<'a, R>
{
    reader: &'a mut R,
}

impl<R:'static> Iterator for FooIter<'_, R>
{
    type Item = Foo<R>;

    fn next(&mut self) -> Option<Self::Item> {
        None
    }
}

I expected to see this happen: Not sure, but not this

Instead, this happened:

Compiling playground v0.0.1 (/playground)
error[E0106]: missing lifetime specifier
  --> src/lib.rs:12:21
   |
12 |     type Item = Foo<R>;
   |                     ^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter
   |
12 |     type Item<'a> = Foo<<'a>R>;
   |              ^^^^       ^^^^

Meta

This occurs both on my local machine and on the playground LINK

Looks like it returns an error with valid syntax at least on nightly, which just leads to GATs.

error[E0106]: missing lifetime specifier
  --> src/lib.rs:12:21
   |
12 |     type Item = Foo<R>;
   |                     ^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter
   |
12 |     type Item<'a> = Foo<'a, R>;
   |              ^^^^       ^^^

rustc --version --verbose:

rustc 1.45.2 (d3fb005a3 2020-07-31)
binary: rustc
commit-hash: d3fb005a39e62501b8b0b356166e515ae24e2e54
commit-date: 2020-07-31
host: x86_64-pc-windows-msvc
release: 1.45.2
LLVM version: 10.0
Backtrace

<backtrace>

@drewkett drewkett added the C-bug Category: This is a bug. label Aug 15, 2020
@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Aug 15, 2020
@jyn514
Copy link
Member

jyn514 commented Aug 15, 2020

@drewkett it looks like this is fixed on nightly if I understand correctly? Is there a reason you opened a bug?

@bugadani
Copy link
Contributor

bugadani commented Aug 15, 2020

I think the reason is that the error recommends an unstable feature?

Also, even after enabling the GAT feature, the suggested code doesn't build: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=13b837b2fc863b1e1008d7ddbdf52b69

@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 15, 2020
@estebank estebank changed the title Non Sensical Compiler Suggestion Missing lifetime in associated type triggers suggestion that requires generic_associated_types Aug 15, 2020
@drewkett
Copy link
Author

@drewkett it looks like this is fixed on nightly if I understand correctly? Is there a reason you opened a bug?

The main reason is that I wasn't sure of is that if something was fixed on nightly if that was necessarily intentional and necessarily would propagate to stable. I'm just not very familiar with exactly how nightly interacts with stable. And since I couldn't find this specific bug in an existing issue, I figured I'd raise it just so someone sees it.

@jyn514
Copy link
Member

jyn514 commented Aug 15, 2020

I'm just not very familiar with exactly how nightly interacts with stable.

https://doc.rust-lang.org/book/appendix-07-nightly-rust.html

But it sounds like there is a separate issue even on nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants