@@ -315,6 +315,7 @@ fn should_hide_param_name_hint(
315
315
param_name : & str ,
316
316
argument : & ast:: Expr ,
317
317
) -> bool {
318
+ // These are to be tested in the `parameter_hint_heuristics` test
318
319
// hide when:
319
320
// - the parameter name is a suffix of the function's name
320
321
// - the argument is an enum whose name is equal to the parameter
@@ -395,7 +396,7 @@ fn get_string_representation(expr: &ast::Expr) -> Option<String> {
395
396
ast:: Expr :: MethodCallExpr ( method_call_expr) => {
396
397
let name_ref = method_call_expr. name_ref ( ) ?;
397
398
match name_ref. text ( ) . as_str ( ) {
398
- "clone" => method_call_expr. receiver ( ) . map ( |rec| rec. to_string ( ) ) ,
399
+ "clone" | "as_ref" => method_call_expr. receiver ( ) . map ( |rec| rec. to_string ( ) ) ,
399
400
name_ref => Some ( name_ref. to_owned ( ) ) ,
400
401
}
401
402
}
@@ -521,6 +522,8 @@ fn main() {
521
522
) ;
522
523
}
523
524
525
+ // Parameter hint tests
526
+
524
527
#[ test]
525
528
fn param_hints_only ( ) {
526
529
check_params (
@@ -558,6 +561,15 @@ fn main() {
558
561
check_params (
559
562
r#"
560
563
fn param_with_underscore(with_underscore: i32) -> i32 { with_underscore }
564
+ fn main() {
565
+ let _x = param_with_underscore(
566
+ 4,
567
+ );
568
+ }"# ,
569
+ ) ;
570
+ check_params (
571
+ r#"
572
+ fn param_with_underscore(underscore: i32) -> i32 { underscore }
561
573
fn main() {
562
574
let _x = param_with_underscore(
563
575
4,
@@ -583,30 +595,32 @@ fn main() {
583
595
fn never_hide_param_when_multiple_params ( ) {
584
596
check_params (
585
597
r#"
586
- fn foo(bar : i32, baz : i32) -> i32 { bar + baz }
598
+ fn foo(foo : i32, bar : i32) -> i32 { bar + baz }
587
599
fn main() {
588
600
let _x = foo(
589
601
4,
590
- //^ bar
602
+ //^ foo
591
603
8,
592
- //^ baz
604
+ //^ bar
593
605
);
594
606
}"# ,
595
607
) ;
596
608
}
597
609
598
610
#[ test]
599
- fn hide_param_hints_for_clones ( ) {
611
+ fn param_hints_look_through_as_ref_and_clone ( ) {
600
612
check_params (
601
613
r#"
602
- fn foo(bar: i32, baz: String, qux: f32) {}
614
+ fn foo(bar: i32, baz: f32) {}
603
615
604
616
fn main() {
605
617
let bar = 3;
606
618
let baz = &"baz";
607
619
let fez = 1.0;
608
- foo(bar.clone(), baz.clone(), fez.clone());
609
- //^^^^^^^^^^^ qux
620
+ foo(bar.clone(), bar.clone());
621
+ //^^^^^^^^^^^ baz
622
+ foo(bar.as_ref(), bar.as_ref());
623
+ //^^^^^^^^^^^^ baz
610
624
}
611
625
"# ,
612
626
) ;
@@ -639,18 +653,18 @@ fn main() {
639
653
r#"pub fn test(a: i32, b: i32) -> [i32; 2] { [a, b] }
640
654
fn main() {
641
655
test(
642
- 0x0fab272b ,
643
- //^^^^^^^^^^ a
644
- 0x0fab272b
645
- //^^^^^^^^^^ b
656
+ 0xa_b ,
657
+ //^^^^^ a
658
+ 0xa_b,
659
+ //^^^^^ b
646
660
);
647
661
}"# ,
648
662
)
649
663
}
650
664
651
665
#[ test]
652
666
fn function_call_parameter_hint ( ) {
653
- check (
667
+ check_params (
654
668
r#"
655
669
enum Option<T> { None, Some(T) }
656
670
use Option::*;
@@ -685,7 +699,6 @@ fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
685
699
686
700
fn main() {
687
701
let not_literal = 1;
688
- //^^^^^^^^^^^ i32
689
702
let _: i32 = test_func(1, 2, "hello", 3, not_literal);
690
703
//^ foo ^ bar ^^^^^^^ msg ^^^^^^^^^^^ last
691
704
let t: Test = Test {};
@@ -712,97 +725,65 @@ fn main() {
712
725
}
713
726
714
727
#[ test]
715
- fn omitted_parameters_hints_heuristics ( ) {
716
- check_with_config (
717
- InlayHintsConfig { max_length : Some ( 8 ) , ..TEST_CONFIG } ,
728
+ fn parameter_hint_heuristics ( ) {
729
+ check_params (
718
730
r#"
731
+ fn check(ra_fixture_thing: &str) {}
732
+
719
733
fn map(f: i32) {}
720
734
fn filter(predicate: i32) {}
721
735
722
- struct TestVarContainer {
723
- test_var: i32,
724
- }
725
-
726
- impl TestVarContainer {
727
- fn test_var(&self) -> i32 {
728
- self.test_var
729
- }
730
- }
736
+ fn strip_suffix(suffix: &str) {}
737
+ fn stripsuffix(suffix: &str) {}
738
+ fn same(same: u32) {}
739
+ fn same2(_same2: u32) {}
731
740
732
- struct Test {}
733
-
734
- impl Test {
735
- fn map(self, f: i32) -> Self {
736
- self
737
- }
738
-
739
- fn filter(self, predicate: i32) -> Self {
740
- self
741
- }
742
-
743
- fn field(self, value: i32) -> Self {
744
- self
745
- }
746
-
747
- fn no_hints_expected(&self, _: i32, test_var: i32) {}
748
-
749
- fn frob(&self, frob: bool) {}
750
- }
751
-
752
- struct Param {}
753
-
754
- fn different_order(param: &Param) {}
755
- fn different_order_mut(param: &mut Param) {}
756
- fn has_underscore(_param: bool) {}
757
741
fn enum_matches_param_name(completion_kind: CompletionKind) {}
758
- fn param_destructuring_omitted_1((a, b): (u32, u32)) {}
759
- fn param_destructuring_omitted_2(TestVarContainer { test_var: _ }: TestVarContainer) {}
760
742
761
- fn twiddle(twiddle: bool ) {}
762
- fn doo(_doo: bool ) {}
743
+ fn foo(param: u32 ) {}
744
+ fn bar(param_eter: u32 ) {}
763
745
764
746
enum CompletionKind {
765
747
Keyword,
766
748
}
767
749
768
- fn main() {
769
- let container: TestVarContainer = TestVarContainer { test_var: 42 };
770
- let test: Test = Test {};
771
-
772
- map(22);
773
- filter(33);
750
+ fn non_ident_pat((a, b): (u32, u32)) {}
774
751
775
- let test_processed: Test = test.map(1).filter(2).field(3);
776
-
777
- let test_var: i32 = 55;
778
- test_processed.no_hints_expected(22, test_var);
779
- test_processed.no_hints_expected(33, container.test_var);
780
- test_processed.no_hints_expected(44, container.test_var());
781
- test_processed.frob(false);
782
-
783
- twiddle(true);
784
- doo(true);
785
-
786
- const TWIDDLE_UPPERCASE: bool = true;
787
- twiddle(TWIDDLE_UPPERCASE);
752
+ fn main() {
753
+ check("");
788
754
789
- let mut param_begin: Param = Param {};
790
- different_order(¶m_begin);
791
- different_order(&mut param_begin);
755
+ map(0);
756
+ filter(0);
792
757
793
- let param: bool = true;
794
- has_underscore(param);
758
+ strip_suffix("");
759
+ stripsuffix("");
760
+ //^^ suffix
761
+ same(0);
762
+ same2(0);
795
763
796
764
enum_matches_param_name(CompletionKind::Keyword);
797
765
798
- let a: f64 = 7.0;
799
- let b: f64 = 4.0;
800
- let _: f64 = a.div_euclid(b);
801
- let _: f64 = a.abs_sub(b);
802
-
803
- let range: (u32, u32) = (3, 5);
804
- param_destructuring_omitted_1(range);
805
- param_destructuring_omitted_2(container);
766
+ let param = 0;
767
+ foo(param);
768
+ let param_end = 0;
769
+ foo(param_end);
770
+ let start_param = 0;
771
+ foo(start_param);
772
+ let param2 = 0;
773
+ foo(param2);
774
+ //^^^^^^ param
775
+
776
+ let param_eter = 0;
777
+ bar(param_eter);
778
+ let param_eter_end = 0;
779
+ bar(param_eter_end);
780
+ let start_param_eter = 0;
781
+ bar(start_param_eter);
782
+ let param_eter2 = 0;
783
+ bar(param_eter2);
784
+ //^^^^^^^^^^^ param_eter
785
+
786
+ non_ident_pat((0, 0));
806
787
}"# ,
807
788
) ;
808
789
}
0 commit comments