about summary refs log tree commit diff
path: root/tests/ui/generics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/generics')
-rw-r--r--tests/ui/generics/generic-extern.rs10
-rw-r--r--tests/ui/generics/generic-extern.stderr23
-rw-r--r--tests/ui/generics/invalid-type-param-default.rs22
-rw-r--r--tests/ui/generics/invalid-type-param-default.stderr70
-rw-r--r--tests/ui/generics/overlapping-errors-span-issue-123861.rs2
-rw-r--r--tests/ui/generics/overlapping-errors-span-issue-123861.stderr4
-rw-r--r--tests/ui/generics/unnecessary-path-disambiguator-36116.rs26
-rw-r--r--tests/ui/generics/unused-type-parameter-regression-36075.rs15
8 files changed, 159 insertions, 13 deletions
diff --git a/tests/ui/generics/generic-extern.rs b/tests/ui/generics/generic-extern.rs
index 36fa5eaafd6..b4f00fc1187 100644
--- a/tests/ui/generics/generic-extern.rs
+++ b/tests/ui/generics/generic-extern.rs
@@ -1,7 +1,15 @@
+// Ensure that we reject generic parameters on foreign items.
+
 extern "C" {
     fn foo<T>(); //~ ERROR foreign items may not have type parameters
+
+    // Furthermore, check that type parameter defaults lead to a *hard* error,
+    // not just a lint error, for maximum forward compatibility.
+    #[allow(invalid_type_param_default)] // Should have no effect here.
+    fn bar<T = ()>(); //~ ERROR foreign items may not have type parameters
+    //~^ ERROR defaults for generic parameters are not allowed here
 }
 
 fn main() {
-    foo::<i32>(); //~ ERROR requires unsafe
+    unsafe { foo::<i32>() };
 }
diff --git a/tests/ui/generics/generic-extern.stderr b/tests/ui/generics/generic-extern.stderr
index a3f28825316..6e837156812 100644
--- a/tests/ui/generics/generic-extern.stderr
+++ b/tests/ui/generics/generic-extern.stderr
@@ -1,20 +1,25 @@
 error[E0044]: foreign items may not have type parameters
-  --> $DIR/generic-extern.rs:2:5
+  --> $DIR/generic-extern.rs:4:5
    |
 LL |     fn foo<T>();
    |     ^^^^^^^^^^^^ can't have type parameters
    |
    = help: replace the type parameters with concrete types like `u32`
 
-error[E0133]: call to unsafe function `foo` is unsafe and requires unsafe function or block
-  --> $DIR/generic-extern.rs:6:5
+error: defaults for generic parameters are not allowed here
+  --> $DIR/generic-extern.rs:9:12
    |
-LL |     foo::<i32>();
-   |     ^^^^^^^^^^^^ call to unsafe function
+LL |     fn bar<T = ()>();
+   |            ^^^^^^
+
+error[E0044]: foreign items may not have type parameters
+  --> $DIR/generic-extern.rs:9:5
    |
-   = note: consult the function's documentation for information on how to avoid undefined behavior
+LL |     fn bar<T = ()>();
+   |     ^^^^^^^^^^^^^^^^^ can't have type parameters
+   |
+   = help: replace the type parameters with concrete types like `u32`
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
 
