4

fix: Goto implementation to impls inside blocks by ShoyuVanilla · Pull Request #...

 1 month ago
source link: https://github.com/rust-lang/rust-analyzer/pull/16812
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

fix: Goto implementation to impls inside blocks #16812

Conversation

Contributor

Fixes #3739

rustbot

added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label

Mar 11, 2024

Comment on lines

270 to 221

// Collect nested impls inside function bodies, etc.

for (_, ns) in module_data.scope.entries() {

for module in ns.types.iter().map(|t| t.0).chain(ns.values.iter().map(|t| t.0)) {

let body: Option<DefWithBodyId> = match module {

ModuleDefId::FunctionId(it) => Some(it.into()),

ModuleDefId::EnumVariantId(it) => Some(it.into()),

ModuleDefId::ConstId(it) => Some(it.into()),

ModuleDefId::StaticId(it) => Some(it.into()),

_ => None,

};

if let Some(body) = body {

let body = db.body(body);

for (_, block_def_map) in body.blocks(db.upcast()) {

Self::collect_def_map(db, map, &block_def_map, query_depth);

}

}

}

}

Contributor

Author

The logic is quite verbose, but I couldn't find any good ways that can probe into those blocks 🤔

Member

@Veykril Veykril

left a comment

We intentionally do not look into all blocks there are, as an IDE we try to be lazy and only analyze the crate structure on a global scale, which allows us to skip out on having to look into every body which would slow us down immensely. So supporting local impls like this isn't really possible.

So what we should do instead to make the first case work is have goto_implementation look into the block defmaps of the ADT/trait definition and iterate those. We can query the relevant impls via the *_impls_in_block queries (check for uses of those queries, that should show you how to use thisI think, if not just ask)

ShoyuVanilla reacted with thumbs up emoji

}

#[test]

fn goto_implementation_in_nested_blocks_2() {

This test we cannot support due to performance reasons, see the main review message

ShoyuVanilla reacted with thumbs up emoji

}

#[test]

fn goto_implementation_in_nested_blocks_1() {

This we can support

ShoyuVanilla reacted with thumbs up emoji

Veykril

added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

labels

Mar 12, 2024

Contributor

Author

I'm seeking some performant implementation; is there any way to find BlockId with current cursor location? 🤔

Member

You can turn block expression ast nodes into blocks via

(Note that will only yield Some for blocks that actually have local items or macro calls in them due to perf optimizations)

Though I tihnk it should be enough to just query the modules of the trait / ADT in question as those should be block modules if they are defined in blocks?

ShoyuVanilla reacted with heart emoji

Contributor

Author

Thank you! I'll look into that point 😄

Member

Thanks!
@bors r+

Collaborator

📌 Commit 967a864 has been approved by Veykril

It is now in the queue for this repository.

Collaborator

⌛ Testing commit 967a864 with merge e03df77...

Collaborator

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing e03df77 to master...

bors

merged commit e03df77 into

rust-lang:master

Mar 19, 2024

11 checks passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Veykril

Veykril approved these changes
Assignees

No one assigned

Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

'0 implementations' on type nested in fn

4 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK