• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Tests that don't fit into a specific category.
2 
3 use expect_test::{expect, Expect};
4 
5 use crate::tests::{
6     check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character,
7 };
8 
check_no_kw(ra_fixture: &str, expect: Expect)9 fn check_no_kw(ra_fixture: &str, expect: Expect) {
10     let actual = completion_list_no_kw(ra_fixture);
11     expect.assert_eq(&actual)
12 }
13 
check(ra_fixture: &str, expect: Expect)14 fn check(ra_fixture: &str, expect: Expect) {
15     let actual = completion_list(ra_fixture);
16     expect.assert_eq(&actual)
17 }
18 
check_with_trigger_character( ra_fixture: &str, trigger_character: Option<char>, expect: Expect, )19 pub(crate) fn check_with_trigger_character(
20     ra_fixture: &str,
21     trigger_character: Option<char>,
22     expect: Expect,
23 ) {
24     let actual = completion_list_with_trigger_character(ra_fixture, trigger_character);
25     expect.assert_eq(&actual)
26 }
27 
28 #[test]
completes_if_prefix_is_keyword()29 fn completes_if_prefix_is_keyword() {
30     check_edit(
31         "wherewolf",
32         r#"
33 fn main() {
34     let wherewolf = 92;
35     drop(where$0)
36 }
37 "#,
38         r#"
39 fn main() {
40     let wherewolf = 92;
41     drop(wherewolf)
42 }
43 "#,
44     )
45 }
46 
47 /// Regression test for issue #6091.
48 #[test]
correctly_completes_module_items_prefixed_with_underscore()49 fn correctly_completes_module_items_prefixed_with_underscore() {
50     check_edit(
51         "_alpha",
52         r#"
53 fn main() {
54     _$0
55 }
56 fn _alpha() {}
57 "#,
58         r#"
59 fn main() {
60     _alpha()$0
61 }
62 fn _alpha() {}
63 "#,
64     )
65 }
66 
67 #[test]
completes_prelude()68 fn completes_prelude() {
69     check_no_kw(
70         r#"
71 //- /main.rs edition:2018 crate:main deps:std
72 fn foo() { let x: $0 }
73 
74 //- /std/lib.rs crate:std
75 pub mod prelude {
76     pub mod rust_2018 {
77         pub struct Option;
78     }
79 }
80 "#,
81         expect![[r#"
82                 md std
83                 st Option
84                 bt u32
85             "#]],
86     );
87 }
88 
89 #[test]
completes_prelude_macros()90 fn completes_prelude_macros() {
91     check_no_kw(
92         r#"
93 //- /main.rs edition:2018 crate:main deps:std
94 fn f() {$0}
95 
96 //- /std/lib.rs crate:std
97 pub mod prelude {
98     pub mod rust_2018 {
99         pub use crate::concat;
100     }
101 }
102 
103 mod macros {
104     #[rustc_builtin_macro]
105     #[macro_export]
106     macro_rules! concat { }
107 }
108 "#,
109         expect![[r#"
110                 fn f()        fn()
111                 ma concat!(…) macro_rules! concat
112                 md std
113                 bt u32
114             "#]],
115     );
116 }
117 
118 #[test]
completes_std_prelude_if_core_is_defined()119 fn completes_std_prelude_if_core_is_defined() {
120     check_no_kw(
121         r#"
122 //- /main.rs crate:main deps:core,std
123 fn foo() { let x: $0 }
124 
125 //- /core/lib.rs crate:core
126 pub mod prelude {
127     pub mod rust_2021 {
128         pub struct Option;
129     }
130 }
131 
132 //- /std/lib.rs crate:std deps:core
133 pub mod prelude {
134     pub mod rust_2021 {
135         pub struct String;
136     }
137 }
138 "#,
139         expect![[r#"
140                 md core
141                 md std
142                 st String
143                 bt u32
144             "#]],
145     );
146 }
147 
148 #[test]
respects_doc_hidden()149 fn respects_doc_hidden() {
150     check_no_kw(
151         r#"
152 //- /lib.rs crate:lib deps:std
153 fn f() {
154     format_$0
155 }
156 
157 //- /std.rs crate:std
158 #[doc(hidden)]
159 #[macro_export]
160 macro_rules! format_args_nl {
161     () => {}
162 }
163 
164 pub mod prelude {
165     pub mod rust_2018 {}
166 }
167             "#,
168         expect![[r#"
169                 fn f() fn()
170                 md std
171                 bt u32
172             "#]],
173     );
174 }
175 
176 #[test]
respects_doc_hidden_in_assoc_item_list()177 fn respects_doc_hidden_in_assoc_item_list() {
178     check_no_kw(
179         r#"
180 //- /lib.rs crate:lib deps:std
181 struct S;
182 impl S {
183     format_$0
184 }
185 
186 //- /std.rs crate:std
187 #[doc(hidden)]
188 #[macro_export]
189 macro_rules! format_args_nl {
190     () => {}
191 }
192 
193 pub mod prelude {
194     pub mod rust_2018 {}
195 }
196             "#,
197         expect![[r#"
198                 md std
199             "#]],
200     );
201 }
202 
203 #[test]
associated_item_visibility()204 fn associated_item_visibility() {
205     check_no_kw(
206         r#"
207 //- /lib.rs crate:lib new_source_root:library
208 pub struct S;
209 
210 impl S {
211     pub fn public_method() { }
212     fn private_method() { }
213     pub type PublicType = u32;
214     type PrivateType = u32;
215     pub const PUBLIC_CONST: u32 = 1;
216     const PRIVATE_CONST: u32 = 1;
217 }
218 
219 //- /main.rs crate:main deps:lib new_source_root:local
220 fn foo() { let _ = lib::S::$0 }
221 "#,
222         expect![[r#"
223                 ct PUBLIC_CONST    pub const PUBLIC_CONST: u32
224                 fn public_method() fn()
225                 ta PublicType      pub type PublicType = u32
226             "#]],
227     );
228 }
229 
230 #[test]
completes_union_associated_method()231 fn completes_union_associated_method() {
232     check_no_kw(
233         r#"
234 union U {};
235 impl U { fn m() { } }
236 
237 fn foo() { let _ = U::$0 }
238 "#,
239         expect![[r#"
240                 fn m() fn()
241             "#]],
242     );
243 }
244 
245 #[test]
completes_trait_associated_method_1()246 fn completes_trait_associated_method_1() {
247     check_no_kw(
248         r#"
249 trait Trait { fn m(); }
250 
251 fn foo() { let _ = Trait::$0 }
252 "#,
253         expect![[r#"
254                 fn m() (as Trait) fn()
255             "#]],
256     );
257 }
258 
259 #[test]
completes_trait_associated_method_2()260 fn completes_trait_associated_method_2() {
261     check_no_kw(
262         r#"
263 trait Trait { fn m(); }
264 
265 struct S;
266 impl Trait for S {}
267 
268 fn foo() { let _ = S::$0 }
269 "#,
270         expect![[r#"
271                 fn m() (as Trait) fn()
272             "#]],
273     );
274 }
275 
276 #[test]
completes_trait_associated_method_3()277 fn completes_trait_associated_method_3() {
278     check_no_kw(
279         r#"
280 trait Trait { fn m(); }
281 
282 struct S;
283 impl Trait for S {}
284 
285 fn foo() { let _ = <S as Trait>::$0 }
286 "#,
287         expect![[r#"
288                 fn m() (as Trait) fn()
289             "#]],
290     );
291 }
292 
293 #[test]
completes_ty_param_assoc_ty()294 fn completes_ty_param_assoc_ty() {
295     check_no_kw(
296         r#"
297 trait Super {
298     type Ty;
299     const CONST: u8;
300     fn func() {}
301     fn method(&self) {}
302 }
303 
304 trait Sub: Super {
305     type SubTy;
306     const C2: ();
307     fn subfunc() {}
308     fn submethod(&self) {}
309 }
310 
311 fn foo<T: Sub>() { T::$0 }
312 "#,
313         expect![[r#"
314                 ct C2 (as Sub)           const C2: ()
315                 ct CONST (as Super)      const CONST: u8
316                 fn func() (as Super)     fn()
317                 fn subfunc() (as Sub)    fn()
318                 ta SubTy (as Sub)        type SubTy
319                 ta Ty (as Super)         type Ty
320                 me method(…) (as Super)  fn(&self)
321                 me submethod(…) (as Sub) fn(&self)
322             "#]],
323     );
324 }
325 
326 #[test]
completes_self_param_assoc_ty()327 fn completes_self_param_assoc_ty() {
328     check_no_kw(
329         r#"
330 trait Super {
331     type Ty;
332     const CONST: u8 = 0;
333     fn func() {}
334     fn method(&self) {}
335 }
336 
337 trait Sub: Super {
338     type SubTy;
339     const C2: () = ();
340     fn subfunc() {}
341     fn submethod(&self) {}
342 }
343 
344 struct Wrap<T>(T);
345 impl<T> Super for Wrap<T> {}
346 impl<T> Sub for Wrap<T> {
347     fn subfunc() {
348         // Should be able to assume `Self: Sub + Super`
349         Self::$0
350     }
351 }
352 "#,
353         expect![[r#"
354                 ct C2 (as Sub)           const C2: ()
355                 ct CONST (as Super)      const CONST: u8
356                 fn func() (as Super)     fn()
357                 fn subfunc() (as Sub)    fn()
358                 ta SubTy (as Sub)        type SubTy
359                 ta Ty (as Super)         type Ty
360                 me method(…) (as Super)  fn(&self)
361                 me submethod(…) (as Sub) fn(&self)
362             "#]],
363     );
364 }
365 
366 #[test]
completes_type_alias()367 fn completes_type_alias() {
368     check_no_kw(
369         r#"
370 struct S;
371 impl S { fn foo() {} }
372 type T = S;
373 impl T { fn bar() {} }
374 
375 fn main() { T::$0; }
376 "#,
377         expect![[r#"
378                 fn bar() fn()
379                 fn foo() fn()
380             "#]],
381     );
382 }
383 
384 #[test]
completes_qualified_macros()385 fn completes_qualified_macros() {
386     check_no_kw(
387         r#"
388 #[macro_export]
389 macro_rules! foo { () => {} }
390 
391 fn main() { let _ = crate::$0 }
392 "#,
393         expect![[r#"
394                 fn main()  fn()
395                 ma foo!(…) macro_rules! foo
396             "#]],
397     );
398 }
399 
400 #[test]
does_not_complete_non_fn_macros()401 fn does_not_complete_non_fn_macros() {
402     check_no_kw(
403         r#"
404 mod m {
405     #[rustc_builtin_macro]
406     pub macro Clone {}
407 }
408 
409 fn f() {m::$0}
410 "#,
411         expect![[r#""#]],
412     );
413     check_no_kw(
414         r#"
415 mod m {
416     #[rustc_builtin_macro]
417     pub macro bench {}
418 }
419 
420 fn f() {m::$0}
421 "#,
422         expect![[r#""#]],
423     );
424 }
425 
426 #[test]
completes_reexported_items_under_correct_name()427 fn completes_reexported_items_under_correct_name() {
428     check_no_kw(
429         r#"
430 fn foo() { self::m::$0 }
431 
432 mod m {
433     pub use super::p::wrong_fn as right_fn;
434     pub use super::p::WRONG_CONST as RIGHT_CONST;
435     pub use super::p::WrongType as RightType;
436 }
437 mod p {
438     pub fn wrong_fn() {}
439     pub const WRONG_CONST: u32 = 1;
440     pub struct WrongType {};
441 }
442 "#,
443         expect![[r#"
444                 ct RIGHT_CONST
445                 fn right_fn()  fn()
446                 st RightType
447             "#]],
448     );
449 
450     check_edit(
451         "RightType",
452         r#"
453 fn foo() { self::m::$0 }
454 
455 mod m {
456     pub use super::p::wrong_fn as right_fn;
457     pub use super::p::WRONG_CONST as RIGHT_CONST;
458     pub use super::p::WrongType as RightType;
459 }
460 mod p {
461     pub fn wrong_fn() {}
462     pub const WRONG_CONST: u32 = 1;
463     pub struct WrongType {};
464 }
465 "#,
466         r#"
467 fn foo() { self::m::RightType }
468 
469 mod m {
470     pub use super::p::wrong_fn as right_fn;
471     pub use super::p::WRONG_CONST as RIGHT_CONST;
472     pub use super::p::WrongType as RightType;
473 }
474 mod p {
475     pub fn wrong_fn() {}
476     pub const WRONG_CONST: u32 = 1;
477     pub struct WrongType {};
478 }
479 "#,
480     );
481 }
482 
483 #[test]
completes_in_simple_macro_call()484 fn completes_in_simple_macro_call() {
485     check_no_kw(
486         r#"
487 macro_rules! m { ($e:expr) => { $e } }
488 fn main() { m!(self::f$0); }
489 fn foo() {}
490 "#,
491         expect![[r#"
492                 fn foo()  fn()
493                 fn main() fn()
494             "#]],
495     );
496 }
497 
498 #[test]
function_mod_share_name()499 fn function_mod_share_name() {
500     check_no_kw(
501         r#"
502 fn foo() { self::m::$0 }
503 
504 mod m {
505     pub mod z {}
506     pub fn z() {}
507 }
508 "#,
509         expect![[r#"
510                 fn z() fn()
511                 md z
512             "#]],
513     );
514 }
515 
516 #[test]
completes_hashmap_new()517 fn completes_hashmap_new() {
518     check_no_kw(
519         r#"
520 struct RandomState;
521 struct HashMap<K, V, S = RandomState> {}
522 
523 impl<K, V> HashMap<K, V, RandomState> {
524     pub fn new() -> HashMap<K, V, RandomState> { }
525 }
526 fn foo() {
527     HashMap::$0
528 }
529 "#,
530         expect![[r#"
531                 fn new() fn() -> HashMap<K, V, RandomState>
532             "#]],
533     );
534 }
535 
536 #[test]
completes_variant_through_self()537 fn completes_variant_through_self() {
538     cov_mark::check!(completes_variant_through_self);
539     check_no_kw(
540         r#"
541 enum Foo {
542     Bar,
543     Baz,
544 }
545 
546 impl Foo {
547     fn foo(self) {
548         Self::$0
549     }
550 }
551 "#,
552         expect![[r#"
553                 ev Bar    Bar
554                 ev Baz    Baz
555                 me foo(…) fn(self)
556             "#]],
557     );
558 }
559 
560 #[test]
completes_non_exhaustive_variant_within_the_defining_crate()561 fn completes_non_exhaustive_variant_within_the_defining_crate() {
562     check_no_kw(
563         r#"
564 enum Foo {
565     #[non_exhaustive]
566     Bar,
567     Baz,
568 }
569 
570 fn foo(self) {
571     Foo::$0
572 }
573 "#,
574         expect![[r#"
575                 ev Bar Bar
576                 ev Baz Baz
577             "#]],
578     );
579 
580     check_no_kw(
581         r#"
582 //- /main.rs crate:main deps:e
583 fn foo(self) {
584     e::Foo::$0
585 }
586 
587 //- /e.rs crate:e
588 enum Foo {
589     #[non_exhaustive]
590     Bar,
591     Baz,
592 }
593 "#,
594         expect![[r#"
595                 ev Baz Baz
596             "#]],
597     );
598 }
599 
600 #[test]
completes_primitive_assoc_const()601 fn completes_primitive_assoc_const() {
602     cov_mark::check!(completes_primitive_assoc_const);
603     check_no_kw(
604         r#"
605 //- /lib.rs crate:lib deps:core
606 fn f() {
607     u8::$0
608 }
609 
610 //- /core.rs crate:core
611 #![rustc_coherence_is_core]
612 #[lang = "u8"]
613 impl u8 {
614     pub const MAX: Self = 255;
615 
616     pub fn func(self) {}
617 }
618 "#,
619         expect![[r#"
620                 ct MAX     pub const MAX: Self
621                 me func(…) fn(self)
622             "#]],
623     );
624 }
625 
626 #[test]
completes_variant_through_alias()627 fn completes_variant_through_alias() {
628     cov_mark::check!(completes_variant_through_alias);
629     check_no_kw(
630         r#"
631 enum Foo {
632     Bar
633 }
634 type Foo2 = Foo;
635 fn main() {
636     Foo2::$0
637 }
638 "#,
639         expect![[r#"
640                 ev Bar Bar
641             "#]],
642     );
643 }
644 
645 #[test]
respects_doc_hidden2()646 fn respects_doc_hidden2() {
647     check_no_kw(
648         r#"
649 //- /lib.rs crate:lib deps:dep
650 fn f() {
651     dep::$0
652 }
653 
654 //- /dep.rs crate:dep
655 #[doc(hidden)]
656 #[macro_export]
657 macro_rules! m {
658     () => {}
659 }
660 
661 #[doc(hidden)]
662 pub fn f() {}
663 
664 #[doc(hidden)]
665 pub struct S;
666 
667 #[doc(hidden)]
668 pub mod m {}
669             "#,
670         expect![[r#""#]],
671     )
672 }
673 
674 #[test]
type_anchor_empty()675 fn type_anchor_empty() {
676     check_no_kw(
677         r#"
678 trait Foo {
679     fn foo() -> Self;
680 }
681 struct Bar;
682 impl Foo for Bar {
683     fn foo() -> {
684         Bar
685     }
686 }
687 fn bar() -> Bar {
688     <_>::$0
689 }
690 "#,
691         expect![[r#"
692                 fn foo() (as Foo) fn() -> Self
693             "#]],
694     );
695 }
696 
697 #[test]
type_anchor_type()698 fn type_anchor_type() {
699     check_no_kw(
700         r#"
701 trait Foo {
702     fn foo() -> Self;
703 }
704 struct Bar;
705 impl Bar {
706     fn bar() {}
707 }
708 impl Foo for Bar {
709     fn foo() -> {
710         Bar
711     }
712 }
713 fn bar() -> Bar {
714     <Bar>::$0
715 }
716 "#,
717         expect![[r#"
718             fn bar()          fn()
719             fn foo() (as Foo) fn() -> Self
720         "#]],
721     );
722 }
723 
724 #[test]
type_anchor_type_trait()725 fn type_anchor_type_trait() {
726     check_no_kw(
727         r#"
728 trait Foo {
729     fn foo() -> Self;
730 }
731 struct Bar;
732 impl Bar {
733     fn bar() {}
734 }
735 impl Foo for Bar {
736     fn foo() -> {
737         Bar
738     }
739 }
740 fn bar() -> Bar {
741     <Bar as Foo>::$0
742 }
743 "#,
744         expect![[r#"
745             fn foo() (as Foo) fn() -> Self
746         "#]],
747     );
748 }
749 
750 #[test]
completes_fn_in_pub_trait_generated_by_macro()751 fn completes_fn_in_pub_trait_generated_by_macro() {
752     check_no_kw(
753         r#"
754 mod other_mod {
755     macro_rules! make_method {
756         ($name:ident) => {
757             fn $name(&self) {}
758         };
759     }
760 
761     pub trait MyTrait {
762         make_method! { by_macro }
763         fn not_by_macro(&self) {}
764     }
765 
766     pub struct Foo {}
767 
768     impl MyTrait for Foo {}
769 }
770 
771 fn main() {
772     use other_mod::{Foo, MyTrait};
773     let f = Foo {};
774     f.$0
775 }
776 "#,
777         expect![[r#"
778             me by_macro() (as MyTrait) fn(&self)
779             me not_by_macro() (as MyTrait) fn(&self)
780         "#]],
781     )
782 }
783 
784 #[test]
completes_fn_in_pub_trait_generated_by_recursive_macro()785 fn completes_fn_in_pub_trait_generated_by_recursive_macro() {
786     check_no_kw(
787         r#"
788 mod other_mod {
789     macro_rules! make_method {
790         ($name:ident) => {
791             fn $name(&self) {}
792         };
793     }
794 
795     macro_rules! make_trait {
796         () => {
797             pub trait MyTrait {
798                 make_method! { by_macro }
799                 fn not_by_macro(&self) {}
800             }
801         }
802     }
803 
804     make_trait!();
805 
806     pub struct Foo {}
807 
808     impl MyTrait for Foo {}
809 }
810 
811 fn main() {
812     use other_mod::{Foo, MyTrait};
813     let f = Foo {};
814     f.$0
815 }
816 "#,
817         expect![[r#"
818             me by_macro() (as MyTrait) fn(&self)
819             me not_by_macro() (as MyTrait) fn(&self)
820         "#]],
821     )
822 }
823 
824 #[test]
completes_const_in_pub_trait_generated_by_macro()825 fn completes_const_in_pub_trait_generated_by_macro() {
826     check_no_kw(
827         r#"
828 mod other_mod {
829     macro_rules! make_const {
830         ($name:ident) => {
831             const $name: u8 = 1;
832         };
833     }
834 
835     pub trait MyTrait {
836         make_const! { by_macro }
837     }
838 
839     pub struct Foo {}
840 
841     impl MyTrait for Foo {}
842 }
843 
844 fn main() {
845     use other_mod::{Foo, MyTrait};
846     let f = Foo {};
847     Foo::$0
848 }
849 "#,
850         expect![[r#"
851             ct by_macro (as MyTrait) pub const by_macro: u8
852         "#]],
853     )
854 }
855 
856 #[test]
completes_locals_from_macros()857 fn completes_locals_from_macros() {
858     check_no_kw(
859         r#"
860 
861 macro_rules! x {
862     ($x:ident, $expr:expr) => {
863         let $x = 0;
864         $expr
865     };
866 }
867 fn main() {
868     x! {
869         foobar, {
870             f$0
871         }
872     };
873 }
874 "#,
875         expect![[r#"
876             fn main() fn()
877             lc foobar i32
878             ma x!(…)  macro_rules! x
879             bt u32
880         "#]],
881     )
882 }
883 
884 #[test]
regression_12644()885 fn regression_12644() {
886     check_no_kw(
887         r#"
888 macro_rules! __rust_force_expr {
889     ($e:expr) => {
890         $e
891     };
892 }
893 macro_rules! vec {
894     ($elem:expr) => {
895         __rust_force_expr!($elem)
896     };
897 }
898 
899 struct Struct;
900 impl Struct {
901     fn foo(self) {}
902 }
903 
904 fn f() {
905     vec![Struct].$0;
906 }
907 "#,
908         expect![[r#"
909             me foo() fn(self)
910         "#]],
911     );
912 }
913 
914 #[test]
completes_after_colon_with_trigger()915 fn completes_after_colon_with_trigger() {
916     check_with_trigger_character(
917         r#"
918 //- minicore: option
919 fn foo { ::$0 }
920 "#,
921         Some(':'),
922         expect![[r#"
923             md core
924         "#]],
925     );
926     check_with_trigger_character(
927         r#"
928 //- minicore: option
929 fn foo { /* test */::$0 }
930 "#,
931         Some(':'),
932         expect![[r#"
933             md core
934         "#]],
935     );
936 
937     check_with_trigger_character(
938         r#"
939 fn foo { crate::$0 }
940 "#,
941         Some(':'),
942         expect![[r#"
943             fn foo() fn()
944         "#]],
945     );
946 
947     check_with_trigger_character(
948         r#"
949 fn foo { crate:$0 }
950 "#,
951         Some(':'),
952         expect![""],
953     );
954 }
955 
956 #[test]
completes_after_colon_without_trigger()957 fn completes_after_colon_without_trigger() {
958     check_with_trigger_character(
959         r#"
960 fn foo { crate::$0 }
961 "#,
962         None,
963         expect![[r#"
964             fn foo() fn()
965         "#]],
966     );
967 
968     check_with_trigger_character(
969         r#"
970 fn foo { crate:$0 }
971 "#,
972         None,
973         expect![""],
974     );
975 }
976 
977 #[test]
no_completions_in_invalid_path()978 fn no_completions_in_invalid_path() {
979     check(
980         r#"
981 fn foo { crate:::$0 }
982 "#,
983         expect![""],
984     );
985     check_no_kw(
986         r#"
987 fn foo { crate::::$0 }
988 "#,
989         expect![""],
990     )
991 }
992 
993 #[test]
completes_struct_via_doc_alias_in_fn_body()994 fn completes_struct_via_doc_alias_in_fn_body() {
995     check(
996         r#"
997 #[doc(alias = "Bar")]
998 struct Foo;
999 
1000 fn here_we_go() {
1001     $0
1002 }
1003 "#,
1004         expect![[r#"
1005             fn here_we_go()    fn()
1006             st Foo (alias Bar)
1007             bt u32
1008             kw const
1009             kw crate::
1010             kw enum
1011             kw extern
1012             kw false
1013             kw fn
1014             kw for
1015             kw if
1016             kw if let
1017             kw impl
1018             kw let
1019             kw loop
1020             kw match
1021             kw mod
1022             kw return
1023             kw self::
1024             kw static
1025             kw struct
1026             kw trait
1027             kw true
1028             kw type
1029             kw union
1030             kw unsafe
1031             kw use
1032             kw while
1033             kw while let
1034             sn macro_rules
1035             sn pd
1036             sn ppd
1037         "#]],
1038     );
1039 }
1040 
1041 #[test]
completes_struct_via_multiple_doc_aliases_in_fn_body()1042 fn completes_struct_via_multiple_doc_aliases_in_fn_body() {
1043     check(
1044         r#"
1045 #[doc(alias("Bar", "Qux"))]
1046 #[doc(alias = "Baz")]
1047 struct Foo;
1048 
1049 fn here_we_go() {
1050     B$0
1051 }
1052 "#,
1053         expect![[r#"
1054             fn here_we_go()           fn()
1055             st Foo (alias Bar, Qux, Baz)
1056             bt u32
1057             kw const
1058             kw crate::
1059             kw enum
1060             kw extern
1061             kw false
1062             kw fn
1063             kw for
1064             kw if
1065             kw if let
1066             kw impl
1067             kw let
1068             kw loop
1069             kw match
1070             kw mod
1071             kw return
1072             kw self::
1073             kw static
1074             kw struct
1075             kw trait
1076             kw true
1077             kw type
1078             kw union
1079             kw unsafe
1080             kw use
1081             kw while
1082             kw while let
1083             sn macro_rules
1084             sn pd
1085             sn ppd
1086         "#]],
1087     );
1088 }
1089 
1090 #[test]
completes_field_name_via_doc_alias_in_fn_body()1091 fn completes_field_name_via_doc_alias_in_fn_body() {
1092     check(
1093         r#"
1094 struct Foo {
1095     #[doc(alias = "qux")]
1096     bar: u8
1097 };
1098 
1099 fn here_we_go() {
1100     let foo = Foo { q$0 }
1101 }
1102 "#,
1103         expect![[r#"
1104             fd bar (alias qux) u8
1105         "#]],
1106     );
1107 }
1108 
1109 #[test]
completes_struct_fn_name_via_doc_alias_in_fn_body()1110 fn completes_struct_fn_name_via_doc_alias_in_fn_body() {
1111     check(
1112         r#"
1113 struct Foo;
1114 impl Foo {
1115     #[doc(alias = "qux")]
1116     fn bar() -> u8 { 1 }
1117 }
1118 
1119 fn here_we_go() {
1120     Foo::q$0
1121 }
1122 "#,
1123         expect![[r#"
1124             fn bar() (alias qux) fn() -> u8
1125         "#]],
1126     );
1127 }
1128 
1129 #[test]
completes_method_name_via_doc_alias_in_fn_body()1130 fn completes_method_name_via_doc_alias_in_fn_body() {
1131     check(
1132         r#"
1133 struct Foo {
1134     bar: u8
1135 }
1136 impl Foo {
1137     #[doc(alias = "qux")]
1138     fn baz(&self) -> u8 {
1139         self.bar
1140     }
1141 }
1142 
1143 fn here_we_go() {
1144     let foo = Foo { field: 42 };
1145     foo.q$0
1146 }
1147 "#,
1148         expect![[r#"
1149             fd bar               u8
1150             me baz() (alias qux) fn(&self) -> u8
1151             sn box               Box::new(expr)
1152             sn call              function(expr)
1153             sn dbg               dbg!(expr)
1154             sn dbgr              dbg!(&expr)
1155             sn let               let
1156             sn letm              let mut
1157             sn match             match expr {}
1158             sn ref               &expr
1159             sn refm              &mut expr
1160             sn unsafe            unsafe {}
1161         "#]],
1162     );
1163 }
1164 
1165 #[test]
completes_fn_name_via_doc_alias_in_fn_body()1166 fn completes_fn_name_via_doc_alias_in_fn_body() {
1167     check(
1168         r#"
1169 #[doc(alias = "qux")]
1170 fn foo() {}
1171 fn bar() { qu$0 }
1172 "#,
1173         expect![[r#"
1174             fn bar()             fn()
1175             fn foo() (alias qux) fn()
1176             bt u32
1177             kw const
1178             kw crate::
1179             kw enum
1180             kw extern
1181             kw false
1182             kw fn
1183             kw for
1184             kw if
1185             kw if let
1186             kw impl
1187             kw let
1188             kw loop
1189             kw match
1190             kw mod
1191             kw return
1192             kw self::
1193             kw static
1194             kw struct
1195             kw trait
1196             kw true
1197             kw type
1198             kw union
1199             kw unsafe
1200             kw use
1201             kw while
1202             kw while let
1203             sn macro_rules
1204             sn pd
1205             sn ppd
1206         "#]],
1207     );
1208 }
1209 
1210 #[test]
completes_struct_name_via_doc_alias_in_another_mod()1211 fn completes_struct_name_via_doc_alias_in_another_mod() {
1212     check(
1213         r#"
1214 mod foo {
1215     #[doc(alias = "Qux")]
1216     pub struct Bar(u8);
1217 }
1218 
1219 fn here_we_go() {
1220     use foo;
1221     let foo = foo::Q$0
1222 }
1223 "#,
1224         expect![[r#"
1225             st Bar (alias Qux)
1226         "#]],
1227     );
1228 }
1229 
1230 #[test]
completes_use_via_doc_alias_in_another_mod()1231 fn completes_use_via_doc_alias_in_another_mod() {
1232     check(
1233         r#"
1234 mod foo {
1235     #[doc(alias = "Qux")]
1236     pub struct Bar(u8);
1237 }
1238 
1239 fn here_we_go() {
1240     use foo::Q$0;
1241 }
1242 "#,
1243         expect![[r#"
1244             st Bar (alias Qux)
1245         "#]],
1246     );
1247 }
1248 
1249 #[test]
completes_flyimport_with_doc_alias_in_another_mod()1250 fn completes_flyimport_with_doc_alias_in_another_mod() {
1251     check(
1252         r#"
1253 mod foo {
1254     #[doc(alias = "Qux")]
1255     pub struct Bar();
1256 }
1257 
1258 fn here_we_go() {
1259     let foo = Bar$0
1260 }
1261 "#,
1262         expect![[r#"
1263             fn here_we_go()           fn()
1264             md foo
1265             st Bar (alias Qux) (use foo::Bar)
1266             bt u32
1267             kw crate::
1268             kw false
1269             kw for
1270             kw if
1271             kw if let
1272             kw loop
1273             kw match
1274             kw return
1275             kw self::
1276             kw true
1277             kw unsafe
1278             kw while
1279             kw while let
1280         "#]],
1281     );
1282 }
1283