Closed
Description
Code
fn main() {}
fn foo(src: &crate::Foo) -> Option<i32> {
todo!()
}
fn bar(src: &crate::Foo) -> impl Iterator<Item = i32> {
[0].into_iter()
.filter_map(|_| foo(src))
}
struct Foo<'a>(&'a str);
Current output
Checking test1 v0.1.0 (/home/lrne/Project/Rust/test1)
error[E0700]: hidden type for `impl Iterator<Item = i32>` captures lifetime that does not appear in bounds
--> src/main.rs:7:5
|
6 | fn bar(src: &crate::Foo) -> impl Iterator<Item = i32> {
| ---------- ------------------------- opaque type defined here
| |
| hidden type `FilterMap<std::array::IntoIter<i32, 1>, {closure@src/main.rs:8:21: 8:24}>` captures the anonymous lifetime defined here
7 | / [0].into_iter()
8 | | .filter_map(|_| foo(src))
| |_________________________________^
|
help: to declare that `impl Iterator<Item = i32>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
6 | fn bar<'a>(src: &'a crate::'a) -> impl Iterator<Item = i32> + 'a {
| ++++ ++ ~~ ++++
For more information about this error, try `rustc --explain E0700`.
error: could not compile `test1` (bin "test1") due to 1 previous error
Desired output
Checking test1 v0.1.0 (/home/lrne/Project/Rust/test1)
error[E0700]: hidden type for `impl Iterator<Item = i32>` captures lifetime that does not appear in bounds
--> src/main.rs:7:5
|
6 | fn bar(src: &crate::Foo) -> impl Iterator<Item = i32> {
| ---------- ------------------------- opaque type defined here
| |
| hidden type `FilterMap<std::array::IntoIter<i32, 1>, {closure@src/main.rs:8:21: 8:24}>` captures the anonymous lifetime defined here
7 | / [0].into_iter()
8 | | .filter_map(|_| foo(src))
| |_________________________________^
|
help: to declare that `impl Iterator<Item = i32>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
6 | fn bar<'a>(src: &'a crate::Foo<'a>) -> impl Iterator<Item = i32> + 'a {
| ++++ ++ ~~ ++++
For more information about this error, try `rustc --explain E0700`.
error: could not compile `test1` (bin "test1") due to 1 previous error
Rationale and extra context
No response
Other cases
fn main() {}
fn foo(src: &crate::Foo) -> Option<i32> {
todo!()
}
fn bar(src: &crate::Foo<'_>) -> impl Iterator<Item = i32> {
[0].into_iter()
.filter_map(|_| foo(src))
}
struct Foo<'a>(&'a str);
Rust Version
rustc 1.77.0-nightly (bf8716f1c 2023-12-24)
binary: rustc
commit-hash: bf8716f1cd6416266807706bcae0ecb2e51c9d4a
commit-date: 2023-12-24
host: aarch64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6
Anything else?
No response
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.