aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-09 20:27:06 +0100
committerGitHub <[email protected]>2020-04-09 20:27:06 +0100
commit33df20868da38ca47f22f8bfab36dd4c965cf333 (patch)
treed1651cf0e2cda2b50e13a631c11a5d94e92ea306 /crates/ra_hir_ty
parent9635d8bc44cf58875e97e9e77c3426f746ab7007 (diff)
parentc1317d692321ba5ba8f138067ebefbb9559d098d (diff)
Merge #3918
3918: Add support for feature attributes in struct literal r=matklad a=bnjjj As promised here is the next PR to solve 2 different scenarios with feature flag on struct literal. close #3870 Co-authored-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/src/tests.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index f97e0bfeb..3b078b8c7 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -349,3 +349,63 @@ fn no_such_field_with_feature_flag_diagnostics() {
349 349
350 assert_snapshot!(diagnostics, @r###""###); 350 assert_snapshot!(diagnostics, @r###""###);
351} 351}
352
353#[test]
354fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() {
355 let diagnostics = TestDB::with_files(
356 r#"
357 //- /lib.rs crate:foo cfg:feature=foo
358 struct S {
359 #[cfg(feature = "foo")]
360 foo: u32,
361 #[cfg(not(feature = "foo"))]
362 bar: u32,
363 }
364
365 impl S {
366 #[cfg(feature = "foo")]
367 fn new(foo: u32) -> Self {
368 Self { foo }
369 }
370 #[cfg(not(feature = "foo"))]
371 fn new(bar: u32) -> Self {
372 Self { bar }
373 }
374 }
375 "#,
376 )
377 .diagnostics()
378 .0;
379
380 assert_snapshot!(diagnostics, @r###""###);
381}
382
383#[test]
384fn no_such_field_with_feature_flag_diagnostics_on_struct_fields() {
385 let diagnostics = TestDB::with_files(
386 r#"
387 //- /lib.rs crate:foo cfg:feature=foo
388 struct S {
389 #[cfg(feature = "foo")]
390 foo: u32,
391 #[cfg(not(feature = "foo"))]
392 bar: u32,
393 }
394
395 impl S {
396 fn new(val: u32) -> Self {
397 Self {
398 #[cfg(feature = "foo")]
399 foo: val,
400 #[cfg(not(feature = "foo"))]
401 bar: val,
402 }
403 }
404 }
405 "#,
406 )
407 .diagnostics()
408 .0;
409
410 assert_snapshot!(diagnostics, @r###""###);
411}