1 //! Tests that don't fit into a specific category.
3 use expect_test::{expect, Expect};
5 use crate::tests::{check_edit, completion_list_no_kw, completion_list_with_trigger_character};
7 fn check(ra_fixture: &str, expect: Expect) {
8 let actual = completion_list_no_kw(ra_fixture);
9 expect.assert_eq(&actual)
12 pub(crate) fn check_with_trigger_character(
14 trigger_character: Option<char>,
17 let actual = completion_list_with_trigger_character(ra_fixture, trigger_character);
18 expect.assert_eq(&actual)
22 fn completes_if_prefix_is_keyword() {
40 /// Regression test for issue #6091.
42 fn correctly_completes_module_items_prefixed_with_underscore() {
61 fn completes_prelude() {
64 //- /main.rs crate:main deps:std
65 fn foo() { let x: $0 }
67 //- /std/lib.rs crate:std
83 fn completes_prelude_macros() {
86 //- /main.rs crate:main deps:std
89 //- /std/lib.rs crate:std
92 pub use crate::concat;
97 #[rustc_builtin_macro]
99 macro_rules! concat { }
104 ma concat!(…) macro_rules! concat
112 fn completes_std_prelude_if_core_is_defined() {
115 //- /main.rs crate:main deps:core,std
116 fn foo() { let x: $0 }
118 //- /core/lib.rs crate:core
125 //- /std/lib.rs crate:std deps:core
142 fn respects_doc_hidden() {
145 //- /lib.rs crate:lib deps:std
150 //- /std.rs crate:std
153 macro_rules! format_args_nl {
170 fn respects_doc_hidden_in_assoc_item_list() {
173 //- /lib.rs crate:lib deps:std
179 //- /std.rs crate:std
182 macro_rules! format_args_nl {
197 fn associated_item_visibility() {
200 //- /lib.rs crate:lib new_source_root:library
204 pub fn public_method() { }
205 fn private_method() { }
206 pub type PublicType = u32;
207 type PrivateType = u32;
208 pub const PUBLIC_CONST: u32 = 1;
209 const PRIVATE_CONST: u32 = 1;
212 //- /main.rs crate:main deps:lib new_source_root:local
213 fn foo() { let _ = lib::S::$0 }
216 ct PUBLIC_CONST pub const PUBLIC_CONST: u32
217 fn public_method() fn()
218 ta PublicType pub type PublicType = u32
224 fn completes_union_associated_method() {
228 impl U { fn m() { } }
230 fn foo() { let _ = U::$0 }
239 fn completes_trait_associated_method_1() {
242 trait Trait { fn m(); }
244 fn foo() { let _ = Trait::$0 }
247 fn m() (as Trait) fn()
253 fn completes_trait_associated_method_2() {
256 trait Trait { fn m(); }
261 fn foo() { let _ = S::$0 }
264 fn m() (as Trait) fn()
270 fn completes_trait_associated_method_3() {
273 trait Trait { fn m(); }
278 fn foo() { let _ = <S as Trait>::$0 }
281 fn m() (as Trait) fn()
287 fn completes_ty_param_assoc_ty() {
301 fn submethod(&self) {}
304 fn foo<T: Sub>() { T::$0 }
307 ct C2 (as Sub) const C2: ()
308 ct CONST (as Super) const CONST: u8
309 fn func() (as Super) fn()
310 fn subfunc() (as Sub) fn()
311 ta SubTy (as Sub) type SubTy
312 ta Ty (as Super) type Ty
313 me method(…) (as Super) fn(&self)
314 me submethod(…) (as Sub) fn(&self)
320 fn completes_self_param_assoc_ty() {
334 fn submethod(&self) {}
338 impl<T> Super for Wrap<T> {}
339 impl<T> Sub for Wrap<T> {
341 // Should be able to assume `Self: Sub + Super`
347 ct C2 (as Sub) const C2: ()
348 ct CONST (as Super) const CONST: u8
349 fn func() (as Super) fn()
350 fn subfunc() (as Sub) fn()
351 ta SubTy (as Sub) type SubTy
352 ta Ty (as Super) type Ty
353 me method(…) (as Super) fn(&self)
354 me submethod(…) (as Sub) fn(&self)
360 fn completes_type_alias() {
364 impl S { fn foo() {} }
366 impl T { fn bar() {} }
378 fn completes_qualified_macros() {
382 macro_rules! foo { () => {} }
384 fn main() { let _ = crate::$0 }
388 ma foo!(…) macro_rules! foo
394 fn does_not_complete_non_fn_macros() {
398 #[rustc_builtin_macro]
409 #[rustc_builtin_macro]
420 fn completes_reexported_items_under_correct_name() {
423 fn foo() { self::m::$0 }
426 pub use super::p::wrong_fn as right_fn;
427 pub use super::p::WRONG_CONST as RIGHT_CONST;
428 pub use super::p::WrongType as RightType;
432 pub const WRONG_CONST: u32 = 1;
433 pub struct WrongType {};
446 fn foo() { self::m::$0 }
449 pub use super::p::wrong_fn as right_fn;
450 pub use super::p::WRONG_CONST as RIGHT_CONST;
451 pub use super::p::WrongType as RightType;
455 pub const WRONG_CONST: u32 = 1;
456 pub struct WrongType {};
460 fn foo() { self::m::RightType }
463 pub use super::p::wrong_fn as right_fn;
464 pub use super::p::WRONG_CONST as RIGHT_CONST;
465 pub use super::p::WrongType as RightType;
469 pub const WRONG_CONST: u32 = 1;
470 pub struct WrongType {};
477 fn completes_in_simple_macro_call() {
480 macro_rules! m { ($e:expr) => { $e } }
481 fn main() { m!(self::f$0); }
492 fn function_mod_share_name() {
495 fn foo() { self::m::$0 }
510 fn completes_hashmap_new() {
514 struct HashMap<K, V, S = RandomState> {}
516 impl<K, V> HashMap<K, V, RandomState> {
517 pub fn new() -> HashMap<K, V, RandomState> { }
524 fn new() fn() -> HashMap<K, V, RandomState>
530 fn completes_variant_through_self() {
531 cov_mark::check!(completes_variant_through_self);
554 fn completes_non_exhaustive_variant_within_the_defining_crate() {
575 //- /main.rs crate:main deps:e
594 fn completes_primitive_assoc_const() {
595 cov_mark::check!(completes_primitive_assoc_const);
598 //- /lib.rs crate:lib deps:core
603 //- /core.rs crate:core
606 pub const MAX: Self = 255;
612 ct MAX pub const MAX: Self
619 fn completes_variant_through_alias() {
620 cov_mark::check!(completes_variant_through_alias);
638 fn respects_doc_hidden2() {
641 //- /lib.rs crate:lib deps:dep
646 //- /dep.rs crate:dep
667 fn type_anchor_empty() {
684 fn foo() (as Foo) fn() -> Self
690 fn type_anchor_type() {
711 fn foo() (as Foo) fn() -> Self
717 fn type_anchor_type_trait() {
737 fn foo() (as Foo) fn() -> Self
743 fn completes_fn_in_pub_trait_generated_by_macro() {
747 macro_rules! make_method {
754 make_method! { by_macro }
755 fn not_by_macro(&self) {}
760 impl MyTrait for Foo {}
764 use other_mod::{Foo, MyTrait};
770 me by_macro() (as MyTrait) fn(&self)
771 me not_by_macro() (as MyTrait) fn(&self)
777 fn completes_fn_in_pub_trait_generated_by_recursive_macro() {
781 macro_rules! make_method {
787 macro_rules! make_trait {
790 make_method! { by_macro }
791 fn not_by_macro(&self) {}
800 impl MyTrait for Foo {}
804 use other_mod::{Foo, MyTrait};
810 me by_macro() (as MyTrait) fn(&self)
811 me not_by_macro() (as MyTrait) fn(&self)
817 fn completes_const_in_pub_trait_generated_by_macro() {
821 macro_rules! make_const {
828 make_const! { by_macro }
833 impl MyTrait for Foo {}
837 use other_mod::{Foo, MyTrait};
843 ct by_macro (as MyTrait) pub const by_macro: u8
849 fn completes_locals_from_macros() {
854 ($x:ident, $expr:expr) => {
870 ma x!(…) macro_rules! x
877 fn regression_12644() {
880 macro_rules! __rust_force_expr {
887 __rust_force_expr!($elem)
907 fn completes_after_colon_with_trigger() {
908 check_with_trigger_character(
918 check_with_trigger_character(
921 fn foo { /* test */::$0 }
929 check_with_trigger_character(
939 check_with_trigger_character(
949 fn completes_after_colon_without_trigger() {
950 check_with_trigger_character(
960 check_with_trigger_character(
970 fn no_completions_in_invalid_path() {
973 fn foo { crate:::$0 }
979 fn foo { crate::::$0 }
986 fn foo { crate:::::$0 }