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

Wrong suggestion for fixing argument-position impl Trait #50817

Closed
goffrie opened this issue May 17, 2018 · 2 comments
Closed

Wrong suggestion for fixing argument-position impl Trait #50817

goffrie opened this issue May 17, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-frontend Area: frontend (errors, parsing and HIR) A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. WG-diagnostics Working group: Diagnostics

Comments

@goffrie
Copy link
Contributor

goffrie commented May 17, 2018

playground link

fn wot(x: impl Iterator<Item = u32> + Send) -> Box<Iterator<Item = u32> + Send> {
    Box::new(x)
}
fn main(){
    let mut it = vec![0, 1, 2].into_iter();
    wot(it.by_ref()).next();
    println!("{:?}", it.collect::<Vec<_>>());
}

yields the following errors:

error[E0310]: the parameter type `impl Iterator<Item = u32> + Send` may not live long enough
 --> src/main.rs:2:5
  |
2 |     Box::new(x)
  |     ^^^^^^^^^^^
  |
note: ...so that the type `impl Iterator<Item = u32> + Send` will meet its required lifetime bounds
 --> src/main.rs:2:5
  |
2 |     Box::new(x)
  |     ^^^^^^^^^^^
help: consider adding an explicit lifetime bound `impl Iterator<Item = u32> + Send: 'static`...
  |
1 | fn wot(x: impl Iterator<Item = u32> + Send: 'static +  -> Box<Iterator<Item = u32> + Send> {
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

In particular, note the suggestion x: impl Iterator<Item = u32> + Send: 'static. The error message itself is also less than ideal.

@Centril
Copy link
Contributor

Centril commented May 17, 2018

Seems right; It should be a suggestion to add + 'static instead, i.e:

fn wot(x: impl Iterator<Item = u32> + Send + 'static)
    -> Box<Iterator<Item = u32> + Send>
{ ... }

@Centril Centril added A-frontend Area: frontend (errors, parsing and HIR) A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. WG-diagnostics Working group: Diagnostics C-bug Category: This is a bug. labels May 17, 2018
@goffrie
Copy link
Contributor Author

goffrie commented Mar 10, 2019

Not sure when, but this has been fixed:

error[E0310]: the parameter type `impl Iterator<Item = u32> + Send` may not live long enough
 --> src/main.rs:2:5
  |
2 |     Box::new(x)
  |     ^^^^^^^^^^^
  |
note: ...so that the type `impl Iterator<Item = u32> + Send` will meet its required lifetime bounds
 --> src/main.rs:2:5
  |
2 |     Box::new(x)
  |     ^^^^^^^^^^^
help: consider adding an explicit lifetime bound  `'static` to `impl Iterator<Item = u32> + Send`...
  |
1 | fn wot(x: impl Iterator<Item = u32> + Send + 'static) -> Box<Iterator<Item = u32> + Send> {
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@goffrie goffrie closed this as completed Mar 10, 2019
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-frontend Area: frontend (errors, parsing and HIR) A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

2 participants