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

Comments

@goffrie
Copy link
Contributor

@goffrie 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 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>
{ ... }
@goffrie
Copy link
Contributor Author

@goffrie 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 Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants