mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Merge pull request #19094 from ChayimFriedman2/use-body
fix: Fix IDE resolution of `use` inside a body
This commit is contained in:
commit
2ad4ec5b73
@ -1252,7 +1252,11 @@ fn scope_for(
|
||||
node: InFile<&SyntaxNode>,
|
||||
) -> Option<ScopeId> {
|
||||
node.ancestors_with_macros(db.upcast())
|
||||
.take_while(|it| !ast::Item::can_cast(it.kind()) || ast::MacroCall::can_cast(it.kind()))
|
||||
.take_while(|it| {
|
||||
!ast::Item::can_cast(it.kind())
|
||||
|| ast::MacroCall::can_cast(it.kind())
|
||||
|| ast::Use::can_cast(it.kind())
|
||||
})
|
||||
.filter_map(|it| it.map(ast::Expr::cast).transpose())
|
||||
.filter_map(|it| source_map.node_expr(it.as_ref())?.as_expr())
|
||||
.find_map(|it| scopes.scope_for(it))
|
||||
|
@ -3272,4 +3272,22 @@ fn f() {
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_inside_body() {
|
||||
check(
|
||||
r#"
|
||||
fn main() {
|
||||
mod nice_module {
|
||||
pub(super) struct NiceStruct;
|
||||
// ^^^^^^^^^^
|
||||
}
|
||||
|
||||
use nice_module::NiceStruct$0;
|
||||
|
||||
let _ = NiceStruct;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2001,19 +2001,37 @@ impl Foo {
|
||||
"foo",
|
||||
r#"
|
||||
fn f($0self) -> i32 {
|
||||
use self as _;
|
||||
self.i
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
fn f(foo: _) -> i32 {
|
||||
use self as _;
|
||||
foo.i
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_type_value_ns_confuse() {
|
||||
// Test that we don't rename items from different namespaces.
|
||||
check(
|
||||
"bar",
|
||||
r#"
|
||||
struct foo {}
|
||||
fn f(foo$0: i32) -> i32 {
|
||||
use foo as _;
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
struct foo {}
|
||||
fn f(bar: i32) -> i32 {
|
||||
use foo as _;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_in_path_to_parameter() {
|
||||
check(
|
||||
|
Loading…
x
Reference in New Issue
Block a user