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

Help suggests non-existent package std::os::ext::process::CommandExt #39175

Closed
psimonyi opened this issue Jan 19, 2017 · 6 comments
Closed

Help suggests non-existent package std::os::ext::process::CommandExt #39175

psimonyi opened this issue Jan 19, 2017 · 6 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@psimonyi
Copy link

Normally rustc will suggest what use line to add, but for CommandExt its suggestion is impossible.

testcase.rs:

use std::process::Command;
// forgot this: use std::os::unix::process::CommandExt;

fn main() {
    Command::new("echo").arg("hello").exec();
}

Compile with rustc testcase.rs. Rust says it can't find exec and explains:

  = help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
  = help: candidate #1: `use std::os::ext::process::CommandExt;`

But the suggested trait doesn't exist; adding the suggested line gives an unresolved import error: "Could not find ext in os"

Rust should instead suggest the correct trait, std::os::unix::process::CommandExt.

Tested with (rustc --version --verbose):

Fedora 25's packaged rust:

rustc 1.10.0 (cfcb716cf 2016-07-03)
binary: rustc
commit-hash: cfcb716cf0961a7e3a4eceac828d94805cf8140b
commit-date: 2016-07-03
host: x86_64-unknown-linux-gnu
release: 1.10.0

And a recent source build:

rustc 1.16.0-dev (74c42ac17 2017-01-19)
binary: rustc
commit-hash: 74c42ac173bee900979870ed986c760596d1fbdb
commit-date: 2017-01-19
host: x86_64-unknown-linux-gnu
release: 1.16.0-dev
LLVM version: 3.9

(The formatting of the error messages differs between versions but the errors are the same.)

@pengowen123
Copy link
Contributor

The path is created at librustc_typeck/check/method/suggest.rs at line 333. item_path_str seems to be following re-exports: std::os::ext::process::CommandExt is a valid path because of a re-export in libstd/os/mod.rs. However, the re-export is pub use sys::ext as unix, so the path should be std::os::unix::process::CommandExt. item_path_str isn't taking this renaming into account, so it leads to an incorrect path.

@setharnold
Copy link

Other modules show this problem:

error[E0432]: unresolved import `std::os::ext::ffi::OsStrExt`
  --> src/main.rs:44:5
   |
44 | use std::os::ext::ffi::OsStrExt;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find `ext` in `os`

error: no method named `as_bytes` found for type `&std::ffi::OsStr` in the current scope
  --> src/main.rs:51:41
   |
51 | 		.filter(|n| *(n.unwrap().file_name()).as_bytes() == b".dsc") {
   | 		                                      ^^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
   = help: candidate #1: `use std::os::ext::ffi::OsStrExt;`

error: aborting due to previous error

Thanks

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 22, 2017
@Mark-Simulacrum
Copy link
Member

Nominating for compiler team. If there's something we can do to fix this, that would be great -- I imagine most beginners hit this fairly often, and even experienced users. I don't know what the underlying problem here is, though, so perhaps it's very hard to fix.

@Mark-Simulacrum Mark-Simulacrum added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 22, 2017
@nikomatsakis
Copy link
Contributor

triage: P-medium

This would indeed be good to fix but doesn't rise to the urgency of P-high. The underlying problem is that we often print the "true path" but we should be printing the "visible" path. Not sure who would be best equipped to plan a solution to this -- @jseyfried ?

@rust-highfive rust-highfive added P-medium Medium priority and removed I-nominated labels Jun 29, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@Ryan1729
Copy link
Contributor

Ryan1729 commented Aug 4, 2018

Just ran into this with 1.28.0 on windows 10. I guess I'll add my example to the pile:

use std::ffi::OsStr;
use std::os::ext::ffi::OsStrExt;

fn main() {
    OsStr::new("1234").encode_wide();
}

This gives me the following absurd pair of errors:

error[E0433]: failed to resolve. Could not find `ext` in `os`
 --> src\main.rs:2:14
  |
2 | use std::os::ext::ffi::OsStrExt;
  |              ^^^ Could not find `ext` in `os`

warning: unused import: `std::os::ext::ffi::OsStrExt`
 --> src\main.rs:2:5
  |
2 | use std::os::ext::ffi::OsStrExt;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error[E0599]: no method named `encode_wide` found for type `&std::ffi::OsStr` in the current scope
 --> src\main.rs:5:24
  |
5 |     OsStr::new("1234").encode_wide();
  |                        ^^^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
  |
1 | use std::os::ext::ffi::OsStrExt;
  |

error: aborting due to 2 previous errors

@ErichDonGubler
Copy link
Contributor

ErichDonGubler commented Oct 10, 2018

I likewise get this issue with the following snippet:

use std::ffi::OsString;

fn main() {
    let _ = OsString::from_wide(b"a\x00b\x00c\x00");
}
   Compiling bad_ffi_ext_trait_suggestion v0.1.0 (file:///C:/Users/egubler/AppData/Local/Cargo/script-cache/file-bad_ffi_ext_trait_suggestion-eaa1f7e82798a3de)
error[E0599]: no function or associated item named `from_wide` found for type `std::ffi::OsString` in the current scope
 --> bad_ffi_ext_trait_suggestion.rs:4:13
  |
4 |     let _ = OsString::from_wide(b"a\x00b\x00c\x00");
  |             ^^^^^^^^^^^^^^^^^^^ function or associated item not found in `std::ffi::OsString`
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
  |
1 | use std::os::ext::ffi::OsStringExt;
  |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: Could not compile `bad_ffi_ext_trait_suggestion`.

To learn more, run the command again with --verbose.

Relevant rustup show output:

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.29.0 (aa3ca1994 2018-09-11)

@davidtwco davidtwco self-assigned this Oct 12, 2018
kennytm added a commit to kennytm/rust that referenced this issue Oct 18, 2018
Help suggests non-existent package std::os::ext::process::CommandExt

Fixes rust-lang#39175.
bors added a commit that referenced this issue Oct 20, 2018
Help suggests non-existent package std::os::ext::process::CommandExt

Fixes #39175.
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 C-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants