-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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.
0xAl3xH
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.