aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r--crates/ra_hir_ty/src/expr.rs12
-rw-r--r--crates/ra_hir_ty/src/tests.rs29
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 1e7395b16..6547eedae 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};
10use hir_expand::{diagnostics::DiagnosticSink, name::Name}; 10use hir_expand::{diagnostics::DiagnosticSink, name::Name};
11use ra_syntax::ast; 11use ra_syntax::{ast, AstPtr};
12use ra_syntax::AstPtr;
13use rustc_hash::FxHashSet; 12use rustc_hash::FxHashSet;
14 13
15use crate::{ 14use crate::{
@@ -167,7 +166,14 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
167 166
168 let variant_data = variant_data(db.upcast(), variant_def); 167 let variant_data = variant_data(db.upcast(), variant_def);
169 168
170 let lit_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); 169 let lit_fields: FxHashSet<_> = fields
170 .iter()
171 .filter_map(|f| {
172 // TODO: check if cfg_is_enabled with .attrs ?
173
174 Some(&f.name)
175 })
176 .collect();
171 let missed_fields: Vec<Name> = variant_data 177 let missed_fields: Vec<Name> = variant_data
172 .fields() 178 .fields()
173 .iter() 179 .iter()
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index e4a103d1b..e6ac0aec3 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -319,3 +319,32 @@ fn no_such_field_diagnostics() {
319 "### 319 "###
320 ); 320 );
321} 321}
322
323#[test]
324fn no_such_field_with_feature_flag_diagnostics() {
325 let diagnostics = TestDB::with_files(
326 r#"
327 //- /lib.rs
328 struct MyStruct {
329 my_val: usize,
330 #[cfg(feature = "foo")]
331 bar: bool,
332 }
333
334 impl MyStruct {
335 #[cfg(feature = "foo")]
336 pub(crate) fn new(my_val: usize, bar: bool) -> Self {
337 Self { my_val, bar }
338 }
339
340 #[cfg(not(feature = "foo"))]
341 pub(crate) fn new(my_val: usize, _bar: bool) -> Self {
342 Self { my_val }
343 }
344 }
345 "#,
346 )
347 .diagnostics();
348
349 assert_snapshot!(diagnostics, "");
350}