Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/ra_ide/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ fn check_struct_shorthand_initialization(
if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) {
let field_name = name_ref.syntax().text().to_string();
let field_expr = expr.syntax().text().to_string();
if field_name == field_expr {
let field_name_is_tup_index = name_ref.as_tuple_field().is_some();
if field_name == field_expr && !field_name_is_tup_index {
let mut edit_builder = TextEditBuilder::default();
edit_builder.delete(record_field.syntax().text_range());
edit_builder.insert(record_field.syntax().text_range().start(), field_name);
Expand Down Expand Up @@ -719,6 +720,18 @@ mod tests {
"#,
check_struct_shorthand_initialization,
);
check_not_applicable(
r#"
struct A(usize);

fn main() {
A {
0: 0
}
}
"#,
check_struct_shorthand_initialization,
);

check_apply(
r#"
Expand Down