Skip to content

Commit 7219414

Browse files
committed
Auto merge of rust-lang#16427 - Young-Flash:fix_no_such_field_diagnostics, 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
2 parents 27c3ed9 + 1374bc8 commit 7219414

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

crates/hir-def/src/body/lower.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ impl ExprCollector<'_> {
13351335
let args = record_pat_field_list
13361336
.fields()
13371337
.filter_map(|f| {
1338+
self.check_cfg(&f)?;
13381339
let ast_pat = f.pat()?;
13391340
let pat = self.collect_pat(ast_pat, binding_list);
13401341
let name = f.field_name()?.as_name();

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,36 @@ fn missing_record_expr_field_fixes(
128128
mod tests {
129129
use crate::tests::{check_diagnostics, check_fix, check_no_fix};
130130

131+
#[test]
132+
fn dont_work_for_field_with_disabled_cfg() {
133+
check_diagnostics(
134+
r#"
135+
struct Test {
136+
#[cfg(feature = "hello")]
137+
test: u32,
138+
other: u32
139+
}
140+
141+
fn main() {
142+
let a = Test {
143+
#[cfg(feature = "hello")]
144+
test: 1,
145+
other: 1
146+
};
147+
148+
let Test {
149+
#[cfg(feature = "hello")]
150+
test,
151+
mut other,
152+
..
153+
} = a;
154+
155+
other += 1;
156+
}
157+
"#,
158+
);
159+
}
160+
131161
#[test]
132162
fn no_such_field_diagnostics() {
133163
check_diagnostics(

0 commit comments

Comments
 (0)