1 //! Tests that don't fit into a specific category.
3 use expect_test
::{expect, Expect}
;
6 check_edit
, completion_list
, completion_list_no_kw
, completion_list_with_trigger_character
,
9 fn check_no_kw(ra_fixture
: &str, expect
: Expect
) {
10 let actual
= completion_list_no_kw(ra_fixture
);
11 expect
.assert_eq(&actual
)
14 fn check(ra_fixture
: &str, expect
: Expect
) {
15 let actual
= completion_list(ra_fixture
);
16 expect
.assert_eq(&actual
)
19 pub(crate) fn check_with_trigger_character(
21 trigger_character
: Option
<char>,
24 let actual
= completion_list_with_trigger_character(ra_fixture
, trigger_character
);
25 expect
.assert_eq(&actual
)
29 fn completes_if_prefix_is_keyword() {
47 /// Regression test for issue #6091.
49 fn correctly_completes_module_items_prefixed_with_underscore() {
68 fn completes_prelude() {
71 //- /main.rs edition:2018 crate:main deps:std
72 fn foo() { let x: $0 }
74 //- /std/lib.rs crate:std
90 fn completes_prelude_macros() {
93 //- /main.rs edition:2018 crate:main deps:std
96 //- /std/lib.rs crate:std
99 pub use crate::concat;
104 #[rustc_builtin_macro]
106 macro_rules! concat { }
111 ma concat!(…) macro_rules! concat
119 fn completes_std_prelude_if_core_is_defined() {
122 //- /main.rs crate:main deps:core,std
123 fn foo() { let x: $0 }
125 //- /core/lib.rs crate:core
132 //- /std/lib.rs crate:std deps:core
149 fn respects_doc_hidden() {
152 //- /lib.rs crate:lib deps:std
157 //- /std.rs crate:std
160 macro_rules! format_args_nl {
177 fn respects_doc_hidden_in_assoc_item_list() {
180 //- /lib.rs crate:lib deps:std
186 //- /std.rs crate:std
189 macro_rules! format_args_nl {
204 fn associated_item_visibility() {
207 //- /lib.rs crate:lib new_source_root:library
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;
219 //- /main.rs crate:main deps:lib new_source_root:local
220 fn foo() { let _ = lib::S::$0 }
223 ct PUBLIC_CONST pub const PUBLIC_CONST: u32
224 fn public_method() fn()
225 ta PublicType pub type PublicType = u32
231 fn completes_union_associated_method() {
235 impl U { fn m() { } }
237 fn foo() { let _ = U::$0 }
246 fn completes_trait_associated_method_1() {
249 trait Trait { fn m(); }
251 fn foo() { let _ = Trait::$0 }
254 fn m() (as Trait) fn()
260 fn completes_trait_associated_method_2() {
263 trait Trait { fn m(); }
268 fn foo() { let _ = S::$0 }
271 fn m() (as Trait) fn()
277 fn completes_trait_associated_method_3() {
280 trait Trait { fn m(); }
285 fn foo() { let _ = <S as Trait>::$0 }
288 fn m() (as Trait) fn()
294 fn completes_ty_param_assoc_ty() {
308 fn submethod(&self) {}
311 fn foo<T: Sub>() { T::$0 }
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)
327 fn completes_self_param_assoc_ty() {
341 fn submethod(&self) {}
345 impl<T> Super for Wrap<T> {}
346 impl<T> Sub for Wrap<T> {
348 // Should be able to assume `Self: Sub + Super`
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)
367 fn completes_type_alias() {
371 impl S { fn foo() {} }
373 impl T { fn bar() {} }
385 fn completes_qualified_macros() {
389 macro_rules! foo { () => {} }
391 fn main() { let _ = crate::$0 }
395 ma foo!(…) macro_rules! foo
401 fn does_not_complete_non_fn_macros() {
405 #[rustc_builtin_macro]
416 #[rustc_builtin_macro]
427 fn completes_reexported_items_under_correct_name() {
430 fn foo() { self::m::$0 }
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;
439 pub const WRONG_CONST: u32 = 1;
440 pub struct WrongType {};
453 fn foo() { self::m::$0 }
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;
462 pub const WRONG_CONST: u32 = 1;
463 pub struct WrongType {};
467 fn foo() { self::m::RightType }
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;
476 pub const WRONG_CONST: u32 = 1;
477 pub struct WrongType {};
484 fn completes_in_simple_macro_call() {
487 macro_rules! m { ($e:expr) => { $e } }
488 fn main() { m!(self::f$0); }
499 fn function_mod_share_name() {
502 fn foo() { self::m::$0 }
517 fn completes_hashmap_new() {
521 struct HashMap<K, V, S = RandomState> {}
523 impl<K, V> HashMap<K, V, RandomState> {
524 pub fn new() -> HashMap<K, V, RandomState> { }
531 fn new() fn() -> HashMap<K, V, RandomState>
537 fn completes_variant_through_self() {
538 cov_mark
::check
!(completes_variant_through_self
);
561 fn completes_non_exhaustive_variant_within_the_defining_crate() {
582 //- /main.rs crate:main deps:e
601 fn completes_primitive_assoc_const() {
602 cov_mark
::check
!(completes_primitive_assoc_const
);
605 //- /lib.rs crate:lib deps:core
610 //- /core.rs crate:core
613 pub const MAX: Self = 255;
619 ct MAX pub const MAX: Self
626 fn completes_variant_through_alias() {
627 cov_mark
::check
!(completes_variant_through_alias
);
645 fn respects_doc_hidden2() {
648 //- /lib.rs crate:lib deps:dep
653 //- /dep.rs crate:dep
674 fn type_anchor_empty() {
691 fn foo() (as Foo) fn() -> Self
697 fn type_anchor_type() {
718 fn foo() (as Foo) fn() -> Self
724 fn type_anchor_type_trait() {
744 fn foo() (as Foo) fn() -> Self
750 fn completes_fn_in_pub_trait_generated_by_macro() {
754 macro_rules! make_method {
761 make_method! { by_macro }
762 fn not_by_macro(&self) {}
767 impl MyTrait for Foo {}
771 use other_mod::{Foo, MyTrait};
777 me by_macro() (as MyTrait) fn(&self)
778 me not_by_macro() (as MyTrait) fn(&self)
784 fn completes_fn_in_pub_trait_generated_by_recursive_macro() {
788 macro_rules! make_method {
794 macro_rules! make_trait {
797 make_method! { by_macro }
798 fn not_by_macro(&self) {}
807 impl MyTrait for Foo {}
811 use other_mod::{Foo, MyTrait};
817 me by_macro() (as MyTrait) fn(&self)
818 me not_by_macro() (as MyTrait) fn(&self)
824 fn completes_const_in_pub_trait_generated_by_macro() {
828 macro_rules! make_const {
835 make_const! { by_macro }
840 impl MyTrait for Foo {}
844 use other_mod::{Foo, MyTrait};
850 ct by_macro (as MyTrait) pub const by_macro: u8
856 fn completes_locals_from_macros() {
861 ($x:ident, $expr:expr) => {
877 ma x!(…) macro_rules! x
884 fn regression_12644() {
887 macro_rules! __rust_force_expr {
894 __rust_force_expr!($elem)
914 fn completes_after_colon_with_trigger() {
915 check_with_trigger_character(
925 check_with_trigger_character(
928 fn foo { /* test */::$0 }
936 check_with_trigger_character(
946 check_with_trigger_character(
956 fn completes_after_colon_without_trigger() {
957 check_with_trigger_character(
967 check_with_trigger_character(
977 fn no_completions_in_invalid_path() {
980 fn foo { crate:::$0 }
986 fn foo { crate::::$0 }