diff options
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 29 |
2 files changed, 38 insertions, 3 deletions
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index b7b476b4c..eb1209d08 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -8,8 +8,7 @@ use hir_def::{ | |||
8 | AdtId, FunctionId, | 8 | AdtId, FunctionId, |
9 | }; | 9 | }; |
10 | use hir_expand::{diagnostics::DiagnosticSink, name::Name}; | 10 | use hir_expand::{diagnostics::DiagnosticSink, name::Name}; |
11 | use ra_syntax::ast; | 11 | use ra_syntax::{ast, AstPtr}; |
12 | use ra_syntax::AstPtr; | ||
13 | use rustc_hash::FxHashSet; | 12 | use rustc_hash::FxHashSet; |
14 | 13 | ||
15 | use crate::{ | 14 | use crate::{ |
@@ -82,7 +81,14 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
82 | 81 | ||
83 | let variant_data = variant_data(db.upcast(), variant_def); | 82 | let variant_data = variant_data(db.upcast(), variant_def); |
84 | 83 | ||
85 | let lit_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); | 84 | let lit_fields: FxHashSet<_> = fields |
85 | .iter() | ||
86 | .filter_map(|f| { | ||
87 | // TODO: check if cfg_is_enabled with .attrs ? | ||
88 | |||
89 | Some(&f.name) | ||
90 | }) | ||
91 | .collect(); | ||
86 | let missed_fields: Vec<Name> = variant_data | 92 | let missed_fields: Vec<Name> = variant_data |
87 | .fields() | 93 | .fields() |
88 | .iter() | 94 | .iter() |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 027e5a8f8..c3d793cc2 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -318,3 +318,32 @@ fn no_such_field_diagnostics() { | |||
318 | "### | 318 | "### |
319 | ); | 319 | ); |
320 | } | 320 | } |
321 | |||
322 | #[test] | ||
323 | fn no_such_field_with_feature_flag_diagnostics() { | ||
324 | let diagnostics = TestDB::with_files( | ||
325 | r#" | ||
326 | //- /lib.rs | ||
327 | struct MyStruct { | ||
328 | my_val: usize, | ||
329 | #[cfg(feature = "foo")] | ||
330 | bar: bool, | ||
331 | } | ||
332 | |||
333 | impl MyStruct { | ||
334 | #[cfg(feature = "foo")] | ||
335 | pub(crate) fn new(my_val: usize, bar: bool) -> Self { | ||
336 | Self { my_val, bar } | ||
337 | } | ||
338 | |||
339 | #[cfg(not(feature = "foo"))] | ||
340 | pub(crate) fn new(my_val: usize, _bar: bool) -> Self { | ||
341 | Self { my_val } | ||
342 | } | ||
343 | } | ||
344 | "#, | ||
345 | ) | ||
346 | .diagnostics(); | ||
347 | |||
348 | assert_snapshot!(diagnostics, ""); | ||
349 | } | ||