diff options
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 27 |
2 files changed, 34 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 8eef51828..d0912ddaa 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -117,7 +117,13 @@ fn lower_enum( | |||
117 | ast: &InFile<ast::EnumDef>, | 117 | ast: &InFile<ast::EnumDef>, |
118 | module_id: ModuleId, | 118 | module_id: ModuleId, |
119 | ) { | 119 | ) { |
120 | for var in ast.value.variant_list().into_iter().flat_map(|it| it.variants()) { | 120 | let expander = CfgExpander::new(db, ast.file_id, module_id.krate); |
121 | let variants = | ||
122 | ast.value.variant_list().into_iter().flat_map(|it| it.variants()).filter(|var| { | ||
123 | let attrs = expander.parse_attrs(var); | ||
124 | expander.is_cfg_enabled(&attrs) | ||
125 | }); | ||
126 | for var in variants { | ||
121 | trace.alloc( | 127 | trace.alloc( |
122 | || var.clone(), | 128 | || var.clone(), |
123 | || EnumVariantData { | 129 | || EnumVariantData { |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 588d81282..d60732e19 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -361,6 +361,33 @@ fn no_such_field_with_feature_flag_diagnostics() { | |||
361 | } | 361 | } |
362 | 362 | ||
363 | #[test] | 363 | #[test] |
364 | fn no_such_field_enum_with_feature_flag_diagnostics() { | ||
365 | let diagnostics = TestDB::with_files( | ||
366 | r#" | ||
367 | //- /lib.rs crate:foo cfg:feature=foo | ||
368 | enum Foo { | ||
369 | #[cfg(not(feature = "foo"))] | ||
370 | Buz, | ||
371 | #[cfg(feature = "foo")] | ||
372 | Bar, | ||
373 | Baz | ||
374 | } | ||
375 | |||
376 | fn test_fn(f: Foo) { | ||
377 | match f { | ||
378 | Foo::Bar => {}, | ||
379 | Foo::Baz => {}, | ||
380 | } | ||
381 | } | ||
382 | "#, | ||
383 | ) | ||
384 | .diagnostics() | ||
385 | .0; | ||
386 | |||
387 | assert_snapshot!(diagnostics, @r###""###); | ||
388 | } | ||
389 | |||
390 | #[test] | ||
364 | fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() { | 391 | fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() { |
365 | let diagnostics = TestDB::with_files( | 392 | let diagnostics = TestDB::with_files( |
366 | r#" | 393 | r#" |