mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Reject tuple index for missing fields assist
This commit is contained in:
parent
8f1792fde2
commit
e55e6da13a
1 changed files with 8 additions and 0 deletions
|
@ -66,6 +66,14 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
||||||
.on::<hir::diagnostics::MissingFields, _>(|d| {
|
.on::<hir::diagnostics::MissingFields, _>(|d| {
|
||||||
let mut field_list = d.ast(db);
|
let mut field_list = d.ast(db);
|
||||||
for f in d.missed_fields.iter() {
|
for f in d.missed_fields.iter() {
|
||||||
|
// Note that although we could add a diagnostics to
|
||||||
|
// fill the missing tuple field, e.g :
|
||||||
|
// `struct A(usize);`
|
||||||
|
// `let a = A { 0: () }`
|
||||||
|
// but it is uncommon usage and it should not be encouraged.
|
||||||
|
if f.as_tuple_index().is_some() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let field = make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit()));
|
let field = make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit()));
|
||||||
field_list = field_list.append_field(&field);
|
field_list = field_list.append_field(&field);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue