Skip to content

Commit c6b7e04

Browse files
authored
Rollup merge of rust-lang#71420 - RalfJung:specialization-incomplete, r=matthewjasper
Specialization is unsound As discussed in rust-lang#31844 (comment), it might be a good idea to warn users of specialization that the feature they are using is unsound. I also expanded the "incomplete feature" warning to link the user to the tracking issue.
2 parents c0d3f22 + d1265e7 commit c6b7e04

File tree

123 files changed

+748
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+748
-130
lines changed

src/libcore/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#![feature(raw)]
2020
#![feature(sort_internals)]
2121
#![feature(slice_partition_at_index)]
22-
#![feature(specialization)]
22+
#![feature(min_specialization)]
2323
#![feature(step_trait)]
2424
#![feature(step_trait_ext)]
2525
#![feature(str_internals)]

src/librustc_feature/active.rs

+1
Original file line numberDiff line numberDiff line change
@@ -596,4 +596,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
596596
sym::raw_dylib,
597597
sym::const_trait_impl,
598598
sym::const_trait_bound_opt_out,
599+
sym::specialization,
599600
];

src/test/compile-fail/specialization/issue-50452.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// compile-fail
2-
32
#![feature(specialization)]
3+
//~^ WARN the feature `specialization` is incomplete
44

