-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Shorten type hints for std::iter Iterators #6154
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
Conversation
crates/ide/src/inlay_hints.rs
Outdated
let iter_trait = module.scope(db, None).into_iter().find_map(|(name, def)| match def { | ||
hir::ScopeDef::ModuleDef(ModuleDef::Trait(r#trait)) if name == known::Iterator => { | ||
Some(r#trait) | ||
} | ||
_ => None, | ||
})?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather then iterating through the scope, we should ask for Iterator
directly. Currently, this handled by the FamousDefs
type in assists. It is somewhat ad-hoc, long term, I think we need to make use of rustc_diagnostic_item
attribute, but, for now, using FamousDefs
as an API is the way to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FamousDefs
is crate private, I assume making it pub for this should be alright?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change a thing in FamousDefs
aside from the visibility. It now also checks the crate you directly pass to it whether that is std/core
, due to the crate the hint has already being std/core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the FIXTURE
const can't be cfg(test)
gated anymore for some reason. The cfg just doesn't seem to work properly across crate boundaries?
yup!
…On Tue, 6 Oct 2020 at 20:25, Lukas Wirth ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In crates/ide/src/inlay_hints.rs
<#6154 (comment)>
:
> + let iter_trait = module.scope(db, None).into_iter().find_map(|(name, def)| match def {
+ hir::ScopeDef::ModuleDef(ModuleDef::Trait(r#trait)) if name == known::Iterator => {
+ Some(r#trait)
+ }
+ _ => None,
+ })?;
FamousDefs is crate private, I assume making it pub for this should be
alright?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6154 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3MYLSKY4ELYY4SQN2Y3SJNOHZANCNFSM4SGJX2CQ>
.
|
821a55f
to
4a39de1
Compare
Is there a better way to check this? https://github.com/rust-analyzer/rust-analyzer/blob/821a55ff2f0c215e78dfbb29838bc0572f72e321/crates/ide/src/inlay_hints.rs#L224-L230 |
So sorry for the billion force-pushes I keep forgetting to run |
no worries, force-pushes are OK!
…On Tue, 6 Oct 2020 at 21:27, Lukas Wirth ***@***.***> wrote:
So sorry for the billion force-pushes I keep forgetting to run cargo test
-p xtask to check for whitespaces 😅
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6154 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M6U7BS44JU5IJMTS6TSJNVQXANCNFSM4SGJX2CQ>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crates/ide/src/inlay_hints.rs
Outdated
.path_to_root(db) | ||
.into_iter() | ||
.rev() | ||
.find(|module| module.name(db) == Some(known::iter))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way we use known::item
here and core_iter_Iterator()
is interesting.
We seem to use more or less the same semantics here (some predefined knowledge about sdlib), both using hir
inside, yet in totally different parts of the code.
Any thoughts? (maybe @matklad ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we could add module lookup to FamousDefs
and then check if the module exports the type or something along those lines? Then we wouldn't have to use known
here I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I am not sure what this should look like, but funneling everything via FamousDefs
seems prudent for future refactorability.
I think the right worklist here:
- make sure that IDE bits only use FamousDefs
- replace
FamousDefs::FIXTURE
with more fine-grained opt-ins at the fixture level (we want to have syntax like//- core with:Iterator,IntoIterator
) - try to replace as much of path lookup as possible with lang-items and diagnostics items, but keep an eye on ide/compiler split
For this PR, only keeping everything scoped to FamousDefs should be sufficient.
(I cannot reply to this question directly due to force pushes). |
The iter structs comes from two module definitions, |
This seems to be chalk failing at that depth, it returns |
Okay I think everything so far got addressed now 👍 |
Fixes #3750.
This re-exports the
hir_expand::name::known
module to be able to fetch theIterator
anditer
names.I'm not sure if there is anything to do with
Solution::Ambig
innormalize_trait_assoc_type
or whether discarding those results is always wanted.