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_qualified() {
47 //- proc_macros: identity
52 at input_replace pub macro input_replace
53 at identity pub macro identity
59 fn inside_nested_attr() {
60 check(r#"#[cfg($0)]"#, expect![[]])
64 fn with_existing_attr() {
66 r#"#[no_mangle] #[$0] mcall!();"#,
82 fn attr_on_source_file() {
100 at no_implicit_prelude
103 at recursion_limit = "…"
104 at type_length_limit = …
105 at windows_subsystem = "…"
114 fn attr_on_module() {
138 r#"mod foo {#![$0]}"#,
152 at no_implicit_prelude
161 fn attr_on_macro_rules() {
163 r#"#[$0] macro_rules! foo {}"#,
187 fn attr_on_macro_def() {
189 r#"#[$0] macro foo {}"#,
211 fn attr_on_extern_crate() {
213 r#"#[$0] extern crate foo;"#,
260 fn attr_on_type_alias() {
262 r#"#[$0] type foo = ();"#,
284 fn attr_on_struct() {
311 at derive pub macro derive
319 r#"#[$0] enum Foo {}"#,
346 r#"#[$0] const FOO: () = ();"#,
368 fn attr_on_static() {
370 r#"#[$0] static FOO: () = ()"#,
386 at link_section = "…"
399 r#"#[$0] trait Foo {}"#,
424 r#"#[$0] impl () {}"#,
438 at automatically_derived
445 r#"impl () {#![$0]}"#,
467 fn attr_on_extern_block() {
469 r#"#[$0] extern {}"#,
490 r#"extern {#![$0]}"#,
513 fn attr_on_variant() {
515 r#"enum Foo { #[$0] Bar }"#,
534 r#"#[$0] fn main() {}"#,
550 at link_section = "…"
557 at proc_macro_derive(…)
558 at proc_macro_attribute
560 at target_feature = "…"
572 cov_mark::check!(no_keyword_completion_in_attr_of_expr);
574 r#"fn main() { #[$0] foo() }"#,
590 fn attr_in_source_file_end() {
595 at automatically_derived
612 at link_section = "…"
621 at proc_macro_attribute
622 at proc_macro_derive(…)
625 at target_feature = "…"
641 fn cfg_target_endian() {
643 r#"#[cfg(target_endian = $0"#,
655 fn check_derive(ra_fixture: &str, expect: Expect) {
656 let actual = completion_list(ra_fixture);
657 expect.assert_eq(&actual);
661 fn no_completion_for_incorrect_derive() {
664 //- minicore: derive, copy, clone, ord, eq, default, fmt
665 #[derive{$0)] struct Test;
675 //- minicore: derive, copy, clone, ord, eq, default, fmt
676 #[derive($0)] struct Test;
683 de PartialEq, Eq, PartialOrd, Ord
685 de PartialEq, PartialOrd
691 fn derive_with_input_before() {
694 //- minicore: derive, copy, clone, ord, eq, default, fmt
695 #[derive(serde::Serialize, PartialEq, $0)] struct Test;
701 de Eq, PartialOrd, Ord
709 fn derive_with_input_after() {
712 //- minicore: derive, copy, clone, ord, eq, default, fmt
713 #[derive($0 serde::Serialize, PartialEq)] struct Test;
719 de Eq, PartialOrd, Ord
727 fn derive_flyimport() {
730 //- proc_macros: derive_identity
731 #[derive(der$0)] struct Test;
734 de DeriveIdentity (use proc_macros::DeriveIdentity)
739 //- proc_macros: derive_identity
740 use proc_macros::DeriveIdentity;
741 #[derive(der$0)] struct Test;
750 fn derive_flyimport_edit() {
754 //- proc_macros: derive_identity
755 #[derive(der$0)] struct Test;
758 use proc_macros::DeriveIdentity;
760 #[derive(DeriveIdentity)] struct Test;
773 r#"#[allow($0)] struct Test;"#,
774 r#"#[allow(deprecated)] struct Test;"#,
779 fn lint_with_existing() {
782 r#"#[allow(keyword_idents, $0)] struct Test;"#,
783 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
788 fn lint_qualified() {
791 r#"#[allow(keyword_idents, $0)] struct Test;"#,
792 r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
800 r#"#[feature(box_$0)] struct Test;"#,
801 r#"#[feature(box_syntax)] struct Test;"#,
806 fn lint_clippy_unqualified() {
808 "clippy::as_conversions",
809 r#"#[allow($0)] struct Test;"#,
810 r#"#[allow(clippy::as_conversions)] struct Test;"#,
815 fn lint_clippy_qualified() {
818 r#"#[allow(clippy::$0)] struct Test;"#,
819 r#"#[allow(clippy::as_conversions)] struct Test;"#,
824 fn lint_rustdoc_unqualified() {
826 "rustdoc::bare_urls",
827 r#"#[allow($0)] struct Test;"#,
828 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
833 fn lint_rustdoc_qualified() {
836 r#"#[allow(rustdoc::$0)] struct Test;"#,
837 r#"#[allow(rustdoc::bare_urls)] struct Test;"#,
845 r#"#[allow(dep$0 struct Test;"#,
846 r#"#[allow(deprecated struct Test;"#,
850 r#"#[allow(rustdoc::$0 struct Test;"#,
851 r#"#[allow(rustdoc::bare_urls struct Test;"#,
859 fn check_repr(ra_fixture: &str, expect: Expect) {
860 let actual = completion_list(ra_fixture);
861 expect.assert_eq(&actual);
865 fn no_completion_for_incorrect_repr() {
866 check_repr(r#"#[repr{$0)] struct Test;"#, expect![[]])
872 r#"#[repr($0)] struct Test;"#,
896 check_repr(r#"#[repr(transparent, $0)] struct Test;"#, expect![[r#""#]]);
902 r#"#[repr(align(1), $0)] struct Test;"#,
925 r#"#[repr(packed, $0)] struct Test;"#,
948 r#"#[repr(C, $0)] struct Test;"#,
971 r#"#[repr(usize, $0)] struct Test;"#,