55
pub trait Foo {
66
fn foo();

src/test/ui/associated-types/defaults-specialization.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests the interaction of associated type defaults and specialization.
22
33
#![feature(associated_type_defaults, specialization)]
4+
//~^ WARN the feature `specialization` is incomplete
45

56
trait Tr {
67
type Ty = u8;

src/test/ui/associated-types/defaults-specialization.stderr

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/defaults-specialization.rs:3:38
3+
|
4+
LL | #![feature(associated_type_defaults, specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
110
error[E0053]: method `make` has an incompatible type for trait
2-
--> $DIR/defaults-specialization.rs:18:18
11+
--> $DIR/defaults-specialization.rs:19:18
312
|
413
LL | fn make() -> Self::Ty {
514
| -------- type in trait
@@ -11,7 +20,7 @@ LL | fn make() -> u8 { 0 }
1120
found fn pointer `fn() -> u8`
1221

1322
error[E0053]: method `make` has an incompatible type for trait
14-
--> $DIR/defaults-specialization.rs:34:18
23+
--> $DIR/defaults-specialization.rs:35:18
1524
|
1625
LL | fn make() -> Self::Ty {
1726
| -------- type in trait
@@ -26,7 +35,7 @@ LL | fn make() -> bool { true }
2635
found fn pointer `fn() -> bool`
2736

2837
error[E0308]: mismatched types
29-
--> $DIR/defaults-specialization.rs:9:9
38+
--> $DIR/defaults-specialization.rs:10:9
3039
|
3140
LL | type Ty = u8;
3241
| ------------- associated type defaults can't be assumed inside the trait defining them
@@ -40,7 +49,7 @@ LL | 0u8
4049
found type `u8`
4150

4251
error[E0308]: mismatched types
43-
--> $DIR/defaults-specialization.rs:25:29
52+
--> $DIR/defaults-specialization.rs:26:29
4453
|
4554
LL | fn make() -> Self::Ty { 0u8 }
4655
| -------- ^^^ expected associated type, found `u8`
@@ -53,7 +62,7 @@ LL | fn make() -> Self::Ty { 0u8 }
5362
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
5463

5564
error[E0308]: mismatched types
56-
--> $DIR/defaults-specialization.rs:43:29
65+
--> $DIR/defaults-specialization.rs:44:29
5766
|
5867
LL | default type Ty = bool;
5968
| ----------------------- expected this associated type
@@ -67,7 +76,7 @@ LL | fn make() -> Self::Ty { true }
6776
found type `bool`
6877

6978
error[E0308]: mismatched types
70-
--> $DIR/defaults-specialization.rs:86:32
79+
--> $DIR/defaults-specialization.rs:87:32
7180
|
7281
LL | let _: <B<()> as Tr>::Ty = 0u8;
7382
| ----------------- ^^^ expected associated type, found `u8`
@@ -77,13 +86,13 @@ LL | let _: <B<()> as Tr>::Ty = 0u8;
7786
= note: expected associated type `<B<()> as Tr>::Ty`
7887
found type `u8`
7988
help: a method is available that returns `<B<()> as Tr>::Ty`
80-
--> $DIR/defaults-specialization.rs:8:5
89+
--> $DIR/defaults-specialization.rs:9:5
8190
|
8291
LL | fn make() -> Self::Ty {
8392
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`
8493

8594
error[E0308]: mismatched types
86-
--> $DIR/defaults-specialization.rs:87:32
95+
--> $DIR/defaults-specialization.rs:88:32
8796
|
8897
LL | let _: <B<()> as Tr>::Ty = true;
8998
| ----------------- ^^^^ expected associated type, found `bool`
@@ -93,13 +102,13 @@ LL | let _: <B<()> as Tr>::Ty = true;
93102
= note: expected associated type `<B<()> as Tr>::Ty`
94103
found type `bool`
95104
help: a method is available that returns `<B<()> as Tr>::Ty`
96-
--> $DIR/defaults-specialization.rs:8:5
105+
--> $DIR/defaults-specialization.rs:9:5
97106
|
98107
LL | fn make() -> Self::Ty {
99108
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`
100109

101110
error[E0308]: mismatched types
102-
--> $DIR/defaults-specialization.rs:88:33
111+
--> $DIR/defaults-specialization.rs:89:33
103112
|
104113
LL | let _: <B2<()> as Tr>::Ty = 0u8;
105114
| ------------------ ^^^ expected associated type, found `u8`
@@ -109,13 +118,13 @@ LL | let _: <B2<()> as Tr>::Ty = 0u8;
109118
= note: expected associated type `<B2<()> as Tr>::Ty`
110119
found type `u8`
111120
help: a method is available that returns `<B2<()> as Tr>::Ty`
112-
--> $DIR/defaults-specialization.rs:8:5
121+
--> $DIR/defaults-specialization.rs:9:5
113122
|
114123
LL | fn make() -> Self::Ty {
115124
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`
116125

117126
error[E0308]: mismatched types
118-
--> $DIR/defaults-specialization.rs:89:33
127+
--> $DIR/defaults-specialization.rs:90:33
119128
|
120129
LL | let _: <B2<()> as Tr>::Ty = true;
121130
| ------------------ ^^^^ expected associated type, found `bool`
@@ -125,12 +134,12 @@ LL | let _: <B2<()> as Tr>::Ty = true;
125134
= note: expected associated type `<B2<()> as Tr>::Ty`
126135
found type `bool`
127136
help: a method is available that returns `<B2<()> as Tr>::Ty`
128-
--> $DIR/defaults-specialization.rs:8:5
137+
--> $DIR/defaults-specialization.rs:9:5
129138
|
130139
LL | fn make() -> Self::Ty {
131140
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`
132141

133-
error: aborting due to 9 previous errors
142+
error: aborting due to 9 previous errors; 1 warning emitted
134143

135144
Some errors have detailed explanations: E0053, E0308.
136145
For more information about an error, try `rustc --explain E0053`.

src/test/ui/coherence/coherence-inherited-assoc-ty-cycle-err.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55
// No we expect to run into a more user-friendly cycle error instead.
66
#![feature(specialization)]
7+
//~^ WARN the feature `specialization` is incomplete
78

89
trait Trait<T> { type Assoc; }
910
//~^ ERROR E0391
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:6:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
110
error[E0391]: cycle detected when building specialization graph of trait `Trait`
2-
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:8:1
11+
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:9:1
312
|
413
LL | trait Trait<T> { type Assoc; }
514
| ^^^^^^^^^^^^^^
615
|
716
= note: ...which again requires building specialization graph of trait `Trait`, completing the cycle
817
note: cycle used when coherence checking all impls of trait `Trait`
9-
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:8:1
18+
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:9:1
1019
|
1120
LL | trait Trait<T> { type Assoc; }
1221
| ^^^^^^^^^^^^^^
1322

14-
error: aborting due to previous error
23+
error: aborting due to previous error; 1 warning emitted
1524

1625
For more information about this error, try `rustc --explain E0391`.

src/test/ui/consts/trait_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Tests that specialization does not cause optimizations running on polymorphic MIR to resolve
66
// to a `default` implementation.
77

8-
#![feature(specialization)]
8+
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete
99

1010
trait Marker {}
1111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/trait_specialization.rs:8:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
10+
warning: 1 warning emitted
11+

src/test/ui/error-codes/E0520.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(specialization)]
2+
//~^ WARN the feature `specialization` is incomplete
23

34
trait SpaceLlama {
45
fn fly(&self);

src/test/ui/error-codes/E0520.stderr

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/E0520.rs:1:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
110
error[E0520]: `fly` specializes an item from a parent `impl`, but that item is not marked `default`
2-
--> $DIR/E0520.rs:16:5
11+
--> $DIR/E0520.rs:17:5
312
|
413
LL | / impl<T: Clone> SpaceLlama for T {
514
LL | | fn fly(&self) {}
@@ -11,6 +20,6 @@ LL | default fn fly(&self) {}
1120
|
1221
= note: to specialize, `fly` in the parent `impl` must be marked `default`
1322

14-
error: aborting due to previous error
23+
error: aborting due to previous error; 1 warning emitted
1524

1625
For more information about this error, try `rustc --explain E0520`.

src/test/ui/impl-trait/equality-rpass.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
#![feature(specialization)]
3+
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete
44

55
trait Foo: std::fmt::Debug + Eq {}
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/equality-rpass.rs:3:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
10+
warning: 1 warning emitted
11+

src/test/ui/impl-trait/equality.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(specialization)]
1+
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete
22

33
trait Foo: Copy + ToString {}
44

src/test/ui/impl-trait/equality.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/equality.rs:1:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
110
error[E0308]: mismatched types
211
--> $DIR/equality.rs:15:5
312
|
@@ -24,7 +33,7 @@ LL | n + sum_to(n - 1)
2433
|
2534
= help: the trait `std::ops::Add<impl Foo>` is not implemented for `u32`
2635

27-
error: aborting due to 2 previous errors
36+
error: aborting due to 2 previous errors; 1 warning emitted
2837

2938
Some errors have detailed explanations: E0277, E0308.
3039
For more information about an error, try `rustc --explain E0277`.

src/test/ui/impl-trait/equality2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(specialization)]
1+
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete
22

33
trait Foo: Copy + ToString {}
44

src/test/ui/impl-trait/equality2.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/equality2.rs:1:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
110
error[E0308]: mismatched types
211
--> $DIR/equality2.rs:25:18
312
|
@@ -58,6 +67,6 @@ LL | x.0);
5867
= note: expected opaque type `impl Foo` (`i32`)
5968
found opaque type `impl Foo` (`u32`)
6069

61-
error: aborting due to 4 previous errors
70+
error: aborting due to 4 previous errors; 1 warning emitted
6271

6372
For more information about this error, try `rustc --explain E0308`.

src/test/ui/issues/issue-35376.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// check-pass
22
#![feature(specialization)]
3+
//~^ WARN the feature `specialization` is incomplete
34

45
fn main() {}
56

src/test/ui/issues/issue-35376.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-35376.rs:2:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
10+
warning: 1 warning emitted
11+

src/test/ui/issues/issue-38091.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-pass
22
#![feature(specialization)]
3+
//~^ WARN the feature `specialization` is incomplete
34

45
trait Iterate<'a> {
56
type Ty: Valid;

src/test/ui/issues/issue-38091.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-38091.rs:2:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
10+
warning: 1 warning emitted
11+

src/test/ui/issues/issue-55380.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
2-
32
#![feature(specialization)]
3+
//~^ WARN the feature `specialization` is incomplete
44

55
pub trait Foo {
66
fn abc() -> u32;

src/test/ui/issues/issue-55380.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-55380.rs:2:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
10+
warning: 1 warning emitted
11+

src/test/ui/overlap-doesnt-conflict-with-specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
22

33
#![feature(marker_trait_attr)]
4-
#![feature(specialization)]
4+
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete
55

66
#[marker]
77
trait MyMarker {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/overlap-doesnt-conflict-with-specialization.rs:4:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)