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

Conflicting error messages for HRTB in impl Trait #69112

Open
JustAPerson opened this issue Feb 12, 2020 · 0 comments
Open

Conflicting error messages for HRTB in impl Trait #69112

JustAPerson opened this issue Feb 12, 2020 · 0 comments
Labels
A-diagnostics A-impl-trait A-lifetimes C-bug T-compiler

Comments

@JustAPerson
Copy link
Contributor

@JustAPerson JustAPerson commented Feb 12, 2020

Rust declares the lifetime 'a is both undeclared and that it is a shadowing declaration

#[derive(Debug)]
struct Ctx<'d> {
    phantom: std::marker::PhantomData<&'d ()>   
}
fn map<'c, 'd: 'c>(ctx: &'c mut Ctx<'d>, data: Vec<()>) -> impl for<'a> Iterator<Item = ()> + 'a where 'c: 'a {
    data.into_iter().inspect(|t| println!("{:?}", ctx))
}

My more complicated example is trying to use the &'c mut Ctx<'d> reference in one of the closures passed to Iterator::map() so I need to somehow incorporate the lifetime 'c into the return type.

Instead I get this confusing error:

error[E0261]: use of undeclared lifetime name `'a`
 --> src/lib.rs:5:95
  |
5 | fn map<'c, 'd: 'c>(ctx: &'c mut Ctx<'d>, data: Vec<()>) -> impl for<'a> Iterator<Item = ()> + 'a where 'c: 'a {
  |                                                                                               ^^ undeclared lifetime

error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
 --> src/lib.rs:5:69
  |
5 | fn map<'c, 'd: 'c>(ctx: &'c mut Ctx<'d>, data: Vec<()>) -> impl for<'a> Iterator<Item = ()> + 'a where 'c: 'a {
  |                                                                     ^^                        -- first declared here
  |                                                                     |
  |                                                                     lifetime 'a already in scope

error[E0261]: use of undeclared lifetime name `'a`
 --> src/lib.rs:5:108
  |
5 | fn map<'c, 'd: 'c>(ctx: &'c mut Ctx<'d>, data: Vec<()>) -> impl for<'a> Iterator<Item = ()> + 'a where 'c: 'a {
  |                                                                                                            ^^ undeclared lifetime

error: aborting due to 3 previous errors

You'll notice the help text of the first error says "undeclared lifetime" but the help of the second says "first declared here" and then gives a bogus "already in scope" hint.

@JustAPerson JustAPerson added the C-bug label Feb 12, 2020
@jonas-schievink jonas-schievink added A-diagnostics A-impl-trait A-lifetimes C-enhancement T-compiler C-bug and removed C-bug C-enhancement labels Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics A-impl-trait A-lifetimes C-bug T-compiler
Projects
None yet
Development

No branches or pull requests

2 participants