-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add an implicit Self: ~const Trait
bound on default_method_body_is_const
methods
#92228
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
Closed
Closed
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -1243,7 +1243,8 @@ mod impls { | |
macro_rules! partial_eq_impl { | ||
($($t:ty)*) => ($( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl PartialEq for $t { | ||
#[rustc_const_unstable(feature = "const_cmp", issue = "none")] | ||
impl const PartialEq for $t { | ||
#[inline] | ||
fn eq(&self, other: &$t) -> bool { (*self) == (*other) } | ||
#[inline] | ||
|
@@ -1280,10 +1281,11 @@ mod impls { | |
macro_rules! partial_ord_impl { | ||
($($t:ty)*) => ($( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl PartialOrd for $t { | ||
#[rustc_const_unstable(feature = "const_cmp", issue = "none")] | ||
impl const PartialOrd for $t { | ||
#[inline] | ||
fn partial_cmp(&self, other: &$t) -> Option<Ordering> { | ||
match (self <= other, self >= other) { | ||
match (*self <= *other, *self >= *other) { | ||
(false, false) => None, | ||
(false, true) => Some(Greater), | ||
(true, false) => Some(Less), | ||
|
@@ -1323,10 +1325,13 @@ mod impls { | |
macro_rules! ord_impl { | ||
($($t:ty)*) => ($( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl PartialOrd for $t { | ||
#[rustc_const_unstable(feature = "const_cmp", issue = "none")] | ||
impl const PartialOrd for $t { | ||
#[inline] | ||
fn partial_cmp(&self, other: &$t) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
Some(if *self < *other { Less } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a const hack comment here |
||
else if *self == *other { Equal } | ||
else { Greater }) | ||
} | ||
#[inline] | ||
fn lt(&self, other: &$t) -> bool { (*self) < (*other) } | ||
|
This file contains hidden or 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 hidden or 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,37 +1,27 @@ | ||
error: overly complex generic constant | ||
--> $DIR/issue-90318.rs:14:8 | ||
error[E0277]: can't compare `TypeId` with `TypeId` | ||
--> $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 == TypeId` | ||
| | ||
= help: consider moving this anonymous constant into a `const` function | ||
= note: this operation may be supported in the future | ||
|
||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/issue-90318.rs:14:10 | ||
= help: the trait `PartialEq` is not implemented for `TypeId` | ||
help: consider extending the `where` bound, but there might be an alternative better way to express this requirement | ||
| | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, TypeId: PartialEq | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: overly complex generic constant | ||
--> $DIR/issue-90318.rs:22:8 | ||
error[E0277]: can't compare `TypeId` with `TypeId` | ||
--> $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 == TypeId` | ||
| | ||
= help: consider moving this anonymous constant into a `const` function | ||
= note: this operation may be supported in the future | ||
|
||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/issue-90318.rs:22:10 | ||
= help: the trait `PartialEq` is not implemented for `TypeId` | ||
help: consider extending the `where` bound, but there might be an alternative better way to express this requirement | ||
| | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True, TypeId: PartialEq | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
|
||
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 hidden or 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 hidden or 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,15 @@ | ||
error: pointers cannot be reliably compared during const eval | ||
--> $DIR/issue-25826.rs:3:30 | ||
error[E0277]: can't compare `*const ()` with `*const ()` | ||
--> $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 `PartialOrd` is not implemented for `*const ()` | ||
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | ||
| | ||
LL | fn main() where *const (): PartialOrd { | ||
| +++++++++++++++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or 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
13 changes: 9 additions & 4 deletions
13
src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr
This file contains hidden or 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,9 +1,14 @@ | ||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/const-default-method-bodies.rs:25:5 | ||
error[E0277]: the trait bound `NonConstImpl: ConstDefaultFn` is not satisfied | ||
--> $DIR/const-default-method-bodies.rs:25:18 | ||
| | ||
LL | NonConstImpl.a(); | ||
| ^^^^^^^^^^^^^^^^ | ||
| ^ the trait `ConstDefaultFn` is not implemented for `NonConstImpl` | ||
| | ||
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | ||
| | ||
LL | const fn test() where NonConstImpl: ConstDefaultFn { | ||
| ++++++++++++++++++++++++++++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0015`. | ||
For more information about this error, try `rustc --explain E0277`. |
17 changes: 17 additions & 0 deletions
17
src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-implied-bounds-on-self.rs
This file contains hidden or 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,17 @@ | ||
// check-pass | ||
|
||
#![feature(const_trait_impl)] | ||
#![feature(const_fn_trait_bound)] | ||
|
||
pub trait Foo { | ||
#[default_method_body_is_const] | ||
fn do_stuff(self) where Self: Sized { | ||
do_stuff_as_foo(self); | ||
} | ||
} | ||
|
||
const fn do_stuff_as_foo<T: ~const Foo>(foo: T) { | ||
std::mem::forget(foo); | ||
} | ||
|
||
fn main() {} |
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.
Uh oh!
There was an error while loading. Please reload this page.