From d80f93d507406375e302d9583e02bf19d1565cfe Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 18 Oct 2020 08:13:25 +0900 Subject: [PATCH] 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 @@ fn cast(&self) -> &T { 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