Skip to content

Commit d80f93d

Browse files
committed
Use smaller example for issue-71659
1 parent 59cc9de commit d80f93d

File tree

2 files changed

+15
-77
lines changed

2 files changed

+15
-77
lines changed

src/test/ui/unsized/issue-71659.rs

+11-73
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,32 @@
11
#![feature(unsize)]
22

33
use std::marker::Unsize;
4-
use std::rc::Rc;
5-
use std::sync::Arc;
64

75
pub trait CastTo<T: ?Sized>: Unsize<T> {
86
fn cast_to(&self) -> &T;
9-
fn cast_mut_to(&mut self) -> &mut T;
10-
fn into_cast_to(self: Box<Self>) -> Box<T>;
11-
fn cast_rc_to(self: Rc<Self>) -> Rc<T>;
12-
fn cast_arc_to(self: Arc<Self>) -> Arc<T>;
137
}
148

15-
impl<T: ?Sized> Cast for T {}
16-
pub trait Cast {
17-
fn cast<T: ?Sized>(&self) -> &T
18-
where
19-
Self: CastTo<T>,
20-
{
9+
impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U {
10+
fn cast_to(&self) -> &T {
2111
self
2212
}
13+
}
2314

24-
fn cast_mut<T>(&mut self) -> &mut T
25-
where
26-
Self: CastTo<T>,
27-
{
28-
self.cast_mut_to()
29-
}
30-
31-
fn into_cast<T>(self: Box<Self>) -> Box<T>
32-
where
33-
Self: CastTo<T>,
34-
{
35-
self.into_cast_to()
36-
}
37-
38-
fn cast_rc<T>(self: Rc<Self>) -> Rc<T>
39-
where
40-
Self: CastTo<T>,
41-
{
42-
self.cast_rc_to()
43-
}
44-
45-
fn cast_arc<T>(self: Arc<Self>) -> Arc<T>
15+
impl<T: ?Sized> Cast for T {}
16+
pub trait Cast {
17+
fn cast<T: ?Sized>(&self) -> &T
4618
where
4719
Self: CastTo<T>,
4820
{
49-
self.cast_arc_to()
50-
}
51-
}
52-
impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U {
53-
fn cast_to(&self) -> &T {
54-
self
55-
}
56-
57-
fn cast_mut_to(&mut self) -> &mut T {
58-
self
59-
}
60-
61-
fn into_cast_to(self: Box<Self>) -> Box<T> {
6221
self
6322
}
64-
65-
fn cast_rc_to(self: Rc<Self>) -> Rc<T> {
66-
self
67-
}
68-
69-
fn cast_arc_to(self: Arc<Self>) -> Arc<T> {
70-
self
71-
}
72-
}
73-
74-
pub trait Foo {
75-
fn foo(&self) {
76-
println!("Foo({})", core::any::type_name::<Self>());
77-
}
78-
}
79-
80-
pub trait Bar: CastTo<dyn Foo> + CastTo<dyn core::fmt::Debug> + CastTo<[i32]> {
81-
fn bar(&self) {
82-
println!("Bar({})", core::any::type_name::<Self>());
83-
}
8423
}
8524

86-
impl Foo for [i32; 10] {}
87-
impl Bar for [i32; 10] {}
25+
pub trait Foo: CastTo<[i32]> {}
26+
impl Foo for [i32; 0] {}
8827

8928
fn main() {
90-
let x = [0; 10];
91-
let x: Box<dyn Bar> = Box::new(x);
92-
let x = (*x).cast::<[i32]>();
93-
//~^ ERROR: the trait bound `dyn Bar: CastTo<[i32]>` is not satisfied
29+
let x: &dyn Foo = &[];
30+
let x = x.cast::<[i32]>();
31+
//~^ ERROR: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
9432
}

src/test/ui/unsized/issue-71659.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `dyn Bar: CastTo<[i32]>` is not satisfied
2-
--> $DIR/issue-71659.rs:92:18
1+
error[E0277]: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied
2+
--> $DIR/issue-71659.rs:30:15
33
|
4-
LL | let x = (*x).cast::<[i32]>();
5-
| ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Bar`
4+
LL | let x = x.cast::<[i32]>();
5+
| ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Foo`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)