Skip to content

Commit a69f0dc

Browse files
committed
Auto merge of rust-lang#120283 - fmease:rollup-rk0f6r5, r=fmease
Rollup of 9 pull requests Successful merges: - rust-lang#112806 (Small code improvements in `collect_intra_doc_links.rs`) - rust-lang#119766 (Split tait and impl trait in assoc items logic) - rust-lang#120139 (Do not normalize closure signature when building `FnOnce` shim) - rust-lang#120160 (Manually implement derived `NonZero` traits.) - rust-lang#120171 (Fix assume and assert in jump threading) - rust-lang#120183 (Add `#[coverage(off)]` to closures introduced by `#[test]` and `#[bench]`) - rust-lang#120195 (add several resolution test cases) - rust-lang#120259 (Split Diagnostics for Uncommon Codepoints: Add List to Display Characters Involved) - rust-lang#120261 (Provide structured suggestion to use trait objects in some cases of `if` arm type divergence) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 29b8800 + f687e3c commit a69f0dc

File tree

3 files changed

+105
-10
lines changed

3 files changed

+105
-10
lines changed

core/src/intrinsics/mir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ define!("mir_unwind_resume",
357357

358358
define!("mir_storage_live", fn StorageLive<T>(local: T));
359359
define!("mir_storage_dead", fn StorageDead<T>(local: T));
360+
#[cfg(not(bootstrap))]
361+
define!("mir_assume", fn Assume(operand: bool));
360362
define!("mir_deinit", fn Deinit<T>(place: T));
361363
define!("mir_checked", fn Checked<T>(binop: T) -> (T, bool));
362364
define!("mir_len", fn Len<T>(place: T) -> usize);

core/src/macros/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ pub(crate) mod builtin {
15961596
///
15971597
/// [the reference]: ../../../reference/attributes/testing.html#the-test-attribute
15981598
#[stable(feature = "rust1", since = "1.0.0")]
1599-
#[allow_internal_unstable(test, rustc_attrs)]
1599+
#[allow_internal_unstable(test, rustc_attrs, coverage_attribute)]
16001600
#[rustc_builtin_macro]
16011601
pub macro test($item:item) {
16021602
/* compiler built-in */
@@ -1609,7 +1609,7 @@ pub(crate) mod builtin {
16091609
soft,
16101610
reason = "`bench` is a part of custom test frameworks which are unstable"
16111611
)]
1612-
#[allow_internal_unstable(test, rustc_attrs)]
1612+
#[allow_internal_unstable(test, rustc_attrs, coverage_attribute)]
16131613
#[rustc_builtin_macro]
16141614
pub macro bench($item:item) {
16151615
/* compiler built-in */

core/src/num/nonzero.rs

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! Definitions of integer that is known not to equal zero.
22
3+
use crate::cmp::Ordering;
34
use crate::fmt;
5+
use crate::hash::{Hash, Hasher};
6+
use crate::marker::StructuralPartialEq;
47
use crate::ops::{BitOr, BitOrAssign, Div, Neg, Rem};
58
use crate::str::FromStr;
69

@@ -31,13 +34,6 @@ pub trait ZeroablePrimitive: Sized + Copy + private::Sealed {
3134
type NonZero;
3235
}
3336

34-
#[unstable(
35-
feature = "nonzero_internals",
36-
reason = "implementation detail which may disappear or be replaced at any time",
37-
issue = "none"
38-
)]
39-
pub(crate) type NonZero<T> = <T as ZeroablePrimitive>::NonZero;
40-
4137
macro_rules! impl_zeroable_primitive {
4238
($NonZero:ident ( $primitive:ty )) => {
4339
#[unstable(
@@ -71,6 +67,13 @@ impl_zeroable_primitive!(NonZeroI64(i64));
7167
impl_zeroable_primitive!(NonZeroI128(i128));
7268
impl_zeroable_primitive!(NonZeroIsize(isize));
7369

70+
#[unstable(
71+
feature = "nonzero_internals",
72+
reason = "implementation detail which may disappear or be replaced at any time",
73+
issue = "none"
74+
)]
75+
pub(crate) type NonZero<T> = <T as ZeroablePrimitive>::NonZero;
76+
7477
macro_rules! impl_nonzero_fmt {
7578
( #[$stability: meta] ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
7679
$(
@@ -128,7 +131,7 @@ macro_rules! nonzero_integer {
128131
///
129132
/// [null pointer optimization]: crate::option#representation
130133
#[$stability]
131-
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
134+
#[derive(Copy, Eq)]
132135
#[repr(transparent)]
133136
#[rustc_layout_scalar_valid_range_start(1)]
134137
#[rustc_nonnull_optimization_guaranteed]
@@ -494,6 +497,96 @@ macro_rules! nonzero_integer {
494497
}
495498
}
496499

500+
#[$stability]
501+
impl Clone for $Ty {
502+
#[inline]
503+
fn clone(&self) -> Self {
504+
// SAFETY: The contained value is non-zero.
505+
unsafe { Self(self.0) }
506+
}
507+
}
508+
509+
#[$stability]
510+
impl PartialEq for $Ty {
511+
#[inline]
512+
fn eq(&self, other: &Self) -> bool {
513+
self.0 == other.0
514+
}
515+
516+
#[inline]
517+
fn ne(&self, other: &Self) -> bool {
518+
self.0 != other.0
519+
}
520+
}
521+
522+
#[unstable(feature = "structural_match", issue = "31434")]
523+
impl StructuralPartialEq for $Ty {}
524+
525+
#[$stability]
526+
impl PartialOrd for $Ty {
527+
#[inline]
528+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
529+
self.0.partial_cmp(&other.0)
530+
}
531+
532+
#[inline]
533+
fn lt(&self, other: &Self) -> bool {
534+
self.0 < other.0
535+
}
536+
537+
#[inline]
538+
fn le(&self, other: &Self) -> bool {
539+
self.0 <= other.0
540+
}
541+
542+
#[inline]
543+
fn gt(&self, other: &Self) -> bool {
544+
self.0 > other.0
545+
}
546+
547+
#[inline]
548+
fn ge(&self, other: &Self) -> bool {
549+
self.0 >= other.0
550+
}
551+
}
552+
553+
#[$stability]
554+
impl Ord for $Ty {
555+
#[inline]
556+
fn cmp(&self, other: &Self) -> Ordering {
557+
self.0.cmp(&other.0)
558+
}
559+
560+
#[inline]
561+
fn max(self, other: Self) -> Self {
562+
// SAFETY: The maximum of two non-zero values is still non-zero.
563+
unsafe { Self(self.0.max(other.0)) }
564+
}
565+
566+
#[inline]
567+
fn min(self, other: Self) -> Self {
568+
// SAFETY: The minimum of two non-zero values is still non-zero.
569+
unsafe { Self(self.0.min(other.0)) }
570+
}
571+
572+
#[inline]
573+
fn clamp(self, min: Self, max: Self) -> Self {
574+
// SAFETY: A non-zero value clamped between two non-zero values is still non-zero.
575+
unsafe { Self(self.0.clamp(min.0, max.0)) }
576+
}
577+
}
578+
579+
#[$stability]
580+
impl Hash for $Ty {
581+
#[inline]
582+
fn hash<H>(&self, state: &mut H)
583+
where
584+
H: Hasher,
585+
{
586+
self.0.hash(state)
587+
}
588+
}
589+
497590
#[stable(feature = "from_nonzero", since = "1.31.0")]
498591
impl From<$Ty> for $Int {
499592
#[doc = concat!("Converts a `", stringify!($Ty), "` into an `", stringify!($Int), "`")]

0 commit comments

Comments
 (0)