-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #133325 - compiler-errors:const-spec, r=lcnr,fee1-dead
Reimplement `~const` trait specialization Reimplement const specialization. We need this for `PartialEq` constification :) r? lcnr
- Loading branch information
Showing
14 changed files
with
274 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/traits/const-traits/overlap-const-with-nonconst.min_spec.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0119]: conflicting implementations of trait `Foo` for type `(_,)` | ||
--> $DIR/overlap-const-with-nonconst.rs:23:1 | ||
| | ||
LL | / impl<T> const Foo for T | ||
LL | | where | ||
LL | | T: ~const Bar, | ||
| |__________________- first implementation here | ||
... | ||
LL | impl<T> Foo for (T,) { | ||
| ^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(_,)` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
38 changes: 38 additions & 0 deletions
38
tests/ui/traits/const-traits/overlap-const-with-nonconst.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//@ revisions: spec min_spec | ||
|
||
#![feature(const_trait_impl)] | ||
#![cfg_attr(spec, feature(specialization))] | ||
//[spec]~^ WARN the feature `specialization` is incomplete | ||
#![cfg_attr(min_spec, feature(min_specialization))] | ||
|
||
#[const_trait] | ||
trait Bar {} | ||
impl<T> const Bar for T {} | ||
|
||
#[const_trait] | ||
trait Foo { | ||
fn method(&self); | ||
} | ||
impl<T> const Foo for T | ||
where | ||
T: ~const Bar, | ||
{ | ||
default fn method(&self) {} | ||
} | ||
// specializing impl: | ||
impl<T> Foo for (T,) { | ||
//~^ ERROR conflicting implementations | ||
fn method(&self) { | ||
println!("hi"); | ||
} | ||
} | ||
|
||
const fn dispatch<T: ~const Bar + Copy>(t: T) { | ||
t.method(); | ||
} | ||
|
||
fn main() { | ||
const { | ||
dispatch(((),)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/ui/traits/const-traits/overlap-const-with-nonconst.spec.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/overlap-const-with-nonconst.rs:4:27 | ||
| | ||
LL | #![cfg_attr(spec, feature(specialization))] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information | ||
= help: consider using `min_specialization` instead, which is more stable and complete | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0119]: conflicting implementations of trait `Foo` for type `(_,)` | ||
--> $DIR/overlap-const-with-nonconst.rs:23:1 | ||
| | ||
LL | / impl<T> const Foo for T | ||
LL | | where | ||
LL | | T: ~const Bar, | ||
| |__________________- first implementation here | ||
... | ||
LL | impl<T> Foo for (T,) { | ||
| ^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(_,)` | ||
|
||
error: aborting due to 1 previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
26 changes: 23 additions & 3 deletions
26
...traits/const-traits/specialization/const-default-bound-non-const-specialized-bound.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
error: cannot specialize on const impl with non-const impl | ||
error[E0119]: conflicting implementations of trait `Bar` | ||
--> $DIR/const-default-bound-non-const-specialized-bound.rs:28:1 | ||
| | ||
LL | / impl<T> const Bar for T | ||
LL | | where | ||
LL | | T: ~const Foo, | ||
| |__________________- first implementation here | ||
... | ||
LL | / impl<T> Bar for T | ||
LL | | where | ||
LL | | T: Foo, //FIXME ~ ERROR missing `~const` qualifier | ||
LL | | T: Specialize, | ||
| |__________________^ | ||
| |__________________^ conflicting implementation | ||
|
||
error[E0119]: conflicting implementations of trait `Baz` | ||
--> $DIR/const-default-bound-non-const-specialized-bound.rs:48:1 | ||
| | ||
LL | / impl<T> const Baz for T | ||
LL | | where | ||
LL | | T: ~const Foo, | ||
| |__________________- first implementation here | ||
... | ||
LL | / impl<T> const Baz for T //FIXME ~ ERROR conflicting implementations of trait `Baz` | ||
LL | | where | ||
LL | | T: Foo, | ||
LL | | T: Specialize, | ||
| |__________________^ conflicting implementation | ||
|
||
error: aborting due to 1 previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
12 changes: 12 additions & 0 deletions
12
...const-traits/specialization/const-default-impl-non-const-specialized-impl.min_spec.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0119]: conflicting implementations of trait `Value` for type `FortyTwo` | ||
--> $DIR/const-default-impl-non-const-specialized-impl.rs:22:1 | ||
| | ||
LL | impl<T> const Value for T { | ||
| ------------------------- first implementation here | ||
... | ||
LL | impl Value for FortyTwo { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `FortyTwo` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
Oops, something went wrong.