-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Rename List::iter
and friends to avoid auto-import conflicts
#15088
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
Comments
iter_elements is my preference. This should have a comment explaining why it was changed to avoid reversion. |
My issue with Prefixing everything with I don’t use auto-importers, so perhaps I’m not the best case subject. |
I really feel like this is the wrong way of solving it, there should probably be some way to disable importing single traits on the auto importer, and harming the normal experience for this case just seems suboptimal. intellij-rust/intellij-rust#9123 perhaps this may solve the issue? |
As an alternative to the
Unfortunately that's an UI setting the user has to set, moreover this is intellij-rust only and doesn't have an equivalent for rust-analyzer, so I don't think this a reasonable solution for now. Maybe in the future, but IMO this issue needs a fix in the short term because I see lot of users being hit by it. |
Agreed: I think we should move forward with a rename. It's fine if a niche method gets a slightly less convenient name to avoid splash damage, especially for beginners. |
If you do the renaming, I feel like |
Additionally, I think it might be better prefix for the subtraits (e.g. Of course, One potential confusion is with methods like
Yeah I don't think this should be something we have to code around. Unfortunately, it's been an issue for at least a year and it's likely users are going to keep running into it—especially newer users or those just learning Rust. So while I'd rather we not do a rename, it does seem like we should (at least until there's some universal-ish way for a crate to opt-out of auto-importing certain paths). |
Fwiw rust-lang/rust-analyzer#18179 might be helping out here as well |
rust-lang/rust-analyzer#18179 is merged I think this solves this problem. Renaming the items seems to be controversial anyway. |
I like that RA PR, but it's not clear how Bevy uses it. Do we submit something to RA? Do users have to configure it? What about other language servers? |
Looks like it would be a |
I don't think that's a good enough fix: this is the most dangerous for beginners, who won't have set up their environment for weird footguns like this. |
We are likely going to add tool attributes a la |
Makes sense :) As RA approaches stabilization for that, I'd really like if we could pull in the Rust project and coordinate on something upstream to ensure cross-tooling compatibility. Let me know when you're there and I'll help connect folks! |
Just wanted to add anohter +1 to this as I hit this issue recently. Having auto-complete add the trait made it ever so much more confusing. See this gist if you want to see a nice "newbie" example :) |
Fyi, rust-lang/rust-analyzer#19375 will give you a mechanism to properly fix this (for rust-analyzer at least) without having to rename things. Its mainly stuck on initial design considerations (we won't be promising that the design won't change either way though) |
FYI rust-lang/rust-analyzer#19375 is now merged, so you can put |
What problem does this solve or what need does it fill?
It's common to have users write their Bevy code in an IDE that supports auto-import. This is not always helpful as sometimes the wrong trait is pulled in.
A common example of this is accidentally importing
List
frombevy_reflect
when autocompleting.iter()
.There are other methods this can happen with too, such as with
List::get
,Array::is_empty
, etc.What solution would you like?
We should consider making the method names more specific to reflection and/or their trait.
For example,
List::iter
could becomeList::iter_elements
,List::reflect_iter
, orList::list_iter
.We'd probably want to do a similar thing for other traits like
Array
,Map
, andSet
.The main thing we'd need to work out is what the new naming convention should be and which traits/methods need it.
What alternative(s) have you considered?
self
withdyn Trait
(e.g.my_vec.iter()
becomesList::iter(&my_vec)
)Ideally, the auto-importers would simply avoid pulling in a trait when the method exists on either the type or the type's deref target. Or even just provide a way for us to hide/discourage certain traits from being auto-imported.
Additional context
See also #15002 for an example of this being an issue.
The text was updated successfully, but these errors were encountered: