mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 14:33:29 +00:00
fix: initializing struct multiple times
This commit is contained in:
parent
83196fd4d9
commit
91ac1d6194
1 changed files with 41 additions and 0 deletions
|
@ -194,6 +194,7 @@ fn replace_usages(edit: &mut SourceChangeBuilder, usages: &UsageSearchResult) {
|
|||
ast::NameLike::NameRef(name) => Some((*range, name)),
|
||||
_ => None,
|
||||
})
|
||||
.rev()
|
||||
.for_each(|(range, name_ref)| {
|
||||
if let Some(initializer) = find_assignment_usage(name_ref) {
|
||||
cov_mark::hit!(replaces_assignment);
|
||||
|
@ -615,6 +616,46 @@ mod foo {
|
|||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field_multiple_initializations() {
|
||||
check_assist(
|
||||
bool_to_enum,
|
||||
r#"
|
||||
struct Foo {
|
||||
$0bar: bool,
|
||||
baz: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let foo1 = Foo { bar: true, baz: false };
|
||||
let foo2 = Foo { bar: false, baz: false };
|
||||
|
||||
if foo1.bar && foo2.bar {
|
||||
println!("foo");
|
||||
}
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
#[derive(PartialEq, Eq)]
|
||||
enum $0Bool { True, False }
|
||||
|
||||
struct Foo {
|
||||
bar: Bool,
|
||||
baz: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let foo1 = Foo { bar: Bool::True, baz: false };
|
||||
let foo2 = Foo { bar: Bool::False, baz: false };
|
||||
|
||||
if foo1.bar == Bool::True && foo2.bar == Bool::True {
|
||||
println!("foo");
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field_non_bool() {
|
||||
cov_mark::check!(not_applicable_non_bool_field);
|
||||
|
|
Loading…
Reference in a new issue