Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eefea28

Browse files
authoredNov 13, 2022
Rollup merge of #104320 - fee1-dead-contrib:use-derive-const-in-std, r=oli-obk
Use `derive_const` and rm manual StructuralEq impl This does not change any semantics of the impl except for the const stability. It should be fine because trait methods and const bounds can never be used in stable without enabling `const_trait_impl`. cc `@oli-obk`
2 parents 5c764da + 4b217e4 commit eefea28

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
 

‎compiler/rustc_passes/src/stability.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,14 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
536536
return;
537537
}
538538

539+
// if the const impl is derived using the `derive_const` attribute,
540+
// then it would be "stable" at least for the impl.
541+
// We gate usages of it using `feature(const_trait_impl)` anyways
542+
// so there is no unstable leakage
543+
if self.tcx.is_builtin_derive(def_id.to_def_id()) {
544+
return;
545+
}
546+
539547
let is_const = self.tcx.is_const_fn(def_id.to_def_id())
540548
|| self.tcx.is_const_trait_impl_raw(def_id.to_def_id());
541549
let is_stable = self

‎library/core/src/cmp.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use crate::const_closure::ConstFnMutClosure;
2626
use crate::marker::Destruct;
27+
#[cfg(bootstrap)]
2728
use crate::marker::StructuralPartialEq;
2829

2930
use self::Ordering::*;
@@ -331,6 +332,7 @@ pub struct AssertParamIsEq<T: Eq + ?Sized> {
331332
/// assert_eq!(Ordering::Greater, result);
332333
/// ```
333334
#[derive(Clone, Copy, Eq, Debug, Hash)]
335+
#[cfg_attr(not(bootstrap), derive_const(PartialOrd, Ord, PartialEq))]
334336
#[stable(feature = "rust1", since = "1.0.0")]
335337
#[repr(i8)]
336338
pub enum Ordering {
@@ -877,10 +879,12 @@ pub macro Ord($item:item) {
877879
}
878880

879881
#[stable(feature = "rust1", since = "1.0.0")]
882+
#[cfg(bootstrap)]
880883
impl StructuralPartialEq for Ordering {}
881884

882885
#[stable(feature = "rust1", since = "1.0.0")]
883886
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
887+
#[cfg(bootstrap)]
884888
impl const PartialEq for Ordering {
885889
#[inline]
886890
fn eq(&self, other: &Self) -> bool {
@@ -890,6 +894,7 @@ impl const PartialEq for Ordering {
890894

891895
#[stable(feature = "rust1", since = "1.0.0")]
892896
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
897+
#[cfg(bootstrap)]
893898
impl const Ord for Ordering {
894899
#[inline]
895900
fn cmp(&self, other: &Ordering) -> Ordering {
@@ -899,6 +904,7 @@ impl const Ord for Ordering {
899904

900905
#[stable(feature = "rust1", since = "1.0.0")]
901906
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
907+
#[cfg(bootstrap)]
902908
impl const PartialOrd for Ordering {
903909
#[inline]
904910
fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {

‎library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
#![feature(const_refs_to_cell)]
186186
#![feature(decl_macro)]
187187
#![feature(deprecated_suggestion)]
188+
#![cfg_attr(not(bootstrap), feature(derive_const))]
188189
#![feature(doc_cfg)]
189190
#![feature(doc_notable_trait)]
190191
#![feature(rustdoc_internals)]

0 commit comments

Comments
 (0)
Please sign in to comment.