about summary refs log tree commit diff
path: root/tests/ui/trait-bounds
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/trait-bounds')
-rw-r--r--tests/ui/trait-bounds/duplicate-relaxed-bounds.rs22
-rw-r--r--tests/ui/trait-bounds/duplicate-relaxed-bounds.stderr47
-rw-r--r--tests/ui/trait-bounds/fix-dyn-sized-fn-param-sugg.rs (renamed from tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs)25
-rw-r--r--tests/ui/trait-bounds/fix-dyn-sized-fn-param-sugg.stderr (renamed from tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr)40
-rw-r--r--tests/ui/trait-bounds/maybe-bound-has-path-args.rs2
-rw-r--r--tests/ui/trait-bounds/maybe-bound-has-path-args.stderr2
-rw-r--r--tests/ui/trait-bounds/maybe-bound-with-assoc.rs4
-rw-r--r--tests/ui/trait-bounds/maybe-bound-with-assoc.stderr4
-rw-r--r--tests/ui/trait-bounds/more_maybe_bounds.rs29
-rw-r--r--tests/ui/trait-bounds/more_maybe_bounds.stderr20
10 files changed, 156 insertions, 39 deletions
diff --git a/tests/ui/trait-bounds/duplicate-relaxed-bounds.rs b/tests/ui/trait-bounds/duplicate-relaxed-bounds.rs
new file mode 100644
index 00000000000..a1681ddec77
--- /dev/null
+++ b/tests/ui/trait-bounds/duplicate-relaxed-bounds.rs
@@ -0,0 +1,22 @@
+fn dupes<T: ?Sized + ?Sized + ?Iterator + ?Iterator>() {}
+//~^ ERROR duplicate relaxed `Sized` bounds
+//~| ERROR duplicate relaxed `Iterator` bounds
+//~| ERROR bound modifier `?` can only be applied to `Sized`
+//~| ERROR bound modifier `?` can only be applied to `Sized`
+
+trait Trait {
+    // We used to say "type parameter has more than one relaxed default bound"
+    // even on *associated types* like here. Test that we no longer do that.
+    type Type: ?Sized + ?Sized;
+    //~^ ERROR duplicate relaxed `Sized` bounds
+    //~| ERROR duplicate relaxed `Sized` bounds
+}
+
+// We used to emit an additional error about "multiple relaxed default bounds".
+// However, multiple relaxed bounds are actually *fine* if they're distinct.
+// Ultimately, we still reject this because `Sized` is
+// the only (stable) default trait, so we're fine.
+fn not_dupes<T: ?Sized + ?Iterator>() {}
+//~^ ERROR bound modifier `?` can only be applied to `Sized`
+
+fn main() {}
diff --git a/tests/ui/trait-bounds/duplicate-relaxed-bounds.stderr b/tests/ui/trait-bounds/duplicate-relaxed-bounds.stderr
new file mode 100644
index 00000000000..ccc723fc7a6
--- /dev/null
+++ b/tests/ui/trait-bounds/duplicate-relaxed-bounds.stderr
@@ -0,0 +1,47 @@
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/duplicate-relaxed-bounds.rs:1:13
+   |
+LL | fn dupes<T: ?Sized + ?Sized + ?Iterator + ?Iterator>() {}
+   |             ^^^^^^   ^^^^^^
+
+error[E0203]: duplicate relaxed `Iterator` bounds
+  --> $DIR/duplicate-relaxed-bounds.rs:1:31
+   |
+LL | fn dupes<T: ?Sized + ?Sized + ?Iterator + ?Iterator>() {}
+   |                               ^^^^^^^^^   ^^^^^^^^^
+
+error: bound modifier `?` can only be applied to `Sized`
+  --> $DIR/duplicate-relaxed-bounds.rs:1:31
+   |
+LL | fn dupes<T: ?Sized + ?Sized + ?Iterator + ?Iterator>() {}
+   |                               ^^^^^^^^^
+
+error: bound modifier `?` can only be applied to `Sized`
+  --> $DIR/duplicate-relaxed-bounds.rs:1:43
+   |
+LL | fn dupes<T: ?Sized + ?Sized + ?Iterator + ?Iterator>() {}
+   |                                           ^^^^^^^^^
+
+error: bound modifier `?` can only be applied to `Sized`
+  --> $DIR/duplicate-relaxed-bounds.rs:19:26
+   |
+LL | fn not_dupes<T: ?Sized + ?Iterator>() {}
+   |                          ^^^^^^^^^
+
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/duplicate-relaxed-bounds.rs:10:16
+   |
+LL |     type Type: ?Sized + ?Sized;
+   |                ^^^^^^   ^^^^^^
+
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/duplicate-relaxed-bounds.rs:10:16
+   |
+LL |     type Type: ?Sized + ?Sized;
+   |                ^^^^^^   ^^^^^^
+   |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0203`.
diff --git a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs b/tests/ui/trait-bounds/fix-dyn-sized-fn-param-sugg.rs
index e6d7f74880f..1aa36207bc3 100644
--- a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs
+++ b/tests/ui/trait-bounds/fix-dyn-sized-fn-param-sugg.rs
@@ -1,39 +1,38 @@
-// Regression test for #127441
-
-// Tests that we make the correct suggestion
-// in case there are more than one `?Sized`
-// bounds on a function parameter
+// Test that we emit a correct structured suggestions for dynamically sized ("maybe unsized")
+// function parameters.
+// We used to emit a butchered suggestion if duplicate relaxed `Sized` bounds were present.
+// issue: <https://github.com/rust-lang/rust/issues/127441>.
 
 use std::fmt::Debug;
 
 fn foo1<T: ?Sized>(a: T) {}
-//~^ ERROR he size for values of type `T` cannot be known at compilation time
+//~^ ERROR the size for values of type `T` cannot be known at compilation time
 
 fn foo2<T: ?Sized + ?Sized>(a: T) {}
-//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
+//~^ ERROR duplicate relaxed `Sized` bounds
 //~| ERROR the size for values of type `T` cannot be known at compilation time
 
 fn foo3<T: ?Sized + ?Sized + Debug>(a: T) {}
-//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
-//~| ERROR he size for values of type `T` cannot be known at compilation time
+//~^ ERROR duplicate relaxed `Sized` bounds
+//~| ERROR the size for values of type `T` cannot be known at compilation time
 
 fn foo4<T: ?Sized + Debug + ?Sized >(a: T) {}
-//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
+//~^ ERROR duplicate relaxed `Sized` bounds
 //~| ERROR the size for values of type `T` cannot be known at compilation time
 
 fn foo5(_: impl ?Sized) {}
 //~^ ERROR the size for values of type `impl ?Sized` cannot be known at compilation time
 
 fn foo6(_: impl ?Sized + ?Sized) {}
-//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
+//~^ ERROR duplicate relaxed `Sized` bounds
 //~| ERROR the size for values of type `impl ?Sized + ?Sized` cannot be known at compilation tim
 
 fn foo7(_: impl ?Sized + ?Sized + Debug) {}
-//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
+//~^ ERROR duplicate relaxed `Sized` bounds
 //~| ERROR the size for values of type `impl ?Sized + ?Sized + Debug` cannot be known at compilation time
 
 fn foo8(_: impl ?Sized + Debug + ?Sized ) {}
-//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
+//~^ ERROR duplicate relaxed `Sized` bounds
 //~| ERROR the size for values of type `impl ?Sized + Debug + ?Sized` cannot be known at compilation time
 
 fn main() {}
diff --git a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr b/tests/ui/trait-bounds/fix-dyn-sized-fn-param-sugg.stderr
index 363f52d6df8..7a9c2f043ac 100644
--- a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr
+++ b/tests/ui/trait-bounds/fix-dyn-sized-fn-param-sugg.stderr
@@ -1,41 +1,41 @@
-error[E0203]: type parameter has more than one relaxed default bound, only one is supported
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:12:12
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:11:12
    |
 LL | fn foo2<T: ?Sized + ?Sized>(a: T) {}
    |            ^^^^^^   ^^^^^^
 
-error[E0203]: type parameter has more than one relaxed default bound, only one is supported
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:16:12
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:15:12
    |
 LL | fn foo3<T: ?Sized + ?Sized + Debug>(a: T) {}
    |            ^^^^^^   ^^^^^^
 
-error[E0203]: type parameter has more than one relaxed default bound, only one is supported
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:20:12
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:19:12
    |
 LL | fn foo4<T: ?Sized + Debug + ?Sized >(a: T) {}
    |            ^^^^^^           ^^^^^^
 
-error[E0203]: type parameter has more than one relaxed default bound, only one is supported
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:27:17
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:26:17
    |
 LL | fn foo6(_: impl ?Sized + ?Sized) {}
    |                 ^^^^^^   ^^^^^^
 
-error[E0203]: type parameter has more than one relaxed default bound, only one is supported
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:31:17
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:30:17
    |
 LL | fn foo7(_: impl ?Sized + ?Sized + Debug) {}
    |                 ^^^^^^   ^^^^^^
 
-error[E0203]: type parameter has more than one relaxed default bound, only one is supported
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:35:17
+error[E0203]: duplicate relaxed `Sized` bounds
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:34:17
    |
 LL | fn foo8(_: impl ?Sized + Debug + ?Sized ) {}
    |                 ^^^^^^           ^^^^^^
 
 error[E0277]: the size for values of type `T` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:9:23
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:8:23
    |
 LL | fn foo1<T: ?Sized>(a: T) {}
    |         -             ^ doesn't have a size known at compile-time
@@ -54,7 +54,7 @@ LL | fn foo1<T: ?Sized>(a: &T) {}
    |                       +
 
 error[E0277]: the size for values of type `T` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:12:32
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:11:32
    |
 LL | fn foo2<T: ?Sized + ?Sized>(a: T) {}
    |         -                      ^ doesn't have a size known at compile-time
@@ -73,7 +73,7 @@ LL | fn foo2<T: ?Sized + ?Sized>(a: &T) {}
    |                                +
 
 error[E0277]: the size for values of type `T` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:16:40
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:15:40
    |
 LL | fn foo3<T: ?Sized + ?Sized + Debug>(a: T) {}
    |         -                              ^ doesn't have a size known at compile-time
@@ -92,7 +92,7 @@ LL | fn foo3<T: ?Sized + ?Sized + Debug>(a: &T) {}
    |                                        +
 
 error[E0277]: the size for values of type `T` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:20:41
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:19:41
    |
 LL | fn foo4<T: ?Sized + Debug + ?Sized >(a: T) {}
    |         -                               ^ doesn't have a size known at compile-time
@@ -111,7 +111,7 @@ LL | fn foo4<T: ?Sized + Debug + ?Sized >(a: &T) {}
    |                                         +
 
 error[E0277]: the size for values of type `impl ?Sized` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:24:12
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:23:12
    |
 LL | fn foo5(_: impl ?Sized) {}
    |            ^^^^^^^^^^^
@@ -131,7 +131,7 @@ LL | fn foo5(_: &impl ?Sized) {}
    |            +
 
 error[E0277]: the size for values of type `impl ?Sized + ?Sized` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:27:12
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:26:12
    |
 LL | fn foo6(_: impl ?Sized + ?Sized) {}
    |            ^^^^^^^^^^^^^^^^^^^^
@@ -151,7 +151,7 @@ LL | fn foo6(_: &impl ?Sized + ?Sized) {}
    |            +
 
 error[E0277]: the size for values of type `impl ?Sized + ?Sized + Debug` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:31:12
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:30:12
    |
 LL | fn foo7(_: impl ?Sized + ?Sized + Debug) {}
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -171,7 +171,7 @@ LL | fn foo7(_: &impl ?Sized + ?Sized + Debug) {}
    |            +
 
 error[E0277]: the size for values of type `impl ?Sized + Debug + ?Sized` cannot be known at compilation time
-  --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:35:12
+  --> $DIR/fix-dyn-sized-fn-param-sugg.rs:34:12
    |
 LL | fn foo8(_: impl ?Sized + Debug + ?Sized ) {}
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/trait-bounds/maybe-bound-has-path-args.rs b/tests/ui/trait-bounds/maybe-bound-has-path-args.rs
index e5abcae5d21..14a26670497 100644
--- a/tests/ui/trait-bounds/maybe-bound-has-path-args.rs
+++ b/tests/ui/trait-bounds/maybe-bound-has-path-args.rs
@@ -2,6 +2,6 @@ trait Trait {}
 
 fn test<T: ?self::<i32>::Trait>() {}
 //~^ ERROR type arguments are not allowed on module `maybe_bound_has_path_args`
-//~| ERROR relaxing a default bound only does something for `?Sized`
+//~| ERROR bound modifier `?` can only be applied to `Sized`
 
 fn main() {}
diff --git a/tests/ui/trait-bounds/maybe-bound-has-path-args.stderr b/tests/ui/trait-bounds/maybe-bound-has-path-args.stderr
index dc55b26c918..bf968b05af0 100644
--- a/tests/ui/trait-bounds/maybe-bound-has-path-args.stderr
+++ b/tests/ui/trait-bounds/maybe-bound-has-path-args.stderr
@@ -1,4 +1,4 @@
-error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
+error: bound modifier `?` can only be applied to `Sized`
   --> $DIR/maybe-bound-has-path-args.rs:3:12
    |
 LL | fn test<T: ?self::<i32>::Trait>() {}
diff --git a/tests/ui/trait-bounds/maybe-bound-with-assoc.rs b/tests/ui/trait-bounds/maybe-bound-with-assoc.rs
index 9127c2de16d..e123f18474d 100644
--- a/tests/ui/trait-bounds/maybe-bound-with-assoc.rs
+++ b/tests/ui/trait-bounds/maybe-bound-with-assoc.rs
@@ -2,11 +2,11 @@ trait HasAssoc {
     type Assoc;
 }
 fn hasassoc<T: ?HasAssoc<Assoc = ()>>() {}
-//~^ ERROR relaxing a default bound
+//~^ ERROR bound modifier `?` can only be applied to `Sized`
 
 trait NoAssoc {}
 fn noassoc<T: ?NoAssoc<Missing = ()>>() {}
-//~^ ERROR relaxing a default bound
+//~^ ERROR bound modifier `?` can only be applied to `Sized`
 //~| ERROR associated type `Missing` not found for `NoAssoc`
 
 fn main() {}
diff --git a/tests/ui/trait-bounds/maybe-bound-with-assoc.stderr b/tests/ui/trait-bounds/maybe-bound-with-assoc.stderr
index 36a1e0ade20..b2ae0584aff 100644
--- a/tests/ui/trait-bounds/maybe-bound-with-assoc.stderr
+++ b/tests/ui/trait-bounds/maybe-bound-with-assoc.stderr
@@ -1,10 +1,10 @@
-error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
+error: bound modifier `?` can only be applied to `Sized`
   --> $DIR/maybe-bound-with-assoc.rs:4:16
    |
 LL | fn hasassoc<T: ?HasAssoc<Assoc = ()>>() {}
    |                ^^^^^^^^^^^^^^^^^^^^^
 
-error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
+error: bound modifier `?` can only be applied to `Sized`
   --> $DIR/maybe-bound-with-assoc.rs:8:15
    |
 LL | fn noassoc<T: ?NoAssoc<Missing = ()>>() {}
diff --git a/tests/ui/trait-bounds/more_maybe_bounds.rs b/tests/ui/trait-bounds/more_maybe_bounds.rs
new file mode 100644
index 00000000000..47348b0a0dd
--- /dev/null
+++ b/tests/ui/trait-bounds/more_maybe_bounds.rs
@@ -0,0 +1,29 @@
+// FIXME(more_maybe_bounds): Even under `more_maybe_bounds` / `-Zexperimental-default-bounds`,
+// trying to relax non-default bounds should still be an error in all contexts! As you can see
+// there are places like supertrait bounds and trait object types where we currently don't perform
+// this check.
+#![feature(auto_traits, more_maybe_bounds, negative_impls)]
+
+trait Trait1 {}
+auto trait Trait2 {}
+
+// FIXME: `?Trait1` should be rejected, `Trait1` isn't marked `#[lang = "default_traitN"]`.
+trait Trait3: ?Trait1 {}
+trait Trait4 where Self: Trait1 {}
+
+// FIXME: `?Trait2` should be rejected, `Trait2` isn't marked `#[lang = "default_traitN"]`.
+fn foo(_: Box<(dyn Trait3 + ?Trait2)>) {}
+fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
+//~^ ERROR bound modifier `?` can only be applied to default traits like `Sized`
+//~| ERROR bound modifier `?` can only be applied to default traits like `Sized`
+//~| ERROR bound modifier `?` can only be applied to default traits like `Sized`
+
+struct S;
+impl !Trait2 for S {}
+impl Trait1 for S {}
+impl Trait3 for S {}
+
+fn main() {
+    foo(Box::new(S));
+    bar(&S);
+}
diff --git a/tests/ui/trait-bounds/more_maybe_bounds.stderr b/tests/ui/trait-bounds/more_maybe_bounds.stderr
new file mode 100644
index 00000000000..09c9fc31165
--- /dev/null
+++ b/tests/ui/trait-bounds/more_maybe_bounds.stderr
@@ -0,0 +1,20 @@
+error: bound modifier `?` can only be applied to default traits like `Sized`
+  --> $DIR/more_maybe_bounds.rs:16:20
+   |
+LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
+   |                    ^^^^^^^
+
+error: bound modifier `?` can only be applied to default traits like `Sized`
+  --> $DIR/more_maybe_bounds.rs:16:30
+   |
+LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
+   |                              ^^^^^^^
+
+error: bound modifier `?` can only be applied to default traits like `Sized`
+  --> $DIR/more_maybe_bounds.rs:16:40
+   |
+LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
+   |                                        ^^^^^^^
+
+error: aborting due to 3 previous errors
+