Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialization is unsound #71420

Merged
merged 3 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![feature(raw)]
#![feature(sort_internals)]
#![feature(slice_partition_at_index)]
#![feature(specialization)]
#![feature(min_specialization)]
#![feature(step_trait)]
#![feature(step_trait_ext)]
#![feature(str_internals)]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::raw_dylib,
sym::const_trait_impl,
sym::const_trait_bound_opt_out,
sym::specialization,
];
2 changes: 1 addition & 1 deletion src/test/compile-fail/specialization/issue-50452.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// compile-fail

#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

pub trait Foo {
fn foo();
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/associated-types/defaults-specialization.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Tests the interaction of associated type defaults and specialization.

#![feature(associated_type_defaults, specialization)]
//~^ WARN the feature `specialization` is incomplete

trait Tr {
type Ty = u8;
Expand Down
37 changes: 23 additions & 14 deletions src/test/ui/associated-types/defaults-specialization.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/defaults-specialization.rs:3:38
|
LL | #![feature(associated_type_defaults, specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

error[E0053]: method `make` has an incompatible type for trait
--> $DIR/defaults-specialization.rs:18:18
--> $DIR/defaults-specialization.rs:19:18
|
LL | fn make() -> Self::Ty {
| -------- type in trait
Expand All @@ -11,7 +20,7 @@ LL | fn make() -> u8 { 0 }
found fn pointer `fn() -> u8`

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

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

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

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

error[E0308]: mismatched types
--> $DIR/defaults-specialization.rs:86:32
--> $DIR/defaults-specialization.rs:87:32
|
LL | let _: <B<()> as Tr>::Ty = 0u8;
| ----------------- ^^^ expected associated type, found `u8`
Expand All @@ -77,13 +86,13 @@ LL | let _: <B<()> as Tr>::Ty = 0u8;
= note: expected associated type `<B<()> as Tr>::Ty`
found type `u8`
help: a method is available that returns `<B<()> as Tr>::Ty`
--> $DIR/defaults-specialization.rs:8:5
--> $DIR/defaults-specialization.rs:9:5
|
LL | fn make() -> Self::Ty {
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`

error[E0308]: mismatched types
--> $DIR/defaults-specialization.rs:87:32
--> $DIR/defaults-specialization.rs:88:32
|
LL | let _: <B<()> as Tr>::Ty = true;
| ----------------- ^^^^ expected associated type, found `bool`
Expand All @@ -93,13 +102,13 @@ LL | let _: <B<()> as Tr>::Ty = true;
= note: expected associated type `<B<()> as Tr>::Ty`
found type `bool`
help: a method is available that returns `<B<()> as Tr>::Ty`
--> $DIR/defaults-specialization.rs:8:5
--> $DIR/defaults-specialization.rs:9:5
|
LL | fn make() -> Self::Ty {
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`

error[E0308]: mismatched types
--> $DIR/defaults-specialization.rs:88:33
--> $DIR/defaults-specialization.rs:89:33
|
LL | let _: <B2<()> as Tr>::Ty = 0u8;
| ------------------ ^^^ expected associated type, found `u8`
Expand All @@ -109,13 +118,13 @@ LL | let _: <B2<()> as Tr>::Ty = 0u8;
= note: expected associated type `<B2<()> as Tr>::Ty`
found type `u8`
help: a method is available that returns `<B2<()> as Tr>::Ty`
--> $DIR/defaults-specialization.rs:8:5
--> $DIR/defaults-specialization.rs:9:5
|
LL | fn make() -> Self::Ty {
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`

error[E0308]: mismatched types
--> $DIR/defaults-specialization.rs:89:33
--> $DIR/defaults-specialization.rs:90:33
|
LL | let _: <B2<()> as Tr>::Ty = true;
| ------------------ ^^^^ expected associated type, found `bool`
Expand All @@ -125,12 +134,12 @@ LL | let _: <B2<()> as Tr>::Ty = true;
= note: expected associated type `<B2<()> as Tr>::Ty`
found type `bool`
help: a method is available that returns `<B2<()> as Tr>::Ty`
--> $DIR/defaults-specialization.rs:8:5
--> $DIR/defaults-specialization.rs:9:5
|
LL | fn make() -> Self::Ty {
| ^^^^^^^^^^^^^^^^^^^^^ consider calling `Tr::make`

error: aborting due to 9 previous errors
error: aborting due to 9 previous errors; 1 warning emitted

Some errors have detailed explanations: E0053, E0308.
For more information about an error, try `rustc --explain E0053`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// No we expect to run into a more user-friendly cycle error instead.
#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

trait Trait<T> { type Assoc; }
//~^ ERROR E0391
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:6:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

error[E0391]: cycle detected when building specialization graph of trait `Trait`
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:8:1
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:9:1
|
LL | trait Trait<T> { type Assoc; }
| ^^^^^^^^^^^^^^
|
= note: ...which again requires building specialization graph of trait `Trait`, completing the cycle
note: cycle used when coherence checking all impls of trait `Trait`
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:8:1
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:9:1
|
LL | trait Trait<T> { type Assoc; }
| ^^^^^^^^^^^^^^

error: aborting due to previous error
error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0391`.
2 changes: 1 addition & 1 deletion src/test/ui/consts/trait_specialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Tests that specialization does not cause optimizations running on polymorphic MIR to resolve
// to a `default` implementation.

#![feature(specialization)]
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete

trait Marker {}

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/consts/trait_specialization.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/trait_specialization.rs:8:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

warning: 1 warning emitted

1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0520.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

trait SpaceLlama {
fn fly(&self);
Expand Down
13 changes: 11 additions & 2 deletions src/test/ui/error-codes/E0520.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/E0520.rs:1:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

error[E0520]: `fly` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/E0520.rs:16:5
--> $DIR/E0520.rs:17:5
|
LL | / impl<T: Clone> SpaceLlama for T {
LL | | fn fly(&self) {}
Expand All @@ -11,6 +20,6 @@ LL | default fn fly(&self) {}
|
= note: to specialize, `fly` in the parent `impl` must be marked `default`

error: aborting due to previous error
error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0520`.
2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/equality-rpass.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// run-pass

#![feature(specialization)]
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete

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

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/impl-trait/equality-rpass.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/equality-rpass.rs:3:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/equality.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(specialization)]
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete

trait Foo: Copy + ToString {}

Expand Down
11 changes: 10 additions & 1 deletion src/test/ui/impl-trait/equality.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/equality.rs:1:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

error[E0308]: mismatched types
--> $DIR/equality.rs:15:5
|
Expand All @@ -24,7 +33,7 @@ LL | n + sum_to(n - 1)
|
= help: the trait `std::ops::Add<impl Foo>` is not implemented for `u32`

error: aborting due to 2 previous errors
error: aborting due to 2 previous errors; 1 warning emitted

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/equality2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(specialization)]
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete

trait Foo: Copy + ToString {}

Expand Down
11 changes: 10 additions & 1 deletion src/test/ui/impl-trait/equality2.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/equality2.rs:1:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

error[E0308]: mismatched types
--> $DIR/equality2.rs:25:18
|
Expand Down Expand Up @@ -58,6 +67,6 @@ LL | x.0);
= note: expected opaque type `impl Foo` (`i32`)
found opaque type `impl Foo` (`u32`)

error: aborting due to 4 previous errors
error: aborting due to 4 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0308`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-35376.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// check-pass
#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

fn main() {}

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-35376.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-35376.rs:2:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

warning: 1 warning emitted

1 change: 1 addition & 0 deletions src/test/ui/issues/issue-38091.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// run-pass
#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

trait Iterate<'a> {
type Ty: Valid;
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-38091.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-38091.rs:2:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-55380.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// run-pass

#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

pub trait Foo {
fn abc() -> u32;
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-55380.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-55380.rs:2:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion src/test/ui/overlap-doesnt-conflict-with-specialization.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// run-pass

#![feature(marker_trait_attr)]
#![feature(specialization)]
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete

#[marker]
trait MyMarker {}
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/overlap-doesnt-conflict-with-specialization.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/overlap-doesnt-conflict-with-specialization.rs:4:12
|
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information

warning: 1 warning emitted

Loading