diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index e4a103d1b..f97e0bfeb 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -23,7 +23,7 @@ use insta::assert_snapshot; | |||
23 | use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase}; | 23 | use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase}; |
24 | use ra_syntax::{ | 24 | use ra_syntax::{ |
25 | algo, | 25 | algo, |
26 | ast::{self, AstNode}, | 26 | ast::{self, AstNode, AstToken}, |
27 | }; | 27 | }; |
28 | use stdx::format_to; | 28 | use stdx::format_to; |
29 | 29 | ||
@@ -101,7 +101,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
101 | let node = src_ptr.value.to_node(&src_ptr.file_syntax(&db)); | 101 | let node = src_ptr.value.to_node(&src_ptr.file_syntax(&db)); |
102 | 102 | ||
103 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) { | 103 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) { |
104 | (self_param.self_kw_token().text_range(), "self".to_string()) | 104 | (self_param.self_kw_token().unwrap().syntax().text_range(), "self".to_string()) |
105 | } else { | 105 | } else { |
106 | (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) | 106 | (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) |
107 | }; | 107 | }; |
@@ -319,3 +319,33 @@ fn no_such_field_diagnostics() { | |||
319 | "### | 319 | "### |
320 | ); | 320 | ); |
321 | } | 321 | } |
322 | |||
323 | #[test] | ||
324 | fn no_such_field_with_feature_flag_diagnostics() { | ||
325 | let diagnostics = TestDB::with_files( | ||
326 | r#" | ||
327 | //- /lib.rs crate:foo cfg:feature=foo | ||
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 | .0; | ||
349 | |||
350 | assert_snapshot!(diagnostics, @r###""###); | ||
351 | } | ||