test: ensure no_such_field diagnostic don't work for field with disabled cfg

This commit is contained in:
Young-Flash 2024-01-25 19:30:04 +08:00
parent 4505f03fbf
commit 1374bc8c93

View file

@ -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(