Skip to content

Commit

Permalink
Auto merge of rust-lang#16427 - Young-Flash:fix_no_such_field_diagnos…
Browse files Browse the repository at this point in the history
…tics, r=Veykril

fix: filter out cfg disabled filed when lowering `RecordPat`

we should filter out field with disabled cfg when lowering ast `RecordPat` to hir.

close rust-lang/rust-analyzer#16169
  • Loading branch information
bors committed Jan 27, 2024
2 parents 27c3ed9 + 1374bc8 commit 7219414
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ impl ExprCollector<'_> {
let args = record_pat_field_list
.fields()
.filter_map(|f| {
self.check_cfg(&f)?;
let ast_pat = f.pat()?;
let pat = self.collect_pat(ast_pat, binding_list);
let name = f.field_name()?.as_name();
Expand Down
30 changes: 30 additions & 0 deletions crates/ide-diagnostics/src/handlers/no_such_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,36 @@ fn missing_record_expr_field_fixes(
mod tests {
use crate::tests::{check_diagnostics, check_fix, check_no_fix};

#[test]
fn dont_work_for_field_with_disabled_cfg() {
check_diagnostics(
r#"
struct Test {
#[cfg(feature = "hello")]
test: u32,
other: u32
}
fn main() {
let a = Test {
#[cfg(feature = "hello")]
test: 1,
other: 1
};
let Test {
#[cfg(feature = "hello")]
test,
mut other,
..
} = a;
other += 1;
}
"#,
);
}

#[test]
fn no_such_field_diagnostics() {
check_diagnostics(
Expand Down

0 comments on commit 7219414

Please sign in to comment.