-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Prefer importing items from the crate they are defined in, rather than a re-export. #11698
Comments
r-a tries to use the shortest imports it can find, hence why it prefers the prelude there, regarding preludes there is not much we can do yet (we need to have some mechanism for libraries marking their preludes). Regarding the overall issue, ye we should be able to do that just fine. |
For macros, it is common to put all items they need to access in a dedicated module and mark that module as |
Do we take |
Hmm, yeah, looks like we don't. That's definitely a bug. |
I see this with |
Seems like the right solution for this, and as far as I can see it is not implemented yet. If anything is marked as |
With the latest beta release of derive_more, rust-analyzer is now importing traits from derive_more instead of std: JelteF/derive_more#351 |
What would be needed to hide doc(hidden) reexports? It seems like that should be a fairly easy filter. |
From a super super cursory poke around (so this could be unusable), it looks like there is some functionality already for picking up on rust-analyzer/crates/hir-def/src/attr.rs Line 163 in e31c9f3
We'd just need to see if that's available information when picking the best path? rust-analyzer/crates/hir-def/src/find_path.rs Line 439 in e31c9f3
|
When trying to use |
Okay, I took a look at this and it seems that #15473 (aka 637f496) fixed this issue partially. But it's not fixed when using #[test]
fn respect_doc_hidden_wildcard() {
check_found_path(
r#"
//- /main.rs crate:main deps:std,lazy_static
$0
//- /lazy_static.rs crate:lazy_static deps:core
#[doc(hidden)]
pub use core::ops::*;
//- /std.rs crate:std deps:core
pub use core::ops;
//- /core.rs crate:core
pub mod ops {
pub trait Deref {}
}
"#,
"std::ops::Deref",
expect![[r#"
Plain (imports ✔): std::ops::Deref
Plain (imports ✖): std::ops::Deref
ByCrate(imports ✔): std::ops::Deref
ByCrate(imports ✖): std::ops::Deref
BySelf (imports ✔): std::ops::Deref
BySelf (imports ✖): std::ops::Deref
"#]],
);
} @Veykril do you have any idea how to fix this? |
That is #14079, will close this in favor of that issue instead then |
libadwaita-rs depends on gtk-rs, which depends on glib-rs/gio-rs. The crates often re-export items from their dependencies, especially because of macros needing to use them. Yet, as a user, you will most likely be using items from all 4.
This leads to awkward issues where RA suggests importing "gio::prelude::item" instead of "glib::prelude::item" for an item originally defined in glib, and you end up with a really confusing mess of imports unless you figure out their paths manually.
I think that gtk-rs can improve their module organization to limit this to some degree, but it would maybe help to have RA prioritize importing items from the crate they were originally defined in.
As a related issue, often "item" will only have the import suggestion "gio::prelude::item", despite being also being available in "glib::submodule::item" or something similar. Not sure why that is.
The text was updated successfully, but these errors were encountered: