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

Open
goffrie opened this Issue May 17, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@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

This comment has been minimized.

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>
{ ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment