Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5467091

Browse files
Fix IDE resolution of use inside a body
We stopped the expression search too early because `use` is an item.
1 parent 1ba7a38 commit 5467091

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,11 @@ fn scope_for(
12521252
node: InFile<&SyntaxNode>,
12531253
) -> Option<ScopeId> {
12541254
node.ancestors_with_macros(db.upcast())
1255-
.take_while(|it| !ast::Item::can_cast(it.kind()) || ast::MacroCall::can_cast(it.kind()))
1255+
.take_while(|it| {
1256+
!ast::Item::can_cast(it.kind())
1257+
|| ast::MacroCall::can_cast(it.kind())
1258+
|| ast::Use::can_cast(it.kind())
1259+
})
12561260
.filter_map(|it| it.map(ast::Expr::cast).transpose())
12571261
.filter_map(|it| source_map.node_expr(it.as_ref())?.as_expr())
12581262
.find_map(|it| scopes.scope_for(it))

src/tools/rust-analyzer/crates/ide/src/goto_definition.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,4 +3272,22 @@ fn f() {
32723272
"#,
32733273
);
32743274
}
3275+
3276+
#[test]
3277+
fn use_inside_body() {
3278+
check(
3279+
r#"
3280+
fn main() {
3281+
mod nice_module {
3282+
pub(super) struct NiceStruct;
3283+
// ^^^^^^^^^^
3284+
}
3285+
3286+
use nice_module::NiceStruct$0;
3287+
3288+
let _ = NiceStruct;
3289+
}
3290+
"#,
3291+
);
3292+
}
32753293
}

0 commit comments

Comments
 (0)