Merge pull request #19094 from ChayimFriedman2/use-body

fix: Fix IDE resolution of `use` inside a body
This commit is contained in:
Laurențiu Nicola 2025-02-05 07:16:35 +00:00 committed by GitHub
commit 2ad4ec5b73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 3 deletions

View File

@ -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))

View File

@ -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;
}
"#,
);
}
}

View File

@ -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(