-Some errors have detailed explanations: E0044, E0133.
-For more information about an error, try `rustc --explain E0044`.
+For more information about this error, try `rustc --explain E0044`.
diff --git a/tests/ui/generics/invalid-type-param-default.rs b/tests/ui/generics/invalid-type-param-default.rs
new file mode 100644
index 00000000000..b47e142605c
--- /dev/null
+++ b/tests/ui/generics/invalid-type-param-default.rs
@@ -0,0 +1,22 @@
+// Ensure that we emit the deny-by-default lint `invalid_type_param_default` in locations where
+// type parameter defaults were accidentally allowed but don't have any effect whatsoever.
+//
+// Tracked in <https://github.com/rust-lang/rust/issues/36887>.
+// FIXME(default_type_parameter_fallback): Consider reallowing them once they work properly.
+
+fn avg<T = i32>(_: T) {}
+//~^ ERROR defaults for generic parameters are not allowed here [invalid_type_param_default]
+//~| WARN this was previously accepted
+
+// issue: <https://github.com/rust-lang/rust/issues/26812>
+fn mdn<T = T::Item>(_: T) {}
+//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
+//~| ERROR defaults for generic parameters are not allowed here [invalid_type_param_default]
+//~| WARN this was previously accepted
+
+struct S<T>(T);
+impl<T = i32> S<T> {}
+//~^ ERROR defaults for generic parameters are not allowed here [invalid_type_param_default]
+//~| WARN this was previously accepted
+
+fn main() {}
diff --git a/tests/ui/generics/invalid-type-param-default.stderr b/tests/ui/generics/invalid-type-param-default.stderr
new file mode 100644
index 00000000000..1c8fdd8ab5c
--- /dev/null
+++ b/tests/ui/generics/invalid-type-param-default.stderr
@@ -0,0 +1,70 @@
+error[E0128]: generic parameter defaults cannot reference parameters before they are declared
+  --> $DIR/invalid-type-param-default.rs:12:12
+   |
+LL | fn mdn<T = T::Item>(_: T) {}
+   |            ^^^^^^^ cannot reference `T` before it is declared
+
+error: defaults for generic parameters are not allowed here
+  --> $DIR/invalid-type-param-default.rs:7:8
+   |
+LL | fn avg<T = i32>(_: T) {}
+   |        ^^^^^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+   = note: `#[deny(invalid_type_param_default)]` on by default
+
+error: defaults for generic parameters are not allowed here
+  --> $DIR/invalid-type-param-default.rs:12:8
+   |
+LL | fn mdn<T = T::Item>(_: T) {}
+   |        ^^^^^^^^^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+
+error: defaults for generic parameters are not allowed here
+  --> $DIR/invalid-type-param-default.rs:18:6
+   |
+LL | impl<T = i32> S<T> {}
+   |      ^^^^^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0128`.
+Future incompatibility report: Future breakage diagnostic:
+error: defaults for generic parameters are not allowed here
+  --> $DIR/invalid-type-param-default.rs:7:8
+   |
+LL | fn avg<T = i32>(_: T) {}
+   |        ^^^^^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+   = note: `#[deny(invalid_type_param_default)]` on by default
+
+Future breakage diagnostic:
+error: defaults for generic parameters are not allowed here
+  --> $DIR/invalid-type-param-default.rs:12:8
+   |
+LL | fn mdn<T = T::Item>(_: T) {}
+   |        ^^^^^^^^^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+   = note: `#[deny(invalid_type_param_default)]` on by default
+
+Future breakage diagnostic:
+error: defaults for generic parameters are not allowed here
+  --> $DIR/invalid-type-param-default.rs:18:6
+   |
+LL | impl<T = i32> S<T> {}
+   |      ^^^^^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+   = note: `#[deny(invalid_type_param_default)]` on by default
+
diff --git a/tests/ui/generics/overlapping-errors-span-issue-123861.rs b/tests/ui/generics/overlapping-errors-span-issue-123861.rs
index e0a27f68748..2549f4b3714 100644
--- a/tests/ui/generics/overlapping-errors-span-issue-123861.rs
+++ b/tests/ui/generics/overlapping-errors-span-issue-123861.rs
@@ -1,7 +1,7 @@
 fn mainIterator<_ = _> {}
 //~^ ERROR expected identifier, found reserved identifier `_`
 //~| ERROR   missing parameters for function definition
-//~| ERROR   defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions [invalid_type_param_default]
+//~| ERROR   defaults for generic parameters are not allowed here [invalid_type_param_default]
 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
 //~| ERROR   the placeholder `_` is not allowed within types on item signatures for functions [E0121]
 
diff --git a/tests/ui/generics/overlapping-errors-span-issue-123861.stderr b/tests/ui/generics/overlapping-errors-span-issue-123861.stderr
index 7d08d8fed9f..44e8b4a01e7 100644
--- a/tests/ui/generics/overlapping-errors-span-issue-123861.stderr
+++ b/tests/ui/generics/overlapping-errors-span-issue-123861.stderr
@@ -15,7 +15,7 @@ help: add a parameter list
 LL | fn mainIterator<_ = _>() {}
    |                       ++
 
-error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
+error: defaults for generic parameters are not allowed here
   --> $DIR/overlapping-errors-span-issue-123861.rs:1:17
    |
 LL | fn mainIterator<_ = _> {}
@@ -35,7 +35,7 @@ error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0121`.
 Future incompatibility report: Future breakage diagnostic:
-error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
+error: defaults for generic parameters are not allowed here
   --> $DIR/overlapping-errors-span-issue-123861.rs:1:17
    |
 LL | fn mainIterator<_ = _> {}
diff --git a/tests/ui/generics/unnecessary-path-disambiguator-36116.rs b/tests/ui/generics/unnecessary-path-disambiguator-36116.rs
new file mode 100644
index 00000000000..c2dab605f59
--- /dev/null
+++ b/tests/ui/generics/unnecessary-path-disambiguator-36116.rs
@@ -0,0 +1,26 @@
+// https://github.com/rust-lang/rust/issues/36116
+// Unnecessary path disambiguator is ok
+
+//@ check-pass
+
+macro_rules! m {
+    ($p: path) => {
+        let _ = $p(0);
+        let _: $p;
+    }
+}
+
+struct Foo<T> {
+    _a: T,
+}
+
+struct S<T>(T);
+
+fn f() {
+    let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
+    let g: Foo::<i32> = Foo { _a: 42 };
+
+    m!(S::<u8>);
+}
+
+fn main() {}
diff --git a/tests/ui/generics/unused-type-parameter-regression-36075.rs b/tests/ui/generics/unused-type-parameter-regression-36075.rs
new file mode 100644
index 00000000000..4d6eb617b59
--- /dev/null
+++ b/tests/ui/generics/unused-type-parameter-regression-36075.rs
@@ -0,0 +1,15 @@
+// https://github.com/rust-lang/rust/issues/36075
+//@ check-pass
+#![allow(dead_code)]
+trait DeclarationParser {
+    type Declaration;
+}
+
+struct DeclarationListParser<'i, I, P>
+    where P: DeclarationParser<Declaration = I>
+{
+    input: &'i (),
+    parser: P
+}
+
+fn main() {}