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

rustc recommends non-existent use #46131

Closed
thanatos opened this issue Nov 20, 2017 · 1 comment
Closed

rustc recommends non-existent use #46131

thanatos opened this issue Nov 20, 2017 · 1 comment

Comments

@thanatos
Copy link
Contributor

thanatos commented Nov 20, 2017

rustc will recommend the non-existent use statement use std::os::ext::process::CommandExt;, if the CommandExt trait is used, but not in scope.

Consider the following minimal example, a program that we would like to exec true:

use std::process::Command;

fn main() {
    let err = Command::new("true").exec();
    panic!(err)
}

This shouldn't compile, as the CommandExt trait, which .exec is part of, is not in scope. rustc says as much:

» rustc execit.rs
error[E0599]: no method named `exec` found for type `std::process::Command` in the current scope
 --> execit.rs:4:36
  |
4 |     let err = Command::new("true").exec();
  |                                    ^^^^
  |
  = help: items from traits can only be used if the trait is in scope
  = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
          candidate #1: `use std::os::ext::process::CommandExt;`

error: aborting due to previous error

Let's take the compiler's suggestion, since it is correct — a required trait is indeed not in scope:

» cat execit.rs
use std::process::Command;
use std::os::ext::process::CommandExt;

fn main() {
    let err = Command::new("true").exec();
    panic!(err)
}
» rustc execit.rs
error[E0432]: unresolved import `std::os::ext`
 --> execit.rs:2:14
  |
2 | use std::os::ext::process::CommandExt;
  |              ^^^ Could not find `ext` in `os`

warning: unused import: `std::os::ext::process::CommandExt`
 --> execit.rs:2:5
  |
2 | use std::os::ext::process::CommandExt;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error[E0599]: no method named `exec` found for type `std::process::Command` in the current scope
 --> execit.rs:5:36
  |
5 |     let err = Command::new("true").exec();
  |                                    ^^^^
  |
  = help: items from traits can only be used if the trait is in scope
  = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
          candidate #1: `use std::os::ext::process::CommandExt;`

error: aborting due to 2 previous errors

… it both fails to resolve the import, and re-recommends that very import in the same output.

I'm not sure how rustc forms its candidates for missing use statements (which are normally spot-on suggestion, BTW) but this particular one is bugged (and somewhat wat-inducing).

The docs for Command link to std::os::unix::process::CommandExt, and indeed, that compiles:

» cat execit.rs
use std::process::Command;
use std::os::unix::process::CommandExt;

fn main() {
    let err = Command::new("true").exec();
    panic!(err)
}
» rustc execit.rs
» # success!
@kennytm
Copy link
Member

kennytm commented Nov 20, 2017

Thanks for the report. This is a duplicate of #21934.

@kennytm kennytm closed this as completed Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants