mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
add support of cfg attributes on enum variants #4279
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
parent
682c079043
commit
bed115d6e1
2 changed files with 34 additions and 1 deletions
|
@ -117,7 +117,13 @@ fn lower_enum(
|
||||||
ast: &InFile<ast::EnumDef>,
|
ast: &InFile<ast::EnumDef>,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
) {
|
) {
|
||||||
for var in ast.value.variant_list().into_iter().flat_map(|it| it.variants()) {
|
let expander = CfgExpander::new(db, ast.file_id, module_id.krate);
|
||||||
|
let variants =
|
||||||
|
ast.value.variant_list().into_iter().flat_map(|it| it.variants()).filter(|var| {
|
||||||
|
let attrs = expander.parse_attrs(var);
|
||||||
|
expander.is_cfg_enabled(&attrs)
|
||||||
|
});
|
||||||
|
for var in variants {
|
||||||
trace.alloc(
|
trace.alloc(
|
||||||
|| var.clone(),
|
|| var.clone(),
|
||||||
|| EnumVariantData {
|
|| EnumVariantData {
|
||||||
|
|
|
@ -360,6 +360,33 @@ fn no_such_field_with_feature_flag_diagnostics() {
|
||||||
assert_snapshot!(diagnostics, @r###""###);
|
assert_snapshot!(diagnostics, @r###""###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_such_field_enum_with_feature_flag_diagnostics() {
|
||||||
|
let diagnostics = TestDB::with_files(
|
||||||
|
r#"
|
||||||
|
//- /lib.rs crate:foo cfg:feature=foo
|
||||||
|
enum Foo {
|
||||||
|
#[cfg(not(feature = "foo"))]
|
||||||
|
Buz,
|
||||||
|
#[cfg(feature = "foo")]
|
||||||
|
Bar,
|
||||||
|
Baz
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_fn(f: Foo) {
|
||||||
|
match f {
|
||||||
|
Foo::Bar => {},
|
||||||
|
Foo::Baz => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.diagnostics()
|
||||||
|
.0;
|
||||||
|
|
||||||
|
assert_snapshot!(diagnostics, @r###""###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() {
|
fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() {
|
||||||
let diagnostics = TestDB::with_files(
|
let diagnostics = TestDB::with_files(
|
||||||
|
|
Loading…
Reference in a new issue