From 7db890451896d8542dd413187b8a84a498ca5422 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 15 Oct 2020 08:35:18 +0900 Subject: [PATCH 1/7] Add test for issue-70877 --- src/test/ui/impl-trait/issues/issue-70877.rs | 38 +++++++++++++++++++ .../ui/impl-trait/issues/issue-70877.stderr | 15 ++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/test/ui/impl-trait/issues/issue-70877.rs create mode 100644 src/test/ui/impl-trait/issues/issue-70877.stderr 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 FooRet>; +type Foo = impl Iterator; //~ ERROR: type mismatch + +#[repr(C)] +struct Bar(u8); + +impl Iterator for Bar { + type Item = FooItem; + + fn next(&mut self) -> Option { + 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 `::Item == Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` + --> $DIR/issue-70877.rs:9:12 + | +LL | type FooRet = impl std::fmt::Debug; + | -------------------- the expected opaque type +... +LL | type Foo = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 + 'static)>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0271`. From 11a188a194b0f62945e8bfb76534f7198e08effe Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 15 Oct 2020 08:35:29 +0900 Subject: [PATCH 2/7] Add test for issue-70944 --- src/test/ui/traits/issue-70944.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/ui/traits/issue-70944.rs 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 + Index + Index {} +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() {} From c266c07453afe4d7c0f1b3bd96fdb202e23810f0 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 15 Oct 2020 08:35:45 +0900 Subject: [PATCH 3/7] Add test for issue-71659 --- src/test/ui/unsized/issue-71659.rs | 94 ++++++++++++++++++++++++++ src/test/ui/unsized/issue-71659.stderr | 9 +++ 2 files changed, 103 insertions(+) create mode 100644 src/test/ui/unsized/issue-71659.rs create mode 100644 src/test/ui/unsized/issue-71659.stderr diff --git a/src/test/ui/unsized/issue-71659.rs b/src/test/ui/unsized/issue-71659.rs new file mode 100644 index 00000000000..ef5ff19153e --- /dev/null +++ b/src/test/ui/unsized/issue-71659.rs @@ -0,0 +1,94 @@ +#![feature(unsize)] + +use std::marker::Unsize; +use std::rc::Rc; +use std::sync::Arc; + +pub trait CastTo: Unsize { + fn cast_to(&self) -> &T; + fn cast_mut_to(&mut self) -> &mut T; + fn into_cast_to(self: Box) -> Box; + fn cast_rc_to(self: Rc) -> Rc; + fn cast_arc_to(self: Arc) -> Arc; +} + +impl Cast for T {} +pub trait Cast { + fn cast(&self) -> &T + where + Self: CastTo, + { + self + } + + fn cast_mut(&mut self) -> &mut T + where + Self: CastTo, + { + self.cast_mut_to() + } + + fn into_cast(self: Box) -> Box + where + Self: CastTo, + { + self.into_cast_to() + } + + fn cast_rc(self: Rc) -> Rc + where + Self: CastTo, + { + self.cast_rc_to() + } + + fn cast_arc(self: Arc) -> Arc + where + Self: CastTo, + { + self.cast_arc_to() + } +} +impl> CastTo for U { + fn cast_to(&self) -> &T { + self + } + + fn cast_mut_to(&mut self) -> &mut T { + self + } + + fn into_cast_to(self: Box) -> Box { + self + } + + fn cast_rc_to(self: Rc) -> Rc { + self + } + + fn cast_arc_to(self: Arc) -> Arc { + self + } +} + +pub trait Foo { + fn foo(&self) { + println!("Foo({})", core::any::type_name::()); + } +} + +pub trait Bar: CastTo + CastTo + CastTo<[i32]> { + fn bar(&self) { + println!("Bar({})", core::any::type_name::()); + } +} + +impl Foo for [i32; 10] {} +impl Bar for [i32; 10] {} + +fn main() { + let x = [0; 10]; + let x: Box = Box::new(x); + let x = (*x).cast::<[i32]>(); + //~^ ERROR: the trait bound `dyn Bar: 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..5d23e991472 --- /dev/null +++ b/src/test/ui/unsized/issue-71659.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `dyn Bar: CastTo<[i32]>` is not satisfied + --> $DIR/issue-71659.rs:92:18 + | +LL | let x = (*x).cast::<[i32]>(); + | ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From fc3a5dc6b4af894086491ea810f948ce61cb0a1b Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 15 Oct 2020 08:36:04 +0900 Subject: [PATCH 4/7] Add test for issue-74816 --- .../generic-associated-types/issue-74816.rs | 23 ++++++++++++++ .../issue-74816.stderr | 31 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-74816.rs create mode 100644 src/test/ui/generic-associated-types/issue-74816.stderr 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::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`. From 23092c7491c05f9da6d9e100d093a02c4a5e476c Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 15 Oct 2020 08:36:16 +0900 Subject: [PATCH 5/7] Add test for issue-75707 --- src/test/ui/unsized/issue-75707.rs | 17 +++++++++++++++++ src/test/ui/unsized/issue-75707.stderr | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/test/ui/unsized/issue-75707.rs create mode 100644 src/test/ui/unsized/issue-75707.stderr 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::Call::cb(); +} + +fn main() { + struct MyCall; + f::>(); + //~^ 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() { + | ---------- required by this bound in `f` +... +LL | f::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Callback` is not implemented for `MyCall` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From 59cc9de039ca251599b007cdf32b721bdd3f4578 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 15 Oct 2020 08:36:24 +0900 Subject: [PATCH 6/7] Add test for issue-75983 --- src/test/ui/traits/trait-alias/issue-75983.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/ui/traits/trait-alias/issue-75983.rs 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(); +} From d80f93d507406375e302d9583e02bf19d1565cfe Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 18 Oct 2020 08:13:25 +0900 Subject: [PATCH 7/7] Use smaller example for issue-71659 --- src/test/ui/unsized/issue-71659.rs | 84 ++++---------------------- src/test/ui/unsized/issue-71659.stderr | 8 +-- 2 files changed, 15 insertions(+), 77 deletions(-) diff --git a/src/test/ui/unsized/issue-71659.rs b/src/test/ui/unsized/issue-71659.rs index ef5ff19153e..3524ca02bbf 100644 --- a/src/test/ui/unsized/issue-71659.rs +++ b/src/test/ui/unsized/issue-71659.rs @@ -1,15 +1,15 @@ #![feature(unsize)] use std::marker::Unsize; -use std::rc::Rc; -use std::sync::Arc; pub trait CastTo: Unsize { fn cast_to(&self) -> &T; - fn cast_mut_to(&mut self) -> &mut T; - fn into_cast_to(self: Box) -> Box; - fn cast_rc_to(self: Rc) -> Rc; - fn cast_arc_to(self: Arc) -> Arc; +} + +impl> CastTo for U { + fn cast_to(&self) -> &T { + self + } } impl Cast for T {} @@ -20,75 +20,13 @@ pub trait Cast { { self } - - fn cast_mut(&mut self) -> &mut T - where - Self: CastTo, - { - self.cast_mut_to() - } - - fn into_cast(self: Box) -> Box - where - Self: CastTo, - { - self.into_cast_to() - } - - fn cast_rc(self: Rc) -> Rc - where - Self: CastTo, - { - self.cast_rc_to() - } - - fn cast_arc(self: Arc) -> Arc - where - Self: CastTo, - { - self.cast_arc_to() - } -} -impl> CastTo for U { - fn cast_to(&self) -> &T { - self - } - - fn cast_mut_to(&mut self) -> &mut T { - self - } - - fn into_cast_to(self: Box) -> Box { - self - } - - fn cast_rc_to(self: Rc) -> Rc { - self - } - - fn cast_arc_to(self: Arc) -> Arc { - self - } } -pub trait Foo { - fn foo(&self) { - println!("Foo({})", core::any::type_name::()); - } -} - -pub trait Bar: CastTo + CastTo + CastTo<[i32]> { - fn bar(&self) { - println!("Bar({})", core::any::type_name::()); - } -} - -impl Foo for [i32; 10] {} -impl Bar for [i32; 10] {} +pub trait Foo: CastTo<[i32]> {} +impl Foo for [i32; 0] {} fn main() { - let x = [0; 10]; - let x: Box = Box::new(x); - let x = (*x).cast::<[i32]>(); - //~^ ERROR: the trait bound `dyn Bar: CastTo<[i32]>` is not satisfied + 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 index 5d23e991472..be2df8c85e1 100644 --- a/src/test/ui/unsized/issue-71659.stderr +++ b/src/test/ui/unsized/issue-71659.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `dyn Bar: CastTo<[i32]>` is not satisfied - --> $DIR/issue-71659.rs:92:18 +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 Bar` +LL | let x = x.cast::<[i32]>(); + | ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Foo` error: aborting due to previous error