summaryrefslogtreecommitdiffstats
path: root/tests/ui/object-safety
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/object-safety')
-rw-r--r--tests/ui/object-safety/assoc_type_bounds_sized_used.rs6
-rw-r--r--tests/ui/object-safety/assoc_type_bounds_sized_used.stderr23
-rw-r--r--tests/ui/object-safety/call-when-assoc-ty-is-sized.rs25
3 files changed, 32 insertions, 22 deletions
diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_used.rs b/tests/ui/object-safety/assoc_type_bounds_sized_used.rs
index cf5345b1c..d59fc1712 100644
--- a/tests/ui/object-safety/assoc_type_bounds_sized_used.rs
+++ b/tests/ui/object-safety/assoc_type_bounds_sized_used.rs
@@ -1,6 +1,5 @@
-//! This test checks that even if some associated types have
-//! `where Self: Sized` bounds, those without still need to be
-//! mentioned in trait objects.
+//! This test checks that associated types with `Self: Sized` cannot be projected
+//! from a `dyn Trait`.
trait Bop {
type Bar: Default
@@ -16,5 +15,4 @@ fn bop<T: Bop + ?Sized>() {
fn main() {
bop::<dyn Bop>();
- //~^ ERROR: the size for values of type `dyn Bop` cannot be known at compilation time
}
diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr b/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr
index f8488d842..224d33fb2 100644
--- a/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr
+++ b/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr
@@ -1,5 +1,5 @@
error[E0599]: the function or associated item `default` exists for associated type `<T as Bop>::Bar`, but its trait bounds were not satisfied
- --> $DIR/assoc_type_bounds_sized_used.rs:12:30
+ --> $DIR/assoc_type_bounds_sized_used.rs:11:30
|
LL | let _ = <T as Bop>::Bar::default();
| ^^^^^^^ function or associated item cannot be called on `<T as Bop>::Bar` due to unsatisfied trait bounds
@@ -13,15 +13,15 @@ LL | fn bop<T: Bop + ?Sized>() where T: Sized {
| ++++++++++++++
error[E0277]: the size for values of type `T` cannot be known at compilation time
- --> $DIR/assoc_type_bounds_sized_used.rs:12:13
+ --> $DIR/assoc_type_bounds_sized_used.rs:11:14
|
LL | fn bop<T: Bop + ?Sized>() {
| - this type parameter needs to be `Sized`
LL | let _ = <T as Bop>::Bar::default();
- | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ | ^ doesn't have a size known at compile-time
|
note: required by a bound in `Bop::Bar`
- --> $DIR/assoc_type_bounds_sized_used.rs:8:15
+ --> $DIR/assoc_type_bounds_sized_used.rs:7:15
|
LL | type Bar: Default
| --- required by a bound in this associated type
@@ -34,20 +34,7 @@ LL - fn bop<T: Bop + ?Sized>() {
LL + fn bop<T: Bop>() {
|
-error[E0277]: the size for values of type `dyn Bop` cannot be known at compilation time
- --> $DIR/assoc_type_bounds_sized_used.rs:18:11
- |
-LL | bop::<dyn Bop>();
- | ^^^^^^^ doesn't have a size known at compile-time
- |
- = help: the trait `Sized` is not implemented for `dyn Bop`
-note: required by a bound in `bop`
- --> $DIR/assoc_type_bounds_sized_used.rs:11:11
- |
-LL | fn bop<T: Bop + ?Sized>() {
- | ^^^ required by this bound in `bop`
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
diff --git a/tests/ui/object-safety/call-when-assoc-ty-is-sized.rs b/tests/ui/object-safety/call-when-assoc-ty-is-sized.rs
new file mode 100644
index 000000000..0b30a88fd
--- /dev/null
+++ b/tests/ui/object-safety/call-when-assoc-ty-is-sized.rs
@@ -0,0 +1,25 @@
+// check-pass
+// revisions: current next
+//[next] compile-flags: -Ztrait-solver=next
+
+trait Foo {
+ type Bar<'a>
+ where
+ Self: Sized;
+
+ fn test(&self);
+}
+
+impl Foo for () {
+ type Bar<'a> = () where Self: Sized;
+
+ fn test(&self) {}
+}
+
+fn test(x: &dyn Foo) {
+ x.test();
+}
+
+fn main() {
+ test(&());
+}