Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs140
1 files changed, 140 insertions, 0 deletions
diff --git a/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs b/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs
index a319a0bcf6..a6d2ed3223 100644
--- a/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs
+++ b/crates/ide-diagnostics/src/handlers/generic_args_prohibited.rs
@@ -34,6 +34,8 @@ fn describe_reason(reason: GenericArgsProhibitedReason) -> String {
return "you can specify generic arguments on either the enum or the variant, but not both"
.to_owned();
}
+ GenericArgsProhibitedReason::Const => "constants",
+ GenericArgsProhibitedReason::Static => "statics",
};
format!("generic arguments are not allowed on {kind}")
}
@@ -439,4 +441,142 @@ impl Trait for () {
"#,
);
}
+
+ #[test]
+ fn in_record_expr() {
+ check_diagnostics(
+ r#"
+mod foo {
+ pub struct Bar { pub field: i32 }
+}
+fn baz() {
+ let _ = foo::<()>::Bar { field: 0 };
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn in_record_pat() {
+ check_diagnostics(
+ r#"
+mod foo {
+ pub struct Bar { field: i32 }
+}
+fn baz(v: foo::Bar) {
+ let foo::<()>::Bar { .. } = v;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn in_tuple_struct_pat() {
+ check_diagnostics(
+ r#"
+mod foo {
+ pub struct Bar(i32);
+}
+fn baz(v: foo::Bar) {
+ let foo::<()>::Bar(..) = v;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn in_path_pat() {
+ check_diagnostics(
+ r#"
+mod foo {
+ pub struct Bar;
+}
+fn baz(v: foo::Bar) {
+ let foo::<()>::Bar = v;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn in_path_expr() {
+ check_diagnostics(
+ r#"
+mod foo {
+ pub struct Bar;
+}
+fn baz() {
+ let _ = foo::<()>::Bar;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn const_and_static() {
+ check_diagnostics(
+ r#"
+const CONST: i32 = 0;
+static STATIC: i32 = 0;
+fn baz() {
+ let _ = CONST::<()>;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on constants
+ let _ = STATIC::<()>;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on statics
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn enum_variant() {
+ check_diagnostics(
+ r#"
+enum Enum<A> {
+ Variant(A),
+}
+mod enum_ {
+ pub(super) use super::Enum::Variant as V;
+}
+fn baz() {
+ let v = Enum::<()>::Variant::<()>(());
+ // ^^^^^^ 💡 error: you can specify generic arguments on either the enum or the variant, but not both
+ let Enum::<()>::Variant::<()>(..) = v;
+ // ^^^^^^ 💡 error: you can specify generic arguments on either the enum or the variant, but not both
+ let _ = Enum::<()>::Variant(());
+ let _ = Enum::Variant::<()>(());
+}
+fn foo() {
+ use Enum::Variant;
+ let _ = Variant::<()>(());
+ let _ = enum_::V::<()>(());
+ let _ = enum_::<()>::V::<()>(());
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn dyn_trait() {
+ check_diagnostics(
+ r#"
+mod foo {
+ pub trait Trait {}
+}
+
+fn bar() {
+ let _: &dyn foo::<()>::Trait;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+ let _: &foo::<()>::Trait;
+ // ^^^^^^ 💡 error: generic arguments are not allowed on modules
+}
+ "#,
+ );
+ }
}