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

Remove extern crate when migrating to Rust 2018 #52829

Closed
johnthagen opened this issue Jul 29, 2018 · 3 comments · Fixed by #53684
Closed

Remove extern crate when migrating to Rust 2018 #52829

johnthagen opened this issue Jul 29, 2018 · 3 comments · Fixed by #53684
Assignees
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. F-rust_2018_preview `#![feature(rust_2018_preview)]`
Milestone

Comments

@johnthagen
Copy link
Contributor

johnthagen commented Jul 29, 2018

Migrated from rust-lang/cargo#5829

It's been mentioned/requested multiple times on the internals thread that cargo fix should remove the extern crate statements when moving to Rust 2018.

Motivation

One of the big draws of Rust 2018's module system is that all of the "redundant" extern crate lines can finally be removed. It took some of the excitement away when I went through all of the cargo fix steps and still saw them there. I think it will just be a better experience for users to see one of the tangible benefits of this change. As it is right now, they just see the crate:: in front of all of their local imports and they might not realize what a nice change the module system updates really are.

After I manually removed the extern crate's I did get my satisfying result 😄, but let's give this to users on the first go around.

Implementation

If I understand correctly this should be implemented in the compiler under the #![warn(rust_2018_idioms)] lints, rather than cargo fix itself.

cc @alexcrichton

@alexcrichton
Copy link
Member

I'm moving this forward up on the milestone list due to just having closed #52451 in favor of this issue, which was itself on the RC milestone.

@alexcrichton alexcrichton self-assigned this Aug 24, 2018
@alexcrichton
Copy link
Member

Ok so I've some triaging of extern crate related lint issues, and I believe the current work items are:

  • A rustfix-fixable suggestion for removing extern crate needs to be implemented. The implementation would go here.
  • Currently the lint suggests switching to simply use. While technically correct and handles lots of corner cases, this doesn't achieve the desired goal of actually removing annotations.
  • We can't blanket remove all extern crate statements, for example this test case is correctly warned to use a use rather than deleting the statement outright.

I'm testing out some ideas locally as well.

@alexcrichton
Copy link
Member

I believe this should be fixed by #53684, I think the naive solution actually works well!

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 27, 2018
This commit updates the `unused_extern_crates` lint to make automatic
suggestions about removing `extern crate` annotations in the 2018 edition. This
ended up being a little easier than originally though due to what's likely been
fixed issues in the resolver!

Closes rust-lang#52829
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Aug 28, 2018
rustc: Suggest removing `extern crate` in 2018

This commit updates the `unused_extern_crates` lint to make automatic
suggestions about removing `extern crate` annotations in the 2018 edition. This
ended up being a little easier than originally though due to what's likely been
fixed issues in the resolver!

Closes rust-lang#52829
bors added a commit that referenced this issue Aug 29, 2018
rustc: Suggest removing `extern crate` in 2018

This commit updates the `unused_extern_crates` lint to make automatic
suggestions about removing `extern crate` annotations in the 2018 edition. This
ended up being a little easier than originally though due to what's likely been
fixed issues in the resolver!

Closes #52829
@fmease fmease added A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-edition-2018-lints labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. F-rust_2018_preview `#![feature(rust_2018_preview)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants