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

unused_extern_crates lint does not suggest rewriting crates to a use or pub use #51013

Closed
nikomatsakis opened this issue May 23, 2018 · 1 comment

Comments

@nikomatsakis
Copy link
Contributor

In #51010 (not yet merged), I removed the unnecessary_extern_crate "idiom lint" and replaced it with the (pre-existing) unused_extern_crates lint. This lint already handles all the tricky cases and so forth so this seems good to me. (In particular, it will suggest removing the extern crate iff it is unused.)

However, there was some stuff that the unnecessary_extern_crate lint would do which we no longer do. For example, we used to sometimes suggest rewriting an extern crate into a use etc. In the event that we are in Epoch 2018, we can of course still do this in the unused_extern_crates lint. The question is, should we?

It seems to me that — most of the time — having just a random pub use crate_name; may not be the most idiomatic thing to do. You might prefer to rewrite the paths that relied on that to just begin with the crate. Or, if you don't, you might just rather leave the extern crate there. Another point in favor is that there are some functions (e.g., most notably #[macro_use] but maybe also #[no_link]?) that are not easily replicated any other way.

On the other hand, doing that rewrite does mean that fewer people ever have to know that extern crate existed.

@nikomatsakis
Copy link
Contributor Author

never mind I put this logic back in

bors added a commit that referenced this issue Jun 2, 2018
…diom, r=alexcrichton

merge unused-extern-crate and unnecessary-extern-crate lints

Extend the `unused_extern_crates` lint to offer a suggestion to remove the extern crate and remove the `unnecessary_extern_crate` lint.

Still a few minor issues to fix:
- [x] this *does* now leave a blank line... (defer to #51176)
  - idea: extend the span to be replaced by 1 character if the next character is a `\n`
- [x] what about macros? do we need to watch out for that? (defer to #48704)
- [x] also it doesn't work for `extern crate foo; fn main() { foo::bar(); }`
  - this is subtle: the `foo` might be shadowing a glob import too, can't always remove
  - defer to #51177
- [x] we also don't do the `pub use` rewrite thang (#51013)

Spun off from #51010

Fixes #50672

r? @alexcrichton
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

1 participant