Skip to content

Commit 3cb625e

Browse files
committed
Various adjustments to historic tests and documents.
1 parent a144333 commit 3cb625e

File tree

11 files changed

+334
-198
lines changed

11 files changed

+334
-198
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# `trait_upcasting`
22

3-
The tracking issue for this feature is: [#31436]
3+
The tracking issue for this feature is: [#65991]
44

55
[#65991]: https://github.com/rust-lang/rust/issues/65991
66

77
------------------------
88

9-
The `trait_upcasting` feature adds support for trait upcasting. This allows a
10-
trait object of type `dyn Foo` to be cast to a trait object of type `dyn Bar`
11-
so long as `Foo: Bar`.
9+
The `trait_upcasting` feature adds support for trait upcasting coercion. This allows a
10+
trait object of type `dyn Bar` to be cast to a trait object of type `dyn Foo`
11+
so long as `Bar: Foo`.
1212

1313
```rust,edition2018
1414
#![feature(trait_upcasting)]
15+
#![allow(incomplete_features)]
1516
1617
trait Foo {}
1718
@@ -21,6 +22,6 @@ impl Foo for i32 {}
2122
2223
impl<T: Foo + ?Sized> Bar for T {}
2324
24-
let foo: &dyn Foo = &123;
25-
let bar: &dyn Bar = foo;
25+
let bar: &dyn Bar = &123;
26+
let foo: &dyn Foo = bar;
2627
```

src/test/ui/traits/trait-upcasting/basic.rs

+28-21
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
11
// run-pass
22

33
#![feature(trait_upcasting)]
4+
#![allow(incomplete_features)]
45

56
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
6-
fn a(&self) -> i32 { 10 }
7+
fn a(&self) -> i32 {
8+
10
9+
}
710

8-
fn z(&self) -> i32 { 11 }
11+
fn z(&self) -> i32 {
12+
11
13+
}
914

10-
fn y(&self) -> i32 { 12 }
15+
fn y(&self) -> i32 {
16+
12
17+
}
1118
}
1219

1320
trait Bar: Foo {
14-
fn b(&self) -> i32 { 20 }
21+
fn b(&self) -> i32 {
22+
20
23+
}
1524

16-
fn w(&self) -> i32 { 21 }
25+
fn w(&self) -> i32 {
26+
21
27+
}
1728
}
1829

1930
trait Baz: Bar {
20-
fn c(&self) -> i32 { 30 }
31+
fn c(&self) -> i32 {
32+
30
33+
}
2134
}
2235

2336
impl Foo for i32 {
24-
fn a(&self) -> i32 { 100 }
37+
fn a(&self) -> i32 {
38+
100
39+
}
2540
}
2641

2742
impl Bar for i32 {
28-
fn b(&self) -> i32 { 200 }
43+
fn b(&self) -> i32 {
44+
200
45+
}
2946
}
3047

3148
impl Baz for i32 {
32-
fn c(&self) -> i32 { 300 }
49+
fn c(&self) -> i32 {
50+
300
51+
}
3352
}
3453

3554
fn main() {
3655
let baz: &dyn Baz = &1;
3756
let _: &dyn std::fmt::Debug = baz;
38-
let _: &(dyn Send + Sync) = baz;
39-
let _: &dyn Send = baz;
40-
let _: &dyn Sync = baz;
4157
assert_eq!(*baz, 1);
4258
assert_eq!(baz.a(), 100);
4359
assert_eq!(baz.b(), 200);
@@ -48,9 +64,6 @@ fn main() {
4864

4965
let bar: &dyn Bar = baz;
5066
let _: &dyn std::fmt::Debug = bar;
51-
let _: &(dyn Send + Sync) = bar;
52-
let _: &dyn Send = bar;
53-
let _: &dyn Sync = bar;
5467
assert_eq!(*bar, 1);
5568
assert_eq!(bar.a(), 100);
5669
assert_eq!(bar.b(), 200);
@@ -60,19 +73,13 @@ fn main() {
6073

6174
let foo: &dyn Foo = baz;
6275
let _: &dyn std::fmt::Debug = foo;
63-
let _: &(dyn Send + Sync) = foo;
64-
let _: &dyn Send = foo;
65-
let _: &dyn Sync = foo;
6676
assert_eq!(*foo, 1);
6777
assert_eq!(foo.a(), 100);
6878
assert_eq!(foo.z(), 11);
6979
assert_eq!(foo.y(), 12);
7080

7181
let foo: &dyn Foo = bar;
7282
let _: &dyn std::fmt::Debug = foo;
73-
let _: &(dyn Send + Sync) = foo;
74-
let _: &dyn Send = foo;
75-
let _: &dyn Sync = foo;
7683
assert_eq!(*foo, 1);
7784
assert_eq!(foo.a(), 100);
7885
assert_eq!(foo.z(), 11);

src/test/ui/traits/trait-upcasting/cyclic-trait-resolution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
trait A: B + A {}
2-
//~^ ERROR cycle detected when computing the supertraits of `A` [E0391]
2+
//~^ ERROR cycle detected when computing the super predicates of `A` [E0391]
33

44
trait B {}
55

src/test/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
error[E0391]: cycle detected when computing the supertraits of `A`
1+
error[E0391]: cycle detected when computing the super predicates of `A`
2+
--> $DIR/cyclic-trait-resolution.rs:1:1
3+
|
4+
LL | trait A: B + A {}
5+
| ^^^^^^^^^^^^^^
6+
|
7+
note: ...which requires computing the super traits of `A`...
28
--> $DIR/cyclic-trait-resolution.rs:1:14
39
|
410
LL | trait A: B + A {}
511
| ^
6-
|
7-
= note: ...which again requires computing the supertraits of `A`, completing the cycle
12+
= note: ...which again requires computing the super predicates of `A`, completing the cycle
813
note: cycle used when collecting item types in top-level module
914
--> $DIR/cyclic-trait-resolution.rs:1:1
1015
|
+37-30
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,75 @@
11
// run-pass
22

33
#![feature(trait_upcasting)]
4+
#![allow(incomplete_features)]
45

56
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
6-
fn a(&self) -> i32 { 10 }
7+
fn a(&self) -> i32 {
8+
10
9+
}
710

8-
fn z(&self) -> i32 { 11 }
11+
fn z(&self) -> i32 {
12+
11
13+
}
914

10-
fn y(&self) -> i32 { 12 }
15+
fn y(&self) -> i32 {
16+
12
17+
}
1118
}
1219

1320
trait Bar1: Foo {
14-
fn b(&self) -> i32 { 20 }
21+
fn b(&self) -> i32 {
22+
20
23+
}
1524

16-
fn w(&self) -> i32 { 21 }
25+
fn w(&self) -> i32 {
26+
21
27+
}
1728
}
1829

1930
trait Bar2: Foo {
20-
fn c(&self) -> i32 { 30 }
31+
fn c(&self) -> i32 {
32+
30
33+
}
2134

22-
fn v(&self) -> i32 { 31 }
35+
fn v(&self) -> i32 {
36+
31
37+
}
2338
}
2439

2540
trait Baz: Bar1 + Bar2 {
26-
fn d(&self) -> i32 { 40 }
41+
fn d(&self) -> i32 {
42+
40
43+
}
2744
}
2845

2946
impl Foo for i32 {
30-
fn a(&self) -> i32 { 100 }
47+
fn a(&self) -> i32 {
48+
100
49+
}
3150
}
3251

3352
impl Bar1 for i32 {
34-
fn b(&self) -> i32 { 200 }
53+
fn b(&self) -> i32 {
54+
200
55+
}
3556
}
3657

3758
impl Bar2 for i32 {
38-
fn c(&self) -> i32 { 300 }
59+
fn c(&self) -> i32 {
60+
300
61+
}
3962
}
4063

4164
impl Baz for i32 {
42-
fn d(&self) -> i32 { 400 }
65+
fn d(&self) -> i32 {
66+
400
67+
}
4368
}
4469

4570
fn main() {
4671
let baz: &dyn Baz = &1;
4772
let _: &dyn std::fmt::Debug = baz;
48-
let _: &(dyn Send + Sync) = baz;
49-
let _: &dyn Send = baz;
50-
let _: &dyn Sync = baz;
5173
assert_eq!(*baz, 1);
5274
assert_eq!(baz.a(), 100);
5375
assert_eq!(baz.b(), 200);
@@ -60,9 +82,6 @@ fn main() {
6082

6183
let bar1: &dyn Bar1 = baz;
6284
let _: &dyn std::fmt::Debug = bar1;
63-
let _: &(dyn Send + Sync) = bar1;
64-
let _: &dyn Send = bar1;
65-
let _: &dyn Sync = bar1;
6685
assert_eq!(*bar1, 1);
6786
assert_eq!(bar1.a(), 100);
6887
assert_eq!(bar1.b(), 200);
@@ -72,9 +91,6 @@ fn main() {
7291

7392
let bar2: &dyn Bar2 = baz;
7493
let _: &dyn std::fmt::Debug = bar2;
75-
let _: &(dyn Send + Sync) = bar2;
76-
let _: &dyn Send = bar2;
77-
let _: &dyn Sync = bar2;
7894
assert_eq!(*bar2, 1);
7995
assert_eq!(bar2.a(), 100);
8096
assert_eq!(bar2.c(), 300);
@@ -84,25 +100,16 @@ fn main() {
84100

85101
let foo: &dyn Foo = baz;
86102
let _: &dyn std::fmt::Debug = foo;
87-
let _: &(dyn Send + Sync) = foo;
88-
let _: &dyn Send = foo;
89-
let _: &dyn Sync = foo;
90103
assert_eq!(*foo, 1);
91104
assert_eq!(foo.a(), 100);
92105

93106
let foo: &dyn Foo = bar1;
94107
let _: &dyn std::fmt::Debug = foo;
95-
let _: &(dyn Send + Sync) = foo;
96-
let _: &dyn Send = foo;
97-
let _: &dyn Sync = foo;
98108
assert_eq!(*foo, 1);
99109
assert_eq!(foo.a(), 100);
100110

101111
let foo: &dyn Foo = bar2;
102112
let _: &dyn std::fmt::Debug = foo;
103-
let _: &(dyn Send + Sync) = foo;
104-
let _: &dyn Send = foo;
105-
let _: &dyn Sync = foo;
106113
assert_eq!(*foo, 1);
107114
assert_eq!(foo.a(), 100);
108115
}

0 commit comments

Comments
 (0)