Repository navigation
|
I'd like to have all absolute module usages declared via imports. Are there any existing lints that can do this? I've tried Suppose that this is my whole file: pub fn get_mime_type(ext: &str) -> Option<mime::Mime> {
if ext == "html" {
Some(mime::TEXT_HTML)
} else {
None
}
}I want Clippy to complain until the absolute module is explicitly imported: use mime;
pub fn get_mime_type(ext: &str) -> Option<mime::Mime> {
if ext == "html" {
Some(mime::TEXT_HTML)
} else {
None
}
}[1] absolute_paths with Instead it requires all children to be imported individually (not something I want to force): use mime::Mime;
use mime::TEXT_HTML;
pub fn get_mime_type(ext: &str) -> Option<Mime> {
if ext == "html" {
Some(TEXT_HTML)
} else {
None
}
} |
Answered by
flip1995
Jan 10, 2024
Replies: 3 comments 3 replies
|
I would consider the |
3 replies
This comment was marked as low quality.
This comment was marked as low quality.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Ruby on Rails thing is not a pattern that works in Rust. If you don't import something, you can only access it through the full path, which is
crate::[modules::]*Item.Back in Rust 2015, if you want to use something from an extern crate
A, you had to writeextern crate A;. Rust 2018 got rid of this restriction and made it more convenient to use something from an extern crate. What you're asking is pretty much a lint that adds this back withusestatements.I don't think this lint would get a lot of use. But I'd accept it as an
restrictionlint, if you were to open a PR for it :)