about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-18 00:19:24 +0000
committerbors <bors@rust-lang.org>2020-10-18 00:19:24 +0000
commitcbc42a0f3eae5103888dbc10f3a7cf213977468c (patch)
treee6eae8f58ce23d4d6accf4adb896aa665334d84d
parent3b0ef34f64c5e97cd485b0f8a4103438ca160a51 (diff)
parentd80f93d507406375e302d9583e02bf19d1565cfe (diff)
downloadrust-cbc42a0f3eae5103888dbc10f3a7cf213977468c.tar.gz
rust-cbc42a0f3eae5103888dbc10f3a7cf213977468c.zip
Auto merge of #77956 - JohnTitor:more-tests, r=nagisa
Add some more regression tests

This is another round of #77741. Tested with `debug-assertions=true` and it passed on my local.
Closes #70877
Closes #70944
Closes #71659
Closes #74816
Closes #75707
Closes #75983
(Skipped #63355 because I'm not sure about the error.)
-rw-r--r--src/test/ui/generic-associated-types/issue-74816.rs23
-rw-r--r--src/test/ui/generic-associated-types/issue-74816.stderr31
-rw-r--r--src/test/ui/impl-trait/issues/issue-70877.rs38
-rw-r--r--src/test/ui/impl-trait/issues/issue-70877.stderr15
-rw-r--r--src/test/ui/traits/issue-70944.rs23
-rw-r--r--src/test/ui/traits/trait-alias/issue-75983.rs17
-rw-r--r--src/test/ui/unsized/issue-71659.rs32
-rw-r--r--src/test/ui/unsized/issue-71659.stderr9
-rw-r--r--src/test/ui/unsized/issue-75707.rs17
-rw-r--r--src/test/ui/unsized/issue-75707.stderr12
10 files changed, 217 insertions, 0 deletions
diff --git a/src/test/ui/generic-associated-types/issue-74816.rs b/src/test/ui/generic-associated-types/issue-74816.rs
new file mode 100644
index 00000000000..754397229a6
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-74816.rs
@@ -0,0 +1,23 @@
+#![feature(associated_type_defaults)]
+#![feature(generic_associated_types)]
+#![allow(incomplete_features)]
+
+trait Trait1 {
+    fn foo();
+}
+
+trait Trait2 {
+    type Associated: Trait1 = Self;
+    //~^ ERROR: the trait bound `Self: Trait1` is not satisfied
+    //~| the size for values of type `Self` cannot be known
+}
+
+impl Trait2 for () {}
+
+fn call_foo<T: Trait2>() {
+    T::Associated::foo()
+}
+
+fn main() {
+    call_foo::<()>()
+}
diff --git a/src/test/ui/generic-associated-types/issue-74816.stderr b/src/test/ui/generic-associated-types/issue-74816.stderr
new file mode 100644
index 00000000000..64bc94d601b
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-74816.stderr
@@ -0,0 +1,31 @@
+error[E0277]: the trait bound `Self: Trait1` is not satisfied
+  --> $DIR/issue-74816.rs:10:5
+   |
+LL |     type Associated: Trait1 = Self;
+   |     ^^^^^^^^^^^^^^^^^------^^^^^^^^
+   |     |                |
+   |     |                required by this bound in `Trait2::Associated`
+   |     the trait `Trait1` is not implemented for `Self`
+   |
+help: consider further restricting `Self`
+   |
+LL | trait Trait2: Trait1 {
+   |             ^^^^^^^^
+
+error[E0277]: the size for values of type `Self` cannot be known at compilation time
+  --> $DIR/issue-74816.rs:10:5
+   |
+LL |     type Associated: Trait1 = Self;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     |
+   |     doesn't have a size known at compile-time
+   |     required by this bound in `Trait2::Associated`
+   |
+help: consider further restricting `Self`
+   |
+LL | trait Trait2: Sized {
+   |             ^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/impl-trait/issues/issue-70877.rs b/src/test/ui/impl-trait/issues/issue-70877.rs
new file mode 100644
index 00000000000..a4a59f98fd8
--- /dev/null
+++ b/src/test/ui/impl-trait/issues/issue-70877.rs
@@ -0,0 +1,38 @@
+#![feature(type_alias_impl_trait)]
+#![feature(impl_trait_in_bindings)]
+#![allow(incomplete_features)]
+
+type FooArg<'a> = &'a dyn ToString;
+type FooRet = impl std::fmt::Debug;
+
+type FooItem = Box<dyn Fn(FooArg) -> FooRet>;
+type Foo = impl Iterator<Item = FooItem>; //~ ERROR: type mismatch
+
+#[repr(C)]
+struct Bar(u8);
+
+impl Iterator for Bar {
+    type Item = FooItem;
+
+    fn next(&mut self) -> Option<Self::Item> {
+        Some(Box::new(quux))
+    }
+}
+
+fn quux(st: FooArg) -> FooRet {
+    Some(st.to_string())
+}
+
+fn ham() -> Foo {
+    Bar(1)
+}
+
+fn oof() -> impl std::fmt::Debug {
+    let mut bar = ham();
+    let func = bar.next().unwrap();
+    return func(&"oof");
+}
+
+fn main() {
+    let _ = oof();
+}
diff --git a/src/test/ui/impl-trait/issues/issue-70877.stderr b/src/test/ui/impl-trait/issues/issue-70877.stderr
new file mode 100644
index 00000000000..3ef7087b08a
--- /dev/null
+++ b/src/test/ui/impl-trait/issues/issue-70877.stderr
@@ -0,0 +1,15 @@
+error[E0271]: type mismatch resolving `<Bar as Iterator>::Item == Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
+  --> $DIR/issue-70877.rs:9:12
+   |
+LL | type FooRet = impl std::fmt::Debug;
+   |               -------------------- the expected opaque type
+...
+LL | type Foo = impl Iterator<Item = FooItem>;
+   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found enum `Option`
+   |
+   = note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>`
+              found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0271`.
diff --git a/src/test/ui/traits/issue-70944.rs b/src/test/ui/traits/issue-70944.rs
new file mode 100644
index 00000000000..3286de9d5b8
--- /dev/null
+++ b/src/test/ui/traits/issue-70944.rs
@@ -0,0 +1,23 @@
+// check-pass
+// Regression test of #70944, should compile fine.
+
+use std::ops::Index;
+
+pub struct KeyA;
+pub struct KeyB;
+pub struct KeyC;
+
+pub trait Foo: Index<KeyA> + Index<KeyB> + Index<KeyC> {}
+pub trait FooBuilder {
+    type Inner: Foo;
+    fn inner(&self) -> &Self::Inner;
+}
+
+pub fn do_stuff(foo: &impl FooBuilder) {
+    let inner = foo.inner();
+    &inner[KeyA];
+    &inner[KeyB];
+    &inner[KeyC];
+}
+
+fn main() {}
diff --git a/src/test/ui/traits/trait-alias/issue-75983.rs b/src/test/ui/traits/trait-alias/issue-75983.rs
new file mode 100644
index 00000000000..f9a7f36de43
--- /dev/null
+++ b/src/test/ui/traits/trait-alias/issue-75983.rs
@@ -0,0 +1,17 @@
+// check-pass
+
+#![feature(trait_alias)]
+
+struct Bar;
+trait Foo {}
+impl Foo for Bar {}
+
+trait Baz = Foo where Bar: Foo;
+
+fn new() -> impl Baz {
+    Bar
+}
+
+fn main() {
+    let _ = new();
+}
diff --git a/src/test/ui/unsized/issue-71659.rs b/src/test/ui/unsized/issue-71659.rs
new file mode 100644
index 00000000000..3524ca02bbf
--- /dev/null
+++ b/src/test/ui/unsized/issue-71659.rs
@@ -0,0 +1,32 @@
+#![feature(unsize)]
+
+use std::marker::Unsize;
+
+pub trait CastTo<T: ?Sized>: Unsize<T> {
+    fn cast_to(&self) -> &T;
+}
+
+impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U {
+    fn cast_to(&self) -> &T {
+        self
+    }
+}
+
+impl<T: ?Sized> Cast for T {}
+pub trait Cast {
+    fn cast<T: ?Sized>(&self) -> &T
+    where
+        Self: CastTo<T>,
+    {
+        self
+    }
+}
+
+pub trait Foo: CastTo<[i32]> {}
+impl Foo for [i32; 0] {}
+
+fn main() {
+    let x: &dyn Foo = &[];
+    let x = x.cast::<[i32]>();
+    //~^ ERROR: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
+}
diff --git a/src/test/ui/unsized/issue-71659.stderr b/src/test/ui/unsized/issue-71659.stderr
new file mode 100644
index 00000000000..be2df8c85e1
--- /dev/null
+++ b/src/test/ui/unsized/issue-71659.stderr
@@ -0,0 +1,9 @@
+error[E0277]: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
+  --> $DIR/issue-71659.rs:30:15
+   |
+LL |     let x = x.cast::<[i32]>();
+   |               ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Foo`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/unsized/issue-75707.rs b/src/test/ui/unsized/issue-75707.rs
new file mode 100644
index 00000000000..9f04cdbb922
--- /dev/null
+++ b/src/test/ui/unsized/issue-75707.rs
@@ -0,0 +1,17 @@
+pub trait Callback {
+    fn cb();
+}
+
+pub trait Processing {
+    type Call: Callback;
+}
+
+fn f<P: Processing + ?Sized>() {
+    P::Call::cb();
+}
+
+fn main() {
+    struct MyCall;
+    f::<dyn Processing<Call = MyCall>>();
+    //~^ ERROR: the trait bound `MyCall: Callback` is not satisfied
+}
diff --git a/src/test/ui/unsized/issue-75707.stderr b/src/test/ui/unsized/issue-75707.stderr
new file mode 100644
index 00000000000..6e557a25f95
--- /dev/null
+++ b/src/test/ui/unsized/issue-75707.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the trait bound `MyCall: Callback` is not satisfied
+  --> $DIR/issue-75707.rs:15:5
+   |
+LL | fn f<P: Processing + ?Sized>() {
+   |         ---------- required by this bound in `f`
+...
+LL |     f::<dyn Processing<Call = MyCall>>();
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Callback` is not implemented for `MyCall`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.