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

cargo fix --edition-idioms fails on extern crate ignore #6353

Closed
illicitonion opened this issue Nov 26, 2018 · 6 comments
Closed

cargo fix --edition-idioms fails on extern crate ignore #6353

illicitonion opened this issue Nov 26, 2018 · 6 comments

Comments

@illicitonion
Copy link
Contributor

Problem
A module with extern crate ignore; causes auto-fixes to fail.
Expect cargo fix --edition-idioms to succeed. Instead, it errors and asks me to file a bug.

Steps

$ git clone https://github.com/illicitonion/cargo-fix-2018-repro.git
$ cd cargo-fix-2018-repro
$ rustc +beta --version
rustc 1.31.0-beta.17 (1a4f1f398 2018-11-25)
$ cargo +beta --version
cargo 1.31.0-beta (339d9f9c8 2018-11-16)
$ cargo +beta fix --edition-idioms
    Checking rust-ignore-repro v0.0.1 (/home/dwh/tmp/rustplay)                                                                                                                                                                                 
warning: failed to automatically apply fixes suggested by rustc to crate `rust_ignore_repro`                                                                                                                                                   

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see 
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/cargo/issues
quoting the full output of this command we'd be very appreciative!

warning: `extern crate` is not idiomatic in the new edition                                                                                                                                                                                    
 --> src/main.rs:1:1                                                                                                                                                                                                                           
  |                                                                                                                                                                                                                                            
1 | extern crate ignore;                                                                                                                                                                                                                       
  | ^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`                                                                                                                                                                                           
  |                                                                                                                                                                                                                                            
  = note: `-W unused-extern-crates` implied by `-W rust-2018-idioms`                                                                                                                                                                           
                                                                                                                                                                                                                                               
warning: `extern crate` is not idiomatic in the new edition                                                                                                                                                                                    
 --> src/main.rs:1:1                                                                                                                                                                                                                           
  |                                                                                                                                                                                                                                            
1 | extern crate ignore;                                                                                                                                                                                                                       
  | ^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`                                                                                                                                                                                           
  |                                                                                                                                                                                                                                            
  = note: `-W unused-extern-crates` implied by `-W rust-2018-idioms`                                                                                                                                                                           
                                                                                                                                                                                                                                               
    Finished dev [unoptimized + debuginfo] target(s) in 0.43s
$ sed -e 's#extern crate#use#g' -i src/main.rs 
$ cargo +beta build
   Compiling rust-ignore-repro v0.0.1 (/home/dwh/tmp/rustplay)                                                                                                                                                                                 
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)                                                                                                                         
 --> src/main.rs:1:5                                                                                                                                                                                                                           
  |                                                                                                                                                                                                                                            
1 | use ignore;                                                                                                                                                                                                                                
  |     ^^^^^^ not an extern crate passed with `--extern`                                                                                                                                                                                      
  |                                                                                                                                                                                                                                            
note: this import refers to the built-in attribute imported here                                                                                                                                                                               
 --> src/main.rs:1:5                                                                                                                                                                                                                           
  |                                                                                                                                                                                                                                            
1 | use ignore;                                                                                                                                                                                                                                
  |     ^^^^^^                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                               
error: aborting due to previous error                                                                                                                                                                                                          
                                                                                                                                                                                                                                               
For more information about this error, try `rustc --explain E0658`.                                                                                                                                                                            
error: Could not compile `rust-ignore-repro`.                                                                                                                                                                                                  

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

Output of cargo version:

$ rustc +beta --version
rustc 1.31.0-beta.17 (1a4f1f398 2018-11-25)
$ cargo +beta --version
cargo 1.31.0-beta (339d9f9c8 2018-11-16)

If I instead replace with use ::ignore; it seems to work fine.

@ehuss
Copy link
Contributor

ehuss commented Nov 26, 2018

That's interesting. It seems to fail with any crate with a name that matches any item in the standard prelude (including attributes, macros, functions, types, etc.).

@illicitonion
Copy link
Contributor Author

Probably related: Depending on a crate which has use ::ignore; in it gives an error about ignore being defined multiple times: https://github.com/illicitonion/cargo-2018-multiple-defines

Can spin off a separate bug if this turns out to be unrelated...

@alexcrichton
Copy link
Member

cc @petrochenkov, is this a bug or expected behavior? Specifically it looks like with --extern ignore=... this fails to compile:

use ignore;

but this succeeds:

use ::ignore;

(and @ehuss indicates that this applies to anything in the prelude!)

@petrochenkov
Copy link
Contributor

petrochenkov commented Nov 28, 2018

It's a deficiency of the migration lint.

extern crate foo; imports foo only in type namespace.
use ::foo; imports foo only in type namespace.

use foo; however imports foo in all three namespaces, and some of the extra imported names may cause issues, e.g. be feature gated (like with the ignore attribute above), or conflict with other names in the root module.

@petrochenkov
Copy link
Contributor

We should either

  • Suggest use ::foo; (easy, correct, but crude).
  • Check whether use foo; brings names in value or macro namespaces, and suggest use foo; only if it doesn't, otherwise suggest use ::foo (this may be harder).

@alexcrichton
Copy link
Member

Ok thanks for the info @petrochenkov! I've moved this to rust-lang/rust#56326 and will close this in favor of that.

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

4 participants