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;
695 de PartialEq, Eq, PartialOrd, Ord
697 de PartialEq, PartialOrd
703 fn derive_with_input_before() {
706 //- minicore: derive, copy, clone, ord, eq, default, fmt
707 #[derive(serde::Serialize, PartialEq, $0)] struct Test;
713 de Eq, PartialOrd, Ord
721 fn derive_with_input_after() {
724 //- minicore: derive, copy, clone, ord, eq, default, fmt
725 #[derive($0 serde::Serialize, PartialEq)] struct Test;
731 de Eq, PartialOrd, Ord
739 fn derive_no_attrs() {
742 //- proc_macros: identity
744 #[derive($0)] struct Test;
750 //- proc_macros: identity
752 #[derive(i$0)] struct Test;
759 fn derive_flyimport() {
762 //- proc_macros: derive_identity
764 #[derive(der$0)] struct Test;
767 de DeriveIdentity (use proc_macros::DeriveIdentity) pub macro derive_identity
772 //- proc_macros: derive_identity
774 use proc_macros::DeriveIdentity;
775 #[derive(der$0)] struct Test;
784 fn derive_flyimport_edit() {
788 //- proc_macros: derive_identity
790 #[derive(der$0)] struct Test;
793 use proc_macros::DeriveIdentity;
795 #[derive(DeriveIdentity)] struct Test;
804 //- proc_macros: derive_identity
805 //- minicore: derive, copy, clone
806 #[derive(proc_macros::$0)] struct Test;
812 //- proc_macros: derive_identity
813 //- minicore: derive, copy, clone
814 #[derive(proc_macros::C$0)] struct Test;
828 r#"#[allow($0)] struct Test;"#,
829 r#"#[allow(deprecated)] struct Test;"#,
834 fn lint_with_existing() {
837 r#"#[allow(keyword_idents, $0)] struct Test;"#,
838 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
843 fn lint_qualified() {
846 r#"#[allow(keyword_idents, $0)] struct Test;"#,
847 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
855 r#"#[feature(box_$0)] struct Test;"#,
856 r#"#[feature(box_syntax)] struct Test;"#,
861 fn lint_clippy_unqualified() {
863 "clippy::as_conversions",
864 r#"#[allow($0)] struct Test;"#,
865 r#"#[allow(clippy::as_conversions)] struct Test;"#,
870 fn lint_clippy_qualified() {
873 r#"#[allow(clippy::$0)] struct Test;"#,
874 r#"#[allow(clippy::as_conversions)] struct Test;"#,
879 fn lint_rustdoc_unqualified() {
881 "rustdoc::bare_urls",
882 r#"#[allow($0)] struct Test;"#,
883 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
888 fn lint_rustdoc_qualified() {
891 r#"#[allow(rustdoc::$0)] struct Test;"#,
892 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
900 r#"#[allow(dep$0 struct Test;"#,
901 r#"#[allow(deprecated struct Test;"#,
905 r#"#[allow(rustdoc::$0 struct Test;"#,
906 r#"#[allow(rustdoc::bare_urls struct Test;"#,
914 fn check_repr(ra_fixture: &str, expect: Expect) {
915 let actual = completion_list(ra_fixture);
916 expect.assert_eq(&actual);
920 fn no_completion_for_incorrect_repr() {
921 check_repr(r#"#[repr{$0)] struct Test;"#, expect![[]])
927 r#"#[repr($0)] struct Test;"#,
951 check_repr(r#"#[repr(transparent, $0)] struct Test;"#, expect![[r#""#]]);
957 r#"#[repr(align(1), $0)] struct Test;"#,
980 r#"#[repr(packed, $0)] struct Test;"#,
1003 r#"#[repr(C, $0)] struct Test;"#,
1026 r#"#[repr(usize, $0)] struct Test;"#,