Skip to content

rustc recommends non-existent use #46131

Closed
@thanatos

Description

@thanatos
Contributor

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!

Activity

kennytm

kennytm commented on Nov 20, 2017

@kennytm
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @thanatos@kennytm

        Issue actions

          rustc recommends non-existent use · Issue #46131 · rust-lang/rust