about summary refs log tree commit diff
diff options
context:
space:
mode:
authorrobojumper <robojumper@gmail.com>2021-07-18 12:21:09 +0200
committerrobojumper <robojumper@gmail.com>2021-07-18 12:21:09 +0200
commit4156473bca0cf1991383cd3643e1a6d23e38957f (patch)
tree48650196a292957f320d408e163a93563f1f5924
parent3ab6b60337edeb49339d173853fee1f8569421e0 (diff)
Add test for unsupported bound relaxation with incorrect behavior
-rw-r--r--src/test/ui/issues/issue-87199.rs21
-rw-r--r--src/test/ui/issues/issue-87199.stderr44
2 files changed, 65 insertions, 0 deletions
diff --git a/src/test/ui/issues/issue-87199.rs b/src/test/ui/issues/issue-87199.rs
new file mode 100644
index 00000000000..f2c57e44077
--- /dev/null
+++ b/src/test/ui/issues/issue-87199.rs
@@ -0,0 +1,21 @@
+// Regression test for issue #87199, where attempting to relax a bound
+// other than the only supported `?Sized` would still cause the compiler
+// to assume that the `Sized` bound was relaxed.
+
+// check-fail
+
+// Check that these function definitions only emit warnings, not errors
+fn arg<T: ?Send>(_: T) {}
+//~^ warning: default bound relaxed for a type parameter, but this does nothing
+//~^^ the size for values of type `T`
+fn ref_arg<T: ?Send>(_: &T) {}
+//~^ warning: default bound relaxed for a type parameter, but this does nothing
+fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
+//~^ warning: default bound relaxed for a type parameter, but this does nothing
+//~^^ the size for values of type `impl Iterator+?Sized` cannot be known
+
+// Check that there's no `?Sized` relaxation!
+fn main() {
+    ref_arg::<i32>(&5);
+    ref_arg::<[i32]>(&[5]);
+}
diff --git a/src/test/ui/issues/issue-87199.stderr b/src/test/ui/issues/issue-87199.stderr
new file mode 100644
index 00000000000..b0bb1da5793
--- /dev/null
+++ b/src/test/ui/issues/issue-87199.stderr
@@ -0,0 +1,44 @@
+warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
+  --> $DIR/issue-87199.rs:8:8
+   |
+LL | fn arg<T: ?Send>(_: T) {}
+   |        ^
+
+warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
+  --> $DIR/issue-87199.rs:11:12
+   |
+LL | fn ref_arg<T: ?Send>(_: &T) {}
+   |            ^
+
+warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
+  --> $DIR/issue-87199.rs:13:13
+   |
+LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0277]: the size for values of type `impl Iterator+?Sized` cannot be known at compilation time
+  --> $DIR/issue-87199.rs:13:13
+   |
+LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `Sized` is not implemented for `impl Iterator+?Sized`
+   = note: the return type of a function must have a statically known size
+
+error[E0277]: the size for values of type `T` cannot be known at compilation time
+  --> $DIR/issue-87199.rs:8:18
+   |
+LL | fn arg<T: ?Send>(_: T) {}
+   |        -         ^ doesn't have a size known at compile-time
+   |        |
+   |        this type parameter needs to be `std::marker::Sized`
+   |
+   = help: unsized fn params are gated as an unstable feature
+help: function arguments must have a statically known size, borrowed types always have a known size
+   |
+LL | fn arg<T: ?Send>(_: &T) {}
+   |                     ^
+
+error: aborting due to 2 previous errors; 3 warnings emitted
+
+For more information about this error, try `rustc --explain E0277`.