Skip to content

Commit 696bee3

Browse files
committed
Auto merge of rust-lang#12997 - Veykril:no-such-field, r=Veykril
fix: Fix panic in `no_such_field` when using tuple fields on record structs
2 parents 3eb340f + 1bb5820 commit 696bee3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

crates/hir/src/source_analyzer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ impl SourceAnalyzer {
368368
let local = if field.name_ref().is_some() {
369369
None
370370
} else {
371+
// Shorthand syntax, resolve to the local
371372
let path = ModPath::from_segments(PathKind::Plain, once(local_name.clone()));
372373
match self.resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) {
373374
Some(ValueNs::LocalBinding(pat_id)) => {

crates/ide-diagnostics/src/handlers/no_such_field.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn missing_record_expr_field_fixes(
6868
}
6969
let new_field = make::record_field(
7070
None,
71-
make::name(&record_expr_field.field_name()?.text()),
71+
make::name(&record_expr_field.field_name()?.ident_token()?.text()),
7272
make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
7373
);
7474

@@ -109,7 +109,7 @@ fn missing_record_expr_field_fixes(
109109

110110
#[cfg(test)]
111111
mod tests {
112-
use crate::tests::{check_diagnostics, check_fix};
112+
use crate::tests::{check_diagnostics, check_fix, check_no_fix};
113113

114114
#[test]
115115
fn no_such_field_diagnostics() {
@@ -277,6 +277,20 @@ struct Foo {
277277
bar: i32,
278278
pub(crate) baz: bool
279279
}
280+
"#,
281+
)
282+
}
283+
284+
#[test]
285+
fn test_tuple_field_on_record_struct() {
286+
check_no_fix(
287+
r#"
288+
struct Struct {}
289+
fn main() {
290+
Struct {
291+
0$0: 0
292+
}
293+
}
280294
"#,
281295
)
282296
}

0 commit comments

Comments
 (0)