mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 12:33:14 +00:00
find_usages limited to actual usages again
This commit is contained in:
parent
ce8121bd65
commit
13ccbb2919
@ -381,6 +381,76 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_field_shorthand_correct_struct() {
|
||||||
|
test_rename(
|
||||||
|
r#"
|
||||||
|
struct Foo {
|
||||||
|
i<|>: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
i: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bar {
|
||||||
|
fn new(i: i32) -> Self {
|
||||||
|
Self { i }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
"j",
|
||||||
|
r#"
|
||||||
|
struct Foo {
|
||||||
|
j: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
i: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bar {
|
||||||
|
fn new(i: i32) -> Self {
|
||||||
|
Self { i }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_shadow_local_for_struct_shorthand() {
|
||||||
|
test_rename(
|
||||||
|
r#"
|
||||||
|
struct Foo {
|
||||||
|
i: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn baz(i<|>: i32) -> Self {
|
||||||
|
let x = Foo { i };
|
||||||
|
{
|
||||||
|
let i = 0;
|
||||||
|
Foo { i }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
"j",
|
||||||
|
r#"
|
||||||
|
struct Foo {
|
||||||
|
i: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn baz(j: i32) -> Self {
|
||||||
|
let x = Foo { i: j };
|
||||||
|
{
|
||||||
|
let i = 0;
|
||||||
|
Foo { i }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rename_mod() {
|
fn test_rename_mod() {
|
||||||
let (analysis, position) = analysis_and_position(
|
let (analysis, position) = analysis_and_position(
|
||||||
|
@ -256,21 +256,21 @@ impl Definition {
|
|||||||
access: reference_access(&def, &name_ref),
|
access: reference_access(&def, &name_ref),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Some(NameRefClass::FieldShorthand { local, field: _ }) => {
|
Some(NameRefClass::FieldShorthand { local, field }) => {
|
||||||
let kind = match self {
|
match self {
|
||||||
Definition::StructField(_) => {
|
Definition::StructField(_) if &field == self => refs.push(Reference {
|
||||||
ReferenceKind::StructFieldShorthandForField
|
file_range: sema.original_range(name_ref.syntax()),
|
||||||
}
|
kind: ReferenceKind::StructFieldShorthandForField,
|
||||||
Definition::Local(_) => ReferenceKind::StructFieldShorthandForLocal,
|
access: reference_access(&field, &name_ref),
|
||||||
_ => continue,
|
}),
|
||||||
};
|
Definition::Local(l) if &local == l => refs.push(Reference {
|
||||||
|
file_range: sema.original_range(name_ref.syntax()),
|
||||||
let file_range = sema.original_range(name_ref.syntax());
|
kind: ReferenceKind::StructFieldShorthandForLocal,
|
||||||
refs.push(Reference {
|
|
||||||
file_range,
|
|
||||||
kind,
|
|
||||||
access: reference_access(&Definition::Local(local), &name_ref),
|
access: reference_access(&Definition::Local(local), &name_ref),
|
||||||
});
|
}),
|
||||||
|
|
||||||
|
_ => {} // not a usage
|
||||||
|
};
|
||||||
}
|
}
|
||||||
_ => {} // not a usage
|
_ => {} // not a usage
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user