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

Lint for use ident; #4903

Closed
jhpratt opened this issue Dec 15, 2019 · 5 comments · Fixed by #5058
Closed

Lint for use ident; #4903

jhpratt opened this issue Dec 15, 2019 · 5 comments · Fixed by #5058
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@jhpratt
Copy link
Member

jhpratt commented Dec 15, 2019

Any statement of the form use ident; is inherently useless, as it brings nothing new into scope. It can safely be removed in all situations (unless there's an edge case I'm not aware of?).

@flip1995
Copy link
Member

This is useful to only import crate scopes:

//! lib.rs of crate1
fn foo() {}
//! lib.rs of crate2 
fn foo() {}

So crate1 and crate2 have 2 functions with the same name. Now it is impossible to import both foo functions at the same time directly:

use crate1::foo;
use crate2::foo;

fn main() {
    foo(); // which `foo` is used here?
}

So what you want to do in this situation is

use crate1;
use crate2;

fn main() {
    crate1::foo();
    crate2::foo();
}

Something similar is done in clippy, when both hir::Expr and ast::Expr is required in a module.

@jhpratt
Copy link
Member Author

jhpratt commented Dec 25, 2019

@flip1995 That would only be the case in Rust 2015, correct?

@flip1995
Copy link
Member

No this is also the case in rust 2018, like in my example above, which is only valid in the 2018 edition.

@jhpratt
Copy link
Member Author

jhpratt commented Dec 29, 2019

I think you might not understand exactly what I'm saying. Importing paths is, of course, extremely useful. I agree it's not always feasible to do so. However, in Rust 2018 at least, you could eliminate the use statements from the latter snippet with zero offect whatsoever. This has nothing at all to do with naming conflicts.

@flip1995
Copy link
Member

you could eliminate the use statements from the latter snippet with zero offect whatsoever.

Ahhh, now it makes sense. Thanks for clarifying!

@flip1995 flip1995 added L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group labels Dec 29, 2019
@xiongmao86 xiongmao86 mentioned this issue Jan 17, 2020
6 tasks
@bors bors closed this as completed in f69835b Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants