Auto merge of #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 https://github.com/rust-lang/rust-analyzer/issues/16169
This commit is contained in:
commit
7219414e81
@ -1335,6 +1335,7 @@ impl ExprCollector<'_> {
|
|||||||
let args = record_pat_field_list
|
let args = record_pat_field_list
|
||||||
.fields()
|
.fields()
|
||||||
.filter_map(|f| {
|
.filter_map(|f| {
|
||||||
|
self.check_cfg(&f)?;
|
||||||
let ast_pat = f.pat()?;
|
let ast_pat = f.pat()?;
|
||||||
let pat = self.collect_pat(ast_pat, binding_list);
|
let pat = self.collect_pat(ast_pat, binding_list);
|
||||||
let name = f.field_name()?.as_name();
|
let name = f.field_name()?.as_name();
|
||||||
|
@ -128,6 +128,36 @@ fn missing_record_expr_field_fixes(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{check_diagnostics, check_fix, check_no_fix};
|
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]
|
#[test]
|
||||||
fn no_such_field_diagnostics() {
|
fn no_such_field_diagnostics() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user