1 //! Completion tests for attributes.
2 use expect_test::{expect, Expect};
4 use crate::tests::{check_edit, completion_list};
6 fn check(ra_fixture: &str, expect: Expect) {
7 let actual = completion_list(ra_fixture);
8 expect.assert_eq(&actual);
15 //- proc_macros: identity
44 fn proc_macros_on_comment() {
47 //- proc_macros: identity
49 #[proc_macros::identity]
57 fn proc_macros_qualified() {
60 //- proc_macros: identity
65 at identity pub macro identity
71 fn inside_nested_attr() {
72 check(r#"#[cfg($0)]"#, expect![[]])
76 fn with_existing_attr() {
78 r#"#[no_mangle] #[$0] mcall!();"#,
94 fn attr_on_source_file() {
115 at no_implicit_prelude
118 at recursion_limit = "…"
119 at type_length_limit = …
120 at windows_subsystem = "…"
126 fn attr_on_module() {
150 r#"mod foo {#![$0]}"#,
167 at no_implicit_prelude
173 fn attr_on_macro_rules() {
175 r#"#[$0] macro_rules! foo {}"#,
199 fn attr_on_macro_def() {
201 r#"#[$0] macro foo {}"#,
223 fn attr_on_extern_crate() {
225 r#"#[$0] extern crate foo;"#,
272 fn attr_on_type_alias() {
274 r#"#[$0] type foo = ();"#,
296 fn attr_on_struct() {
305 at derive pub macro derive
331 r#"#[$0] enum Foo {}"#,
358 r#"#[$0] const FOO: () = ();"#,
380 fn attr_on_static() {
382 r#"#[$0] static FOO: () = ()"#,
401 at link_section = "…"
411 r#"#[$0] trait Foo {}"#,
436 r#"#[$0] impl () {}"#,
453 at automatically_derived
457 r#"impl () {#![$0]}"#,
479 fn attr_on_extern_block() {
481 r#"#[$0] extern {}"#,
502 r#"extern {#![$0]}"#,
525 fn attr_on_variant() {
527 r#"enum Foo { #[$0] Bar }"#,
546 r#"#[$0] fn main() {}"#,
565 at link_section = "…"
572 at proc_macro_derive(…)
573 at proc_macro_attribute
575 at target_feature = "…"
584 cov_mark::check!(no_keyword_completion_in_attr_of_expr);
586 r#"fn main() { #[$0] foo() }"#,
602 fn attr_in_source_file_end() {
610 at automatically_derived
627 at link_section = "…"
636 at proc_macro_attribute
637 at proc_macro_derive(…)
640 at target_feature = "…"
653 fn cfg_target_endian() {
655 r#"#[cfg(target_endian = $0"#,
667 fn check_derive(ra_fixture: &str, expect: Expect) {
668 let actual = completion_list(ra_fixture);
669 expect.assert_eq(&actual);
673 fn no_completion_for_incorrect_derive() {
676 //- minicore: derive, copy, clone, ord, eq, default, fmt
677 #[derive{$0)] struct Test;
687 //- minicore: derive, copy, clone, ord, eq, default, fmt
688 #[derive($0)] struct Test;
692 de Default pub macro Default
694 de PartialEq pub macro PartialEq
696 de PartialEq, Eq, PartialOrd, Ord
697 de Clone pub macro Clone
698 de PartialEq, PartialOrd
707 fn derive_with_input_before() {
710 //- minicore: derive, copy, clone, ord, eq, default, fmt
711 #[derive(serde::Serialize, PartialEq, $0)] struct Test;
715 de Default pub macro Default
718 de Eq, PartialOrd, Ord
719 de Clone pub macro Clone
729 fn derive_with_input_after() {
732 //- minicore: derive, copy, clone, ord, eq, default, fmt
733 #[derive($0 serde::Serialize, PartialEq)] struct Test;
737 de Default pub macro Default
740 de Eq, PartialOrd, Ord
741 de Clone pub macro Clone
751 fn derive_flyimport() {
754 //- proc_macros: derive_identity
756 #[derive(der$0)] struct Test;
764 de DeriveIdentity (use proc_macros::DeriveIdentity) pub macro derive_identity
769 //- proc_macros: derive_identity
771 use proc_macros::DeriveIdentity;
772 #[derive(der$0)] struct Test;
775 de DeriveIdentity pub macro derive_identity
786 fn derive_flyimport_edit() {
790 //- proc_macros: derive_identity
792 #[derive(der$0)] struct Test;
795 use proc_macros::DeriveIdentity;
797 #[derive(DeriveIdentity)] struct Test;
806 //- proc_macros: derive_identity
807 //- minicore: derive, copy, clone
808 #[derive(proc_macros::$0)] struct Test;
811 de DeriveIdentity pub macro derive_identity
816 //- proc_macros: derive_identity
817 //- minicore: derive, copy, clone
818 #[derive(proc_macros::C$0)] struct Test;
821 de DeriveIdentity pub macro derive_identity
834 r#"#[allow($0)] struct Test;"#,
835 r#"#[allow(deprecated)] struct Test;"#,
840 fn lint_with_existing() {
843 r#"#[allow(keyword_idents, $0)] struct Test;"#,
844 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
849 fn lint_qualified() {
852 r#"#[allow(keyword_idents, $0)] struct Test;"#,
853 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
861 r#"#[feature(box_$0)] struct Test;"#,
862 r#"#[feature(box_syntax)] struct Test;"#,
867 fn lint_clippy_unqualified() {
869 "clippy::as_conversions",
870 r#"#[allow($0)] struct Test;"#,
871 r#"#[allow(clippy::as_conversions)] struct Test;"#,
876 fn lint_clippy_qualified() {
879 r#"#[allow(clippy::$0)] struct Test;"#,
880 r#"#[allow(clippy::as_conversions)] struct Test;"#,
885 fn lint_rustdoc_unqualified() {
887 "rustdoc::bare_urls",
888 r#"#[allow($0)] struct Test;"#,
889 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
894 fn lint_rustdoc_qualified() {
897 r#"#[allow(rustdoc::$0)] struct Test;"#,
898 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
906 r#"#[allow(dep$0 struct Test;"#,
907 r#"#[allow(deprecated struct Test;"#,
911 r#"#[allow(rustdoc::$0 struct Test;"#,
912 r#"#[allow(rustdoc::bare_urls struct Test;"#,
920 fn check_repr(ra_fixture: &str, expect: Expect) {
921 let actual = completion_list(ra_fixture);
922 expect.assert_eq(&actual);
926 fn no_completion_for_incorrect_repr() {
927 check_repr(r#"#[repr{$0)] struct Test;"#, expect![[]])
933 r#"#[repr($0)] struct Test;"#,
957 check_repr(r#"#[repr(transparent, $0)] struct Test;"#, expect![[r#""#]]);
963 r#"#[repr(align(1), $0)] struct Test;"#,
986 r#"#[repr(packed, $0)] struct Test;"#,
1009 r#"#[repr(C, $0)] struct Test;"#,
1032 r#"#[repr(usize, $0)] struct Test;"#,