Skip to content

Commit f5604a6

Browse files
committed
Auto merge of rust-lang#96964 - oli-obk:const_trait_mvp, r=compiler-errors
Replace `#[default_method_body_is_const]` with `#[const_trait]` pulled out of rust-lang#96077 related issues: rust-lang#67792 and rust-lang#92158 cc `@fee1-dead` This is groundwork to only allowing `impl const Trait` for traits that are marked with `#[const_trait]`. This is necessary to prevent adding a new default method from becoming a breaking change (as it could be a non-const fn).
2 parents d1a9802 + 8be7498 commit f5604a6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

core/src/clone.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ use crate::marker::Destruct;
107107
#[lang = "clone"]
108108
#[rustc_diagnostic_item = "Clone"]
109109
#[rustc_trivial_field_reads]
110+
#[cfg_attr(not(bootstrap), const_trait)]
110111
pub trait Clone: Sized {
111112
/// Returns a copy of the value.
112113
///
@@ -129,7 +130,7 @@ pub trait Clone: Sized {
129130
/// allocations.
130131
#[inline]
131132
#[stable(feature = "rust1", since = "1.0.0")]
132-
#[default_method_body_is_const]
133+
#[cfg_attr(bootstrap, default_method_body_is_const)]
133134
fn clone_from(&mut self, source: &Self)
134135
where
135136
Self: ~const Destruct,

core/src/cmp.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ use self::Ordering::*;
214214
append_const_msg,
215215
)
216216
)]
217+
#[cfg_attr(not(bootstrap), const_trait)]
217218
#[rustc_diagnostic_item = "PartialEq"]
218219
pub trait PartialEq<Rhs: ?Sized = Self> {
219220
/// This method tests for `self` and `other` values to be equal, and is used
@@ -226,7 +227,7 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
226227
#[inline]
227228
#[must_use]
228229
#[stable(feature = "rust1", since = "1.0.0")]
229-
#[default_method_body_is_const]
230+
#[cfg_attr(bootstrap, default_method_body_is_const)]
230231
fn ne(&self, other: &Rhs) -> bool {
231232
!self.eq(other)
232233
}
@@ -1053,6 +1054,7 @@ impl PartialOrd for Ordering {
10531054
append_const_msg,
10541055
)
10551056
)]
1057+
#[cfg_attr(not(bootstrap), const_trait)]
10561058
#[rustc_diagnostic_item = "PartialOrd"]
10571059
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
10581060
/// This method returns an ordering between `self` and `other` values if one exists.
@@ -1096,7 +1098,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
10961098
#[inline]
10971099
#[must_use]
10981100
#[stable(feature = "rust1", since = "1.0.0")]
1099-
#[default_method_body_is_const]
1101+
#[cfg_attr(bootstrap, default_method_body_is_const)]
11001102
fn lt(&self, other: &Rhs) -> bool {
11011103
matches!(self.partial_cmp(other), Some(Less))
11021104
}
@@ -1116,7 +1118,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
11161118
#[inline]
11171119
#[must_use]
11181120
#[stable(feature = "rust1", since = "1.0.0")]
1119-
#[default_method_body_is_const]
1121+
#[cfg_attr(bootstrap, default_method_body_is_const)]
11201122
fn le(&self, other: &Rhs) -> bool {
11211123
// Pattern `Some(Less | Eq)` optimizes worse than negating `None | Some(Greater)`.
11221124
// FIXME: The root cause was fixed upstream in LLVM with:
@@ -1139,7 +1141,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
11391141
#[inline]
11401142
#[must_use]
11411143
#[stable(feature = "rust1", since = "1.0.0")]
1142-
#[default_method_body_is_const]
1144+
#[cfg_attr(bootstrap, default_method_body_is_const)]
11431145
fn gt(&self, other: &Rhs) -> bool {
11441146
matches!(self.partial_cmp(other), Some(Greater))
11451147
}
@@ -1159,7 +1161,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
11591161
#[inline]
11601162
#[must_use]
11611163
#[stable(feature = "rust1", since = "1.0.0")]
1162-
#[default_method_body_is_const]
1164+
#[cfg_attr(bootstrap, default_method_body_is_const)]
11631165
fn ge(&self, other: &Rhs) -> bool {
11641166
matches!(self.partial_cmp(other), Some(Greater | Equal))
11651167
}

0 commit comments

Comments
 (0)