aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/diagnostics/expr.rs57
-rw-r--r--crates/hir_ty/src/tests/simple.rs19
-rw-r--r--crates/hir_ty/src/tests/traits.rs21
3 files changed, 97 insertions, 0 deletions
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs
index 71b2cade0..3909ad354 100644
--- a/crates/hir_ty/src/diagnostics/expr.rs
+++ b/crates/hir_ty/src/diagnostics/expr.rs
@@ -690,4 +690,61 @@ fn main() {
690"#, 690"#,
691 ) 691 )
692 } 692 }
693
694 #[test]
695 fn cfgd_out_call_arguments() {
696 check_diagnostics(
697 r#"
698struct C(#[cfg(FALSE)] ());
699impl C {
700 fn new() -> Self {
701 Self(
702 #[cfg(FALSE)]
703 (),
704 )
705 }
706
707 fn method(&self) {}
708}
709
710fn main() {
711 C::new().method(#[cfg(FALSE)] 0);
712}
713 "#,
714 );
715 }
716
717 #[test]
718 fn cfgd_out_fn_params() {
719 check_diagnostics(
720 r#"
721fn foo(#[cfg(NEVER)] x: ()) {}
722
723struct S;
724
725impl S {
726 fn method(#[cfg(NEVER)] self) {}
727 fn method2(#[cfg(NEVER)] self, arg: u8) {}
728 fn method3(self, #[cfg(NEVER)] arg: u8) {}
729}
730
731extern "C" {
732 fn fixed(fixed: u8, #[cfg(NEVER)] ...);
733 fn varargs(#[cfg(not(NEVER))] ...);
734}
735
736fn main() {
737 foo();
738 S::method();
739 S::method2(0);
740 S::method3(S);
741 S.method3();
742 unsafe {
743 fixed(0);
744 varargs(1, 2, 3);
745 }
746}
747 "#,
748 )
749 }
693} 750}
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs
index f5069eba5..bcc43ed70 100644
--- a/crates/hir_ty/src/tests/simple.rs
+++ b/crates/hir_ty/src/tests/simple.rs
@@ -2545,3 +2545,22 @@ fn test() {
2545 "#]], 2545 "#]],
2546 ) 2546 )
2547} 2547}
2548
2549#[test]
2550fn cfgd_out_assoc_items() {
2551 check_types(
2552 r#"
2553struct S;
2554
2555impl S {
2556 #[cfg(FALSE)]
2557 const C: S = S;
2558}
2559
2560fn f() {
2561 S::C;
2562 //^^^^ {unknown}
2563}
2564 "#,
2565 )
2566}
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 93d3ad020..8270fa219 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -3253,3 +3253,24 @@ fn f() {
3253 "#, 3253 "#,
3254 ); 3254 );
3255} 3255}
3256
3257#[test]
3258fn nested_inner_function_calling_self() {
3259 check_infer(
3260 r#"
3261struct S;
3262fn f() {
3263 fn inner() -> S {
3264 let s = inner();
3265 }
3266}
3267 "#,
3268 expect![[r#"
3269 17..73 '{ ... } }': ()
3270 39..71 '{ ... }': ()
3271 53..54 's': S
3272 57..62 'inner': fn inner() -> S
3273 57..64 'inner()': S
3274 "#]],
3275 )
3276}