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 suggestion: require self for relative use statement paths #14246

Open
noamraph opened this issue Feb 18, 2025 · 0 comments
Open

Lint suggestion: require self for relative use statement paths #14246

noamraph opened this issue Feb 18, 2025 · 0 comments
Labels
A-lint Area: New lints

Comments

@noamraph
Copy link

noamraph commented Feb 18, 2025

What it does

Require self before paths in use statements that are relative to self.

Advantage

I found out that I'd want to easily distinguish between imports of my code and imports from other crates, and currently I can't easily distinguish between them.

A possible solution is to require adding self before relative imports. This makes it easy to distinguish between the two kinds, since local imports will always start with self, crate or super.

This would also make it easier to organize the imports according to their kind, like what the unstable rust-fmt option group_imports = StdExternalCrate does.

I don't suggest to enable this lint by default.

Drawbacks

I don't think of drawbacks, but I won't be surpried if others would think of some...

Example

use my_module::my_function;

Could be written as:

use self::my_module::my_function;

Note

If this is approved, I'd be happy to try to implement this.

@noamraph noamraph added the A-lint Area: New lints label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant