mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
fix: consider assignee expressions in record fields exhaustiveness check
This commit is contained in:
parent
64758bd481
commit
805ac666ca
2 changed files with 35 additions and 1 deletions
|
@ -305,7 +305,10 @@ pub fn record_literal_missing_fields(
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
|
) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
|
||||||
let (fields, exhaustive) = match expr {
|
let (fields, exhaustive) = match expr {
|
||||||
Expr::RecordLit { fields, spread, .. } => (fields, spread.is_none()),
|
Expr::RecordLit { fields, spread, ellipsis, is_assignee_expr, .. } => {
|
||||||
|
let exhaustive = if *is_assignee_expr { !*ellipsis } else { spread.is_none() };
|
||||||
|
(fields, exhaustive)
|
||||||
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -292,6 +292,37 @@ fn x(a: S) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_record_expr_in_assignee_expr() {
|
||||||
|
check_diagnostics(
|
||||||
|
r"
|
||||||
|
struct S { s: usize, t: usize }
|
||||||
|
struct S2 { s: S, t: () }
|
||||||
|
struct T(S);
|
||||||
|
fn regular(a: S) {
|
||||||
|
let s;
|
||||||
|
S { s, .. } = a;
|
||||||
|
}
|
||||||
|
fn nested(a: S2) {
|
||||||
|
let s;
|
||||||
|
S2 { s: S { s, .. }, .. } = a;
|
||||||
|
}
|
||||||
|
fn in_tuple(a: (S,)) {
|
||||||
|
let s;
|
||||||
|
(S { s, .. },) = a;
|
||||||
|
}
|
||||||
|
fn in_array(a: [S;1]) {
|
||||||
|
let s;
|
||||||
|
[S { s, .. },] = a;
|
||||||
|
}
|
||||||
|
fn in_tuple_struct(a: T) {
|
||||||
|
let s;
|
||||||
|
T(S { s, .. }) = a;
|
||||||
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn range_mapping_out_of_macros() {
|
fn range_mapping_out_of_macros() {
|
||||||
check_fix(
|
check_fix(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue