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

The output help is incorrect, lifetime appears in an unexpected position #121267

Closed
A4-Tacks opened this issue Feb 18, 2024 · 0 comments · Fixed by #121587
Closed

The output help is incorrect, lifetime appears in an unexpected position #121267

A4-Tacks opened this issue Feb 18, 2024 · 0 comments · Fixed by #121587
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@A4-Tacks
Copy link

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

@A4-Tacks A4-Tacks added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 18, 2024
@jieyouxu jieyouxu added A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Feb 18, 2024
@bors bors closed this as completed in 6e1f7b5 Mar 21, 2024
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-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants