-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add Self: ~const Trait
to traits with #[const_trait]
#99704
Merged
bors
merged 4 commits into
rust-lang:master
from
fee1-dead-contrib:add_self_tilde_const_trait
Jul 27, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,29 @@ | ||
error: overly complex generic constant | ||
--> $DIR/issue-90318.rs:14:8 | ||
error[E0277]: can't compare `TypeId` with `_` in const contexts | ||
--> $DIR/issue-90318.rs:14:28 | ||
| | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, | ||
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| borrowing is not supported in generic constants | ||
| ^^ no implementation for `TypeId == _` | ||
| | ||
= help: consider moving this anonymous constant into a `const` function | ||
= note: this operation may be supported in the future | ||
|
||
error[E0015]: cannot call non-const operator in constants | ||
--> $DIR/issue-90318.rs:14:10 | ||
= help: the trait `~const PartialEq<_>` is not implemented for `TypeId` | ||
note: the trait `PartialEq<_>` is implemented for `TypeId`, but that implementation is not `const` | ||
--> $DIR/issue-90318.rs:14:28 | ||
| | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: impl defined here, but it is not `const` | ||
--> $SRC_DIR/core/src/any.rs:LL:COL | ||
| | ||
LL | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] | ||
| ^^^^^^^^^ | ||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| ^^ | ||
|
||
error: overly complex generic constant | ||
--> $DIR/issue-90318.rs:22:8 | ||
error[E0277]: can't compare `TypeId` with `_` in const contexts | ||
--> $DIR/issue-90318.rs:21:28 | ||
| | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, | ||
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| borrowing is not supported in generic constants | ||
| ^^ no implementation for `TypeId == _` | ||
| | ||
= help: consider moving this anonymous constant into a `const` function | ||
= note: this operation may be supported in the future | ||
|
||
error[E0015]: cannot call non-const operator in constants | ||
--> $DIR/issue-90318.rs:22:10 | ||
= help: the trait `~const PartialEq<_>` is not implemented for `TypeId` | ||
note: the trait `PartialEq<_>` is implemented for `TypeId`, but that implementation is not `const` | ||
--> $DIR/issue-90318.rs:21:28 | ||
| | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: impl defined here, but it is not `const` | ||
--> $SRC_DIR/core/src/any.rs:LL:COL | ||
| | ||
LL | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] | ||
| ^^^^^^^^^ | ||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
| ^^ | ||
|
||
error: aborting due to 4 previous errors | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0015`. | ||
For more information about this error, try `rustc --explain E0277`. |
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,6 +1,6 @@ | ||
fn main() {} | ||
|
||
// unconst and bad, will thus error in miri | ||
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR cannot be reliably | ||
const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; //~ ERROR can't compare | ||
// unconst and bad, will thus error in miri | ||
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR cannot be reliably | ||
const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; //~ ERROR can't compare |
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,18 +1,49 @@ | ||
error: pointers cannot be reliably compared during const eval | ||
--> $DIR/const_raw_ptr_ops.rs:4:26 | ||
error[E0277]: can't compare `*const i32` with `_` in const contexts | ||
--> $DIR/const_raw_ptr_ops.rs:4:43 | ||
| | ||
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^^ no implementation for `*const i32 == _` | ||
| | ||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information | ||
= help: the trait `~const PartialEq<_>` is not implemented for `*const i32` | ||
note: the trait `PartialEq<_>` is implemented for `*const i32`, but that implementation is not `const` | ||
--> $DIR/const_raw_ptr_ops.rs:4:43 | ||
| | ||
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 }; | ||
| ^^ | ||
= help: the following other types implement trait `PartialEq<Rhs>`: | ||
f32 | ||
f64 | ||
i128 | ||
i16 | ||
i32 | ||
i64 | ||
i8 | ||
isize | ||
and 6 others | ||
|
||
error: pointers cannot be reliably compared during const eval | ||
--> $DIR/const_raw_ptr_ops.rs:6:27 | ||
error[E0277]: can't compare `*const i32` with `_` in const contexts | ||
--> $DIR/const_raw_ptr_ops.rs:6:44 | ||
| | ||
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^^ no implementation for `*const i32 == _` | ||
| | ||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information | ||
= help: the trait `~const PartialEq<_>` is not implemented for `*const i32` | ||
note: the trait `PartialEq<_>` is implemented for `*const i32`, but that implementation is not `const` | ||
--> $DIR/const_raw_ptr_ops.rs:6:44 | ||
| | ||
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 }; | ||
| ^^ | ||
= help: the following other types implement trait `PartialEq<Rhs>`: | ||
f32 | ||
f64 | ||
i128 | ||
i16 | ||
i32 | ||
i64 | ||
i8 | ||
isize | ||
and 6 others | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,6 +1,6 @@ | ||
fn id<T>(t: T) -> T { t } | ||
fn main() { | ||
const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () }; | ||
//~^ ERROR pointers cannot be reliably compared during const eval | ||
//~^ ERROR can't compare | ||
println!("{}", A); | ||
} |
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,10 +1,20 @@ | ||
error: pointers cannot be reliably compared during const eval | ||
--> $DIR/issue-25826.rs:3:30 | ||
error[E0277]: can't compare `*const ()` with `*const ()` in const contexts | ||
--> $DIR/issue-25826.rs:3:52 | ||
| | ||
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^ no implementation for `*const () < *const ()` and `*const () > *const ()` | ||
| | ||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information | ||
= help: the trait `~const PartialOrd` is not implemented for `*const ()` | ||
note: the trait `PartialOrd` is implemented for `*const ()`, but that implementation is not `const` | ||
--> $DIR/issue-25826.rs:3:52 | ||
| | ||
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () }; | ||
| ^ | ||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | ||
| | ||
LL | fn main() where *const (): ~const PartialOrd { | ||
| ++++++++++++++++++++++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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,6 +1,6 @@ | ||
const fn cmp(x: fn(), y: fn()) -> bool { | ||
unsafe { x == y } | ||
//~^ ERROR pointers cannot be reliably compared | ||
//~^ ERROR can't compare | ||
} | ||
|
||
fn main() {} |
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,10 +1,16 @@ | ||
error: pointers cannot be reliably compared during const eval | ||
--> $DIR/cmp_fn_pointers.rs:2:14 | ||
error[E0277]: can't compare `fn()` with `_` in const contexts | ||
--> $DIR/cmp_fn_pointers.rs:2:16 | ||
| | ||
LL | unsafe { x == y } | ||
| ^^^^^^ | ||
| ^^ no implementation for `fn() == _` | ||
| | ||
= note: see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information | ||
= help: the trait `~const PartialEq<_>` is not implemented for `fn()` | ||
note: the trait `PartialEq<_>` is implemented for `fn()`, but that implementation is not `const` | ||
--> $DIR/cmp_fn_pointers.rs:2:16 | ||
| | ||
LL | unsafe { x == y } | ||
| ^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The const checking logic for this message can now just be an assert or a delay_span_bug I believe