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 macros fails some obvious cases due to prelude #51177

Open
nikomatsakis opened this issue May 29, 2018 · 0 comments
Open

unused macros fails some obvious cases due to prelude #51177

nikomatsakis opened this issue May 29, 2018 · 0 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-epoch Working group: Epoch (2018) management

Comments

@nikomatsakis
Copy link
Contributor

This example does not warn, even in Rust 2018 edition:

// compile-flags: --edition 2018
extern crate foo; 
fn main() { foo::bar(); }

The reason is that we resolve foo against the extern crate, when in fact it could also be resolved by the extern prelude fallback. But that's tricky! Something like this could also happen:

// compile-flags: --edition 2018
mod bar { mod foo { } }
use bar::*; // `foo` here is shadowed by `foo` below
extern crate foo; 
fn main() { foo::bar(); }

In which case, removing foo would result in importing the module, since (I believe) that would shadow the implicit prelude imports.

Therefore: we can do better here, but with caution -- for example, we could suggest removing an extern crate in a scenario like this, but only if there are no glob imports in the current module. Not sure it's worth it though.

@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-epoch Working group: Epoch (2018) management labels May 29, 2018
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
@XAMPPRocky XAMPPRocky added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-epoch Working group: Epoch (2018) management
Projects
None yet
Development

No branches or pull requests

2 participants