mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Auto merge of #12997 - Veykril:no-such-field, r=Veykril
fix: Fix panic in `no_such_field` when using tuple fields on record structs
This commit is contained in:
commit
696bee3246
@ -368,6 +368,7 @@ impl SourceAnalyzer {
|
|||||||
let local = if field.name_ref().is_some() {
|
let local = if field.name_ref().is_some() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
// Shorthand syntax, resolve to the local
|
||||||
let path = ModPath::from_segments(PathKind::Plain, once(local_name.clone()));
|
let path = ModPath::from_segments(PathKind::Plain, once(local_name.clone()));
|
||||||
match self.resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) {
|
match self.resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) {
|
||||||
Some(ValueNs::LocalBinding(pat_id)) => {
|
Some(ValueNs::LocalBinding(pat_id)) => {
|
||||||
|
@ -68,7 +68,7 @@ fn missing_record_expr_field_fixes(
|
|||||||
}
|
}
|
||||||
let new_field = make::record_field(
|
let new_field = make::record_field(
|
||||||
None,
|
None,
|
||||||
make::name(&record_expr_field.field_name()?.text()),
|
make::name(&record_expr_field.field_name()?.ident_token()?.text()),
|
||||||
make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
|
make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ fn missing_record_expr_field_fixes(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{check_diagnostics, check_fix};
|
use crate::tests::{check_diagnostics, check_fix, check_no_fix};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_such_field_diagnostics() {
|
fn no_such_field_diagnostics() {
|
||||||
@ -277,6 +277,20 @@ struct Foo {
|
|||||||
bar: i32,
|
bar: i32,
|
||||||
pub(crate) baz: bool
|
pub(crate) baz: bool
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tuple_field_on_record_struct() {
|
||||||
|
check_no_fix(
|
||||||
|
r#"
|
||||||
|
struct Struct {}
|
||||||
|
fn main() {
|
||||||
|
Struct {
|
||||||
|
0$0: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user