-
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
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I would consider the |
Beta Was this translation helpful? Give feedback.
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 withuse
statements.I don't think this lint would get a lot of use. But I'd accept it as an
restriction
lint, if you were to open a PR for it :)