Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9582040

Browse files
committedJan 27, 2024
Auto merge of rust-lang#120165 - reitermarkus:nonzero-switch-alias-direction, r=dtolnay
Switch `NonZero` alias direction. Step 4 mentioned in rust-lang#100428 (review). Depends on rust-lang#120160. r? `@dtolnay`
2 parents 6b4f1c5 + 021739c commit 9582040

File tree

22 files changed

+208
-190
lines changed

22 files changed

+208
-190
lines changed
 

‎compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,46 +2140,50 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21402140
expr_ty: Ty<'tcx>,
21412141
) -> bool {
21422142
let tcx = self.tcx;
2143-
let (adt, unwrap) = match expected.kind() {
2143+
let (adt, substs, unwrap) = match expected.kind() {
21442144
// In case Option<NonZero*> is wanted, but * is provided, suggest calling new
2145-
ty::Adt(adt, args) if tcx.is_diagnostic_item(sym::Option, adt.did()) => {
2146-
// Unwrap option
2147-
let ty::Adt(adt, _) = args.type_at(0).kind() else {
2145+
ty::Adt(adt, substs) if tcx.is_diagnostic_item(sym::Option, adt.did()) => {
2146+
let nonzero_type = substs.type_at(0); // Unwrap option type.
2147+
let ty::Adt(adt, substs) = nonzero_type.kind() else {
21482148
return false;
21492149
};
2150-
2151-
(adt, "")
2150+
(adt, substs, "")
21522151
}
2153-
// In case NonZero* is wanted, but * is provided also add `.unwrap()` to satisfy types
2154-
ty::Adt(adt, _) => (adt, ".unwrap()"),
2152+
// In case `NonZero<*>` is wanted but `*` is provided, also add `.unwrap()` to satisfy types.
2153+
ty::Adt(adt, substs) => (adt, substs, ".unwrap()"),
21552154
_ => return false,
21562155
};
21572156

2158-
let map = [
2159-
(sym::NonZeroU8, tcx.types.u8),
2160-
(sym::NonZeroU16, tcx.types.u16),
2161-
(sym::NonZeroU32, tcx.types.u32),
2162-
(sym::NonZeroU64, tcx.types.u64),
2163-
(sym::NonZeroU128, tcx.types.u128),
2164-
(sym::NonZeroI8, tcx.types.i8),
2165-
(sym::NonZeroI16, tcx.types.i16),
2166-
(sym::NonZeroI32, tcx.types.i32),
2167-
(sym::NonZeroI64, tcx.types.i64),
2168-
(sym::NonZeroI128, tcx.types.i128),
2157+
if !self.tcx.is_diagnostic_item(sym::NonZero, adt.did()) {
2158+
return false;
2159+
}
2160+
2161+
// FIXME: This can be simplified once `NonZero<T>` is stable.
2162+
let coercable_types = [
2163+
("NonZeroU8", tcx.types.u8),
2164+
("NonZeroU16", tcx.types.u16),
2165+
("NonZeroU32", tcx.types.u32),
2166+
("NonZeroU64", tcx.types.u64),
2167+
("NonZeroU128", tcx.types.u128),
2168+
("NonZeroI8", tcx.types.i8),
2169+
("NonZeroI16", tcx.types.i16),
2170+
("NonZeroI32", tcx.types.i32),
2171+
("NonZeroI64", tcx.types.i64),
2172+
("NonZeroI128", tcx.types.i128),
21692173
];
21702174

2171-
let Some((s, _)) = map.iter().find(|&&(s, t)| {
2172-
self.tcx.is_diagnostic_item(s, adt.did()) && self.can_coerce(expr_ty, t)
2175+
let int_type = substs.type_at(0);
2176+
2177+
let Some(nonzero_alias) = coercable_types.iter().find_map(|(nonzero_alias, t)| {
2178+
if *t == int_type && self.can_coerce(expr_ty, *t) { Some(nonzero_alias) } else { None }
21732179
}) else {
21742180
return false;
21752181
};
21762182

2177-
let path = self.tcx.def_path_str(adt.non_enum_variant().def_id);
2178-
21792183
err.multipart_suggestion(
2180-
format!("consider calling `{s}::new`"),
2184+
format!("consider calling `{nonzero_alias}::new`"),
21812185
vec![
2182-
(expr.span.shrink_to_lo(), format!("{path}::new(")),
2186+
(expr.span.shrink_to_lo(), format!("{nonzero_alias}::new(")),
21832187
(expr.span.shrink_to_hi(), format!("){unwrap}")),
21842188
],
21852189
Applicability::MaybeIncorrect,

‎compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,7 @@ symbols! {
246246
MutexGuard,
247247
N,
248248
NonNull,
249-
NonZeroI128,
250-
NonZeroI16,
251-
NonZeroI32,
252-
NonZeroI64,
253-
NonZeroI8,
254-
NonZeroU128,
255-
NonZeroU16,
256-
NonZeroU32,
257-
NonZeroU64,
258-
NonZeroU8,
259-
NonZeroUsize,
249+
NonZero,
260250
None,
261251
Normal,
262252
Ok,

‎library/core/src/num/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ pub use dec2flt::ParseFloatError;
6161
#[stable(feature = "rust1", since = "1.0.0")]
6262
pub use error::ParseIntError;
6363

64-
pub(crate) use nonzero::NonZero;
64+
#[unstable(
65+
feature = "nonzero_internals",
66+
reason = "implementation detail which may disappear or be replaced at any time",
67+
issue = "none"
68+
)]
69+
pub use nonzero::ZeroablePrimitive;
70+
71+
#[unstable(feature = "generic_nonzero", issue = "120257")]
72+
pub use nonzero::NonZero;
6573

6674
#[stable(feature = "nonzero", since = "1.28.0")]
6775
pub use nonzero::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};

‎library/core/src/num/nonzero.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use crate::cmp::Ordering;
44
use crate::fmt;
55
use crate::hash::{Hash, Hasher};
6+
#[cfg(bootstrap)]
7+
use crate::marker::StructuralEq;
68
use crate::marker::StructuralPartialEq;
79
use crate::ops::{BitOr, BitOrAssign, Div, Neg, Rem};
810
use crate::str::FromStr;
@@ -30,9 +32,7 @@ mod private {
3032
issue = "none"
3133
)]
3234
#[const_trait]
33-
pub trait ZeroablePrimitive: Sized + Copy + private::Sealed {
34-
type NonZero;
35-
}
35+
pub trait ZeroablePrimitive: Sized + Copy + private::Sealed {}
3636

3737
macro_rules! impl_zeroable_primitive {
3838
($NonZero:ident ( $primitive:ty )) => {
@@ -48,9 +48,7 @@ macro_rules! impl_zeroable_primitive {
4848
reason = "implementation detail which may disappear or be replaced at any time",
4949
issue = "none"
5050
)]
51-
impl const ZeroablePrimitive for $primitive {
52-
type NonZero = $NonZero;
53-
}
51+
impl const ZeroablePrimitive for $primitive {}
5452
};
5553
}
5654

@@ -67,12 +65,23 @@ impl_zeroable_primitive!(NonZeroI64(i64));
6765
impl_zeroable_primitive!(NonZeroI128(i128));
6866
impl_zeroable_primitive!(NonZeroIsize(isize));
6967

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;
68+
/// A value that is known not to equal zero.
69+
///
70+
/// This enables some memory layout optimization.
71+
/// For example, `Option<NonZero<u32>>` is the same size as `u32`:
72+
///
73+
/// ```
74+
/// #![feature(generic_nonzero)]
75+
/// use core::mem::size_of;
76+
///
77+
/// assert_eq!(size_of::<Option<core::num::NonZero<u32>>>(), size_of::<u32>());
78+
/// ```
79+
#[unstable(feature = "generic_nonzero", issue = "120257")]
80+
#[repr(transparent)]
81+
#[rustc_layout_scalar_valid_range_start(1)]
82+
#[rustc_nonnull_optimization_guaranteed]
83+
#[rustc_diagnostic_item = "NonZero"]
84+
pub struct NonZero<T: ZeroablePrimitive>(T);
7685

7786
macro_rules! impl_nonzero_fmt {
7887
( #[$stability: meta] ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
@@ -131,12 +140,7 @@ macro_rules! nonzero_integer {
131140
///
132141
/// [null pointer optimization]: crate::option#representation
133142
#[$stability]
134-
#[derive(Copy, Eq)]
135-
#[repr(transparent)]
136-
#[rustc_layout_scalar_valid_range_start(1)]
137-
#[rustc_nonnull_optimization_guaranteed]
138-
#[rustc_diagnostic_item = stringify!($Ty)]
139-
pub struct $Ty($Int);
143+
pub type $Ty = NonZero<$Int>;
140144

141145
impl $Ty {
142146
/// Creates a non-zero without checking whether the value is non-zero.
@@ -543,6 +547,9 @@ macro_rules! nonzero_integer {
543547
}
544548
}
545549

550+
#[$stability]
551+
impl Copy for $Ty {}
552+
546553
#[$stability]
547554
impl PartialEq for $Ty {
548555
#[inline]
@@ -559,6 +566,13 @@ macro_rules! nonzero_integer {
559566
#[unstable(feature = "structural_match", issue = "31434")]
560567
impl StructuralPartialEq for $Ty {}
561568

569+
#[$stability]
570+
impl Eq for $Ty {}
571+
572+
#[unstable(feature = "structural_match", issue = "31434")]
573+
#[cfg(bootstrap)]
574+
impl StructuralEq for $Ty {}
575+
562576
#[$stability]
563577
impl PartialOrd for $Ty {
564578
#[inline]

‎library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@
323323
#![feature(float_gamma)]
324324
#![feature(float_minimum_maximum)]
325325
#![feature(float_next_up_down)]
326+
#![feature(generic_nonzero)]
326327
#![feature(hasher_prefixfree_extras)]
327328
#![feature(hashmap_internals)]
328329
#![feature(hint_assert_unchecked)]

‎library/std/src/num.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ pub use core::num::Wrapping;
1616
#[stable(feature = "rust1", since = "1.0.0")]
1717
pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError};
1818

19+
#[unstable(
20+
feature = "nonzero_internals",
21+
reason = "implementation detail which may disappear or be replaced at any time",
22+
issue = "none"
23+
)]
24+
pub use core::num::ZeroablePrimitive;
25+
26+
#[unstable(feature = "generic_nonzero", issue = "120257")]
27+
pub use core::num::NonZero;
28+
1929
#[stable(feature = "signed_nonzero", since = "1.34.0")]
2030
pub use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
2131
#[stable(feature = "nonzero", since = "1.28.0")]

‎src/etc/natvis/libcore.natvis

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,7 @@
4141
</Expand>
4242
</Type>
4343

44-
<Type Name="core::num::nonzero::NonZeroI8">
45-
<DisplayString>{__0}</DisplayString>
46-
</Type>
47-
<Type Name="core::num::nonzero::NonZeroI16">
48-
<DisplayString>{__0}</DisplayString>
49-
</Type>
50-
<Type Name="core::num::nonzero::NonZeroI32">
51-
<DisplayString>{__0}</DisplayString>
52-
</Type>
53-
<Type Name="core::num::nonzero::NonZeroI64">
54-
<DisplayString>{__0}</DisplayString>
55-
</Type>
56-
<Type Name="core::num::nonzero::NonZeroI128">
57-
<DisplayString>{__0}</DisplayString>
58-
</Type>
59-
<Type Name="core::num::nonzero::NonZeroIsize">
60-
<DisplayString>{__0}</DisplayString>
61-
</Type>
62-
<Type Name="core::num::nonzero::NonZeroU8">
63-
<DisplayString>{__0}</DisplayString>
64-
</Type>
65-
<Type Name="core::num::nonzero::NonZeroU16">
66-
<DisplayString>{__0}</DisplayString>
67-
</Type>
68-
<Type Name="core::num::nonzero::NonZeroU32">
69-
<DisplayString>{__0}</DisplayString>
70-
</Type>
71-
<Type Name="core::num::nonzero::NonZeroU64">
72-
<DisplayString>{__0}</DisplayString>
73-
</Type>
74-
<Type Name="core::num::nonzero::NonZeroU128">
75-
<DisplayString>{__0}</DisplayString>
76-
</Type>
77-
<Type Name="core::num::nonzero::NonZeroUsize">
44+
<Type Name="core::num::nonzero::NonZero&lt;*&gt;">
7845
<DisplayString>{__0}</DisplayString>
7946
</Type>
8047

‎src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use super::ARITHMETIC_SIDE_EFFECTS;
22
use clippy_utils::consts::{constant, constant_simple, Constant};
33
use clippy_utils::diagnostics::span_lint;
4-
use clippy_utils::ty::type_diagnostic_name;
4+
use clippy_utils::ty::is_type_diagnostic_item;
55
use clippy_utils::{expr_or_init, is_from_proc_macro, is_lint_allowed, peel_hir_expr_refs, peel_hir_expr_unary};
66
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_lint::{LateContext, LateLintPass};
8-
use rustc_middle::ty::Ty;
8+
use rustc_middle::ty::{self, Ty};
99
use rustc_session::impl_lint_pass;
1010
use rustc_span::source_map::Spanned;
1111
use rustc_span::symbol::sym;
@@ -88,37 +88,44 @@ impl ArithmeticSideEffects {
8888
}
8989

9090
/// Verifies built-in types that have specific allowed operations
91-
fn has_specific_allowed_type_and_operation(
92-
cx: &LateContext<'_>,
93-
lhs_ty: Ty<'_>,
91+
fn has_specific_allowed_type_and_operation<'tcx>(
92+
cx: &LateContext<'tcx>,
93+
lhs_ty: Ty<'tcx>,
9494
op: &Spanned<hir::BinOpKind>,
95-
rhs_ty: Ty<'_>,
95+
rhs_ty: Ty<'tcx>,
9696
) -> bool {
9797
let is_div_or_rem = matches!(op.node, hir::BinOpKind::Div | hir::BinOpKind::Rem);
98-
let is_non_zero_u = |symbol: Option<Symbol>| {
99-
matches!(
100-
symbol,
101-
Some(
102-
sym::NonZeroU128
103-
| sym::NonZeroU16
104-
| sym::NonZeroU32
105-
| sym::NonZeroU64
106-
| sym::NonZeroU8
107-
| sym::NonZeroUsize
108-
)
109-
)
98+
let is_non_zero_u = |cx: &LateContext<'tcx>, ty: Ty<'tcx>| {
99+
let tcx = cx.tcx;
100+
101+
let ty::Adt(adt, substs) = ty.kind() else { return false };
102+
103+
if !tcx.is_diagnostic_item(sym::NonZero, adt.did()) {
104+
return false;
105+
};
106+
107+
let int_type = substs.type_at(0);
108+
let unsigned_int_types = [
109+
tcx.types.u8,
110+
tcx.types.u16,
111+
tcx.types.u32,
112+
tcx.types.u64,
113+
tcx.types.u128,
114+
tcx.types.usize,
115+
];
116+
117+
unsigned_int_types.contains(&int_type)
110118
};
111119
let is_sat_or_wrap = |ty: Ty<'_>| {
112-
let is_sat = type_diagnostic_name(cx, ty) == Some(sym::Saturating);
113-
let is_wrap = type_diagnostic_name(cx, ty) == Some(sym::Wrapping);
114-
is_sat || is_wrap
120+
is_type_diagnostic_item(cx, ty, sym::Saturating) || is_type_diagnostic_item(cx, ty, sym::Wrapping)
115121
};
116122

117-
// If the RHS is NonZeroU*, then division or module by zero will never occur
118-
if is_non_zero_u(type_diagnostic_name(cx, rhs_ty)) && is_div_or_rem {
123+
// If the RHS is `NonZero<u*>`, then division or module by zero will never occur.
124+
if is_non_zero_u(cx, rhs_ty) && is_div_or_rem {
119125
return true;
120126
}
121-
// `Saturation` and `Wrapping` can overflow if the RHS is zero in a division or module
127+
128+
// `Saturation` and `Wrapping` can overflow if the RHS is zero in a division or module.
122129
if is_sat_or_wrap(lhs_ty) {
123130
return !is_div_or_rem;
124131
}

‎src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_non_zero.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,55 @@ pub(super) fn check<'tcx>(
1616
to_ty: Ty<'tcx>,
1717
arg: &'tcx Expr<'_>,
1818
) -> bool {
19-
let (ty::Int(_) | ty::Uint(_), Some(to_ty_adt)) = (&from_ty.kind(), to_ty.ty_adt_def()) else {
19+
let tcx = cx.tcx;
20+
21+
let (ty::Int(_) | ty::Uint(_), ty::Adt(adt, substs)) = (&from_ty.kind(), to_ty.kind()) else {
2022
return false;
2123
};
22-
let Some(to_type_sym) = cx.tcx.get_diagnostic_name(to_ty_adt.did()) else {
24+
25+
if !tcx.is_diagnostic_item(sym::NonZero, adt.did()) {
2326
return false;
2427
};
2528

26-
if !matches!(
27-
to_type_sym,
28-
sym::NonZeroU8
29-
| sym::NonZeroU16
30-
| sym::NonZeroU32
31-
| sym::NonZeroU64
32-
| sym::NonZeroU128
33-
| sym::NonZeroI8
34-
| sym::NonZeroI16
35-
| sym::NonZeroI32
36-
| sym::NonZeroI64
37-
| sym::NonZeroI128
38-
) {
29+
// FIXME: This can be simplified once `NonZero<T>` is stable.
30+
let coercable_types = [
31+
("NonZeroU8", tcx.types.u8),
32+
("NonZeroU16", tcx.types.u16),
33+
("NonZeroU32", tcx.types.u32),
34+
("NonZeroU64", tcx.types.u64),
35+
("NonZeroU128", tcx.types.u128),
36+
("NonZeroUsize", tcx.types.usize),
37+
("NonZeroI8", tcx.types.i8),
38+
("NonZeroI16", tcx.types.i16),
39+
("NonZeroI32", tcx.types.i32),
40+
("NonZeroI64", tcx.types.i64),
41+
("NonZeroI128", tcx.types.i128),
42+
("NonZeroIsize", tcx.types.isize),
43+
];
44+
45+
let int_type = substs.type_at(0);
46+
47+
let Some(nonzero_alias) = coercable_types.iter().find_map(|(nonzero_alias, t)| {
48+
if *t == int_type && *t == from_ty {
49+
Some(nonzero_alias)
50+
} else {
51+
None
52+
}
53+
}) else {
3954
return false;
40-
}
55+
};
4156

4257
span_lint_and_then(
4358
cx,
4459
TRANSMUTE_INT_TO_NON_ZERO,
4560
e.span,
46-
&format!("transmute from a `{from_ty}` to a `{to_type_sym}`"),
61+
&format!("transmute from a `{from_ty}` to a `{nonzero_alias}`"),
4762
|diag| {
4863
let arg = sugg::Sugg::hir(cx, arg, "..");
4964
diag.span_suggestion(
5065
e.span,
5166
"consider using",
52-
format!("{to_type_sym}::{}({arg})", sym::new_unchecked),
67+
format!("{nonzero_alias}::{}({arg})", sym::new_unchecked),
5368
Applicability::Unspecified,
5469
);
5570
},

‎tests/debuginfo/msvc-pretty-enums.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
// cdb-check: [+0x000] __0 : 0x2a [Type: unsigned int]
4747

4848
// cdb-command: dx niche128_some
49-
// cdb-check: niche128_some : Some [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
49+
// cdb-check: niche128_some : Some [Type: enum2$<core::option::Option<core::num::nonzero::NonZero<i128> > >]
5050
// Note: we can't actually read the value of the field because CDB cannot handle 128 bit integers.
51-
// cdb-check: [+0x000] __0 [...] [Type: core::num::nonzero::NonZeroI128]
51+
// cdb-check: [+0x000] __0 [...] [Type: core::num::nonzero::NonZero<i128>]
5252

5353
// cdb-command: dx niche128_none
54-
// cdb-check: niche128_none : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
54+
// cdb-check: niche128_none : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZero<i128> > >]
5555

5656
// cdb-command: dx wrapping_niche128_untagged
5757
// cdb-check: wrapping_niche128_untagged : X [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
@@ -84,7 +84,7 @@
8484

8585
// cdb-command: dx niche_w_fields_2_some,d
8686
// cdb-check: niche_w_fields_2_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>]
87-
// cdb-check: [+0x[...]] __0 : 800 [Type: core::num::nonzero::NonZeroU32]
87+
// cdb-check: [+0x[...]] __0 : 800 [Type: core::num::nonzero::NonZero<u32>]
8888
// cdb-check: [+0x[...]] __1 : 900 [Type: unsigned __int64]
8989

9090
// cdb-command: dx niche_w_fields_2_none,d

‎tests/debuginfo/numeric-types.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,59 @@
33
// min-gdb-version: 8.1
44
// ignore-windows-gnu // emit_debug_gdb_scripts is disabled on Windows
55

6-
// Tests the visualizations for `NonZero{I,U}{8,16,32,64,128,size}`, `Wrapping<T>` and
6+
// Tests the visualizations for `NonZero<T>`, `Wrapping<T>` and
77
// `Atomic{Bool,I8,I16,I32,I64,Isize,U8,U16,U32,U64,Usize}` located in `libcore.natvis`.
88

99
// === CDB TESTS ==================================================================================
1010
// cdb-command: g
1111

1212
// cdb-command: dx nz_i8
13-
// cdb-check:nz_i8 : 11 [Type: core::num::nonzero::NonZeroI8]
14-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroI8]
13+
// cdb-check:nz_i8 : 11 [Type: core::num::nonzero::NonZero<i8>]
14+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<i8>]
1515

1616
// cdb-command: dx nz_i16
17-
// cdb-check:nz_i16 : 22 [Type: core::num::nonzero::NonZeroI16]
18-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroI16]
17+
// cdb-check:nz_i16 : 22 [Type: core::num::nonzero::NonZero<i16>]
18+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<i16>]
1919

2020
// cdb-command: dx nz_i32
21-
// cdb-check:nz_i32 : 33 [Type: core::num::nonzero::NonZeroI32]
22-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroI32]
21+
// cdb-check:nz_i32 : 33 [Type: core::num::nonzero::NonZero<i32>]
22+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<i32>]
2323

2424
// cdb-command: dx nz_i64
25-
// cdb-check:nz_i64 : 44 [Type: core::num::nonzero::NonZeroI64]
26-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroI64]
25+
// cdb-check:nz_i64 : 44 [Type: core::num::nonzero::NonZero<i64>]
26+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<i64>]
2727

2828
// 128-bit integers don't seem to work in CDB
2929
// cdb-command: dx nz_i128
30-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroI128]
30+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<i128>]
3131

3232
// cdb-command: dx nz_isize
33-
// cdb-check:nz_isize : 66 [Type: core::num::nonzero::NonZeroIsize]
34-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroIsize]
33+
// cdb-check:nz_isize : 66 [Type: core::num::nonzero::NonZero<isize>]
34+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<isize>]
3535

3636
// cdb-command: dx nz_u8
37-
// cdb-check:nz_u8 : 0x4d [Type: core::num::nonzero::NonZeroU8]
38-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroU8]
37+
// cdb-check:nz_u8 : 0x4d [Type: core::num::nonzero::NonZero<u8>]
38+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<u8>]
3939

4040
// cdb-command: dx nz_u16
41-
// cdb-check:nz_u16 : 0x58 [Type: core::num::nonzero::NonZeroU16]
42-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroU16]
41+
// cdb-check:nz_u16 : 0x58 [Type: core::num::nonzero::NonZero<u16>]
42+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<u16>]
4343

4444
// cdb-command: dx nz_u32
45-
// cdb-check:nz_u32 : 0x63 [Type: core::num::nonzero::NonZeroU32]
46-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroU32]
45+
// cdb-check:nz_u32 : 0x63 [Type: core::num::nonzero::NonZero<u32>]
46+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<u32>]
4747

4848
// cdb-command: dx nz_u64
49-
// cdb-check:nz_u64 : 0x64 [Type: core::num::nonzero::NonZeroU64]
50-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroU64]
49+
// cdb-check:nz_u64 : 0x64 [Type: core::num::nonzero::NonZero<u64>]
50+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<u64>]
5151

5252
// 128-bit integers don't seem to work in CDB
5353
// cdb-command: dx nz_u128
54-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroU128]
54+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<u128>]
5555

5656
// cdb-command: dx nz_usize
57-
// cdb-check:nz_usize : 0x7a [Type: core::num::nonzero::NonZeroUsize]
58-
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZeroUsize]
57+
// cdb-check:nz_usize : 0x7a [Type: core::num::nonzero::NonZero<usize>]
58+
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<usize>]
5959

6060
// cdb-command: dx w_i8
6161
// cdb-check:w_i8 : 10 [Type: core::num::wrapping::Wrapping<i8>]

‎tests/mir-opt/instsimplify/combine_transmutes.adt_transmutes.InstSimplify.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
fn adt_transmutes() -> () {
55
let mut _0: ();
66
let _1: u8;
7-
let mut _2: std::option::Option<std::num::NonZeroU8>;
7+
let mut _2: std::option::Option<std::num::NonZero<u8>>;
88
let mut _4: std::num::Wrapping<i16>;
99
let mut _6: std::num::Wrapping<i16>;
1010
let mut _8: Union32;
@@ -37,7 +37,7 @@
3737
bb0: {
3838
StorageLive(_1);
3939
StorageLive(_2);
40-
_2 = Option::<NonZeroU8>::Some(const _);
40+
_2 = Option::<NonZero<u8>>::Some(const _);
4141
_1 = move _2 as u8 (Transmute);
4242
StorageDead(_2);
4343
StorageLive(_3);

‎tests/ui/layout/zero-sized-array-enum-niche.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ error: layout_of(MultipleAlignments) = Layout {
232232
LL | enum MultipleAlignments {
233233
| ^^^^^^^^^^^^^^^^^^^^^^^
234234

235-
error: layout_of(Result<[u32; 0], Packed<NonZeroU16>>) = Layout {
235+
error: layout_of(Result<[u32; 0], Packed<NonZero<u16>>>) = Layout {
236236
size: Size(4 bytes),
237237
align: AbiAndPrefAlign {
238238
abi: Align(4 bytes),

‎tests/ui/lint/clashing-extern-fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ mod hidden_niche {
436436

437437
fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize>>;
438438
//~^ WARN redeclared with a different signature
439-
//~| WARN block uses type `Option<UnsafeCell<NonZeroUsize>>`, which is not FFI-safe
439+
//~| WARN block uses type `Option<UnsafeCell<NonZero<usize>>>`, which is not FFI-safe
440440
}
441441
}
442442
}

‎tests/ui/lint/clashing-extern-fn.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoN
88
= note: enum has no representation hint
99
= note: `#[warn(improper_ctypes)]` on by default
1010

11-
warning: `extern` block uses type `Option<UnsafeCell<NonZeroUsize>>`, which is not FFI-safe
11+
warning: `extern` block uses type `Option<UnsafeCell<NonZero<usize>>>`, which is not FFI-safe
1212
--> $DIR/clashing-extern-fn.rs:437:46
1313
|
1414
LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize>>;
@@ -163,7 +163,7 @@ LL | fn non_zero_usize() -> core::num::NonZeroUsize;
163163
LL | fn non_zero_usize() -> usize;
164164
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
165165
|
166-
= note: expected `unsafe extern "C" fn() -> NonZeroUsize`
166+
= note: expected `unsafe extern "C" fn() -> NonZero<usize>`
167167
found `unsafe extern "C" fn() -> usize`
168168

169169
warning: `non_null_ptr` redeclared with a different signature
@@ -224,7 +224,7 @@ LL | fn hidden_niche_unsafe_cell() -> Option<UnsafeCell<NonZeroUsize
224224
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
225225
|
226226
= note: expected `unsafe extern "C" fn() -> usize`
227-
found `unsafe extern "C" fn() -> Option<UnsafeCell<NonZeroUsize>>`
227+
found `unsafe extern "C" fn() -> Option<UnsafeCell<NonZero<usize>>>`
228228

229229
warning: 19 warnings emitted
230230

‎tests/ui/lint/invalid_value.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ LL | let _val: NonNull<i32> = mem::uninitialized();
316316
= note: `std::ptr::NonNull<i32>` must be non-null
317317
= note: raw pointers must be initialized
318318

319-
error: the type `(NonZeroU32, i32)` does not permit zero-initialization
319+
error: the type `(NonZero<u32>, i32)` does not permit zero-initialization
320320
--> $DIR/invalid_value.rs:95:39
321321
|
322322
LL | let _val: (NonZeroU32, i32) = mem::zeroed();
@@ -325,9 +325,9 @@ LL | let _val: (NonZeroU32, i32) = mem::zeroed();
325325
| this code causes undefined behavior when executed
326326
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
327327
|
328-
= note: `std::num::NonZeroU32` must be non-null
328+
= note: `std::num::NonZero<u32>` must be non-null
329329

330-
error: the type `(NonZeroU32, i32)` does not permit being left uninitialized
330+
error: the type `(NonZero<u32>, i32)` does not permit being left uninitialized
331331
--> $DIR/invalid_value.rs:96:39
332332
|
333333
LL | let _val: (NonZeroU32, i32) = mem::uninitialized();
@@ -336,7 +336,7 @@ LL | let _val: (NonZeroU32, i32) = mem::uninitialized();
336336
| this code causes undefined behavior when executed
337337
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
338338
|
339-
= note: `std::num::NonZeroU32` must be non-null
339+
= note: `std::num::NonZero<u32>` must be non-null
340340
= note: integers must be initialized
341341

342342
error: the type `*const dyn Send` does not permit zero-initialization
@@ -417,7 +417,7 @@ LL | let _val: OneFruitNonZero = mem::zeroed();
417417
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
418418
|
419419
= note: `OneFruitNonZero` must be non-null
420-
note: because `std::num::NonZeroU32` must be non-null (in this field of the only potentially inhabited enum variant)
420+
note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant)
421421
--> $DIR/invalid_value.rs:39:12
422422
|
423423
LL | Banana(NonZeroU32),
@@ -433,7 +433,7 @@ LL | let _val: OneFruitNonZero = mem::uninitialized();
433433
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
434434
|
435435
= note: `OneFruitNonZero` must be non-null
436-
note: because `std::num::NonZeroU32` must be non-null (in this field of the only potentially inhabited enum variant)
436+
note: because `std::num::NonZero<u32>` must be non-null (in this field of the only potentially inhabited enum variant)
437437
--> $DIR/invalid_value.rs:39:12
438438
|
439439
LL | Banana(NonZeroU32),
@@ -603,7 +603,7 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
603603
|
604604
= note: references must be non-null
605605

606-
error: the type `NonZeroU32` does not permit zero-initialization
606+
error: the type `NonZero<u32>` does not permit zero-initialization
607607
--> $DIR/invalid_value.rs:154:32
608608
|
609609
LL | let _val: NonZeroU32 = mem::transmute(0);
@@ -612,7 +612,7 @@ LL | let _val: NonZeroU32 = mem::transmute(0);
612612
| this code causes undefined behavior when executed
613613
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
614614
|
615-
= note: `std::num::NonZeroU32` must be non-null
615+
= note: `std::num::NonZero<u32>` must be non-null
616616

617617
error: the type `NonNull<i32>` does not permit zero-initialization
618618
--> $DIR/invalid_value.rs:157:34

‎tests/ui/lint/lint-ctypes-enum.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ LL | fn nonzero_i128(x: Option<num::NonZeroI128>);
6161
|
6262
= note: 128-bit integers don't currently have a known stable ABI
6363

64-
error: `extern` block uses type `Option<TransparentUnion<NonZeroU8>>`, which is not FFI-safe
64+
error: `extern` block uses type `Option<TransparentUnion<NonZero<u8>>>`, which is not FFI-safe
6565
--> $DIR/lint-ctypes-enum.rs:86:28
6666
|
6767
LL | fn transparent_union(x: Option<TransparentUnion<num::NonZeroU8>>);
@@ -70,7 +70,7 @@ LL | fn transparent_union(x: Option<TransparentUnion<num::NonZeroU8>>);
7070
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
7171
= note: enum has no representation hint
7272

73-
error: `extern` block uses type `Option<Rust<NonZeroU8>>`, which is not FFI-safe
73+
error: `extern` block uses type `Option<Rust<NonZero<u8>>>`, which is not FFI-safe
7474
--> $DIR/lint-ctypes-enum.rs:88:20
7575
|
7676
LL | fn repr_rust(x: Option<Rust<num::NonZeroU8>>);
@@ -79,7 +79,7 @@ LL | fn repr_rust(x: Option<Rust<num::NonZeroU8>>);
7979
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
8080
= note: enum has no representation hint
8181

82-
error: `extern` block uses type `Result<(), NonZeroI32>`, which is not FFI-safe
82+
error: `extern` block uses type `Result<(), NonZero<i32>>`, which is not FFI-safe
8383
--> $DIR/lint-ctypes-enum.rs:89:20
8484
|
8585
LL | fn no_result(x: Result<(), num::NonZeroI32>);

‎tests/ui/mismatched_types/non_zero_assigned_something.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ error[E0308]: mismatched types
22
--> $DIR/non_zero_assigned_something.rs:2:35
33
|
44
LL | let _: std::num::NonZeroU64 = 1;
5-
| -------------------- ^ expected `NonZeroU64`, found integer
5+
| -------------------- ^ expected `NonZero<u64>`, found integer
66
| |
77
| expected due to this
88
|
9+
= note: expected struct `NonZero<u64>`
10+
found type `{integer}`
911
help: consider calling `NonZeroU64::new`
1012
|
1113
LL | let _: std::num::NonZeroU64 = NonZeroU64::new(1).unwrap();
@@ -15,11 +17,11 @@ error[E0308]: mismatched types
1517
--> $DIR/non_zero_assigned_something.rs:6:43
1618
|
1719
LL | let _: Option<std::num::NonZeroU64> = 1;
18-
| ---------------------------- ^ expected `Option<NonZeroU64>`, found integer
20+
| ---------------------------- ^ expected `Option<NonZero<u64>>`, found integer
1921
| |
2022
| expected due to this
2123
|
22-
= note: expected enum `Option<NonZeroU64>`
24+
= note: expected enum `Option<NonZero<u64>>`
2325
found type `{integer}`
2426
help: consider calling `NonZeroU64::new`
2527
|

‎tests/ui/numbers-arithmetic/not-suggest-float-literal.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ LL | x / 100.0
124124
= help: the trait `Div<{float}>` is not implemented for `u8`
125125
= help: the following other types implement trait `Div<Rhs>`:
126126
<u8 as Div>
127-
<u8 as Div<NonZeroU8>>
127+
<u8 as Div<NonZero<u8>>>
128128
<u8 as Div<&u8>>
129129
<&'a u8 as Div<u8>>
130130
<&u8 as Div<&u8>>

‎tests/ui/print_type_sizes/niche-filling.stdout

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ print-type-size field `.pre`: 1 bytes
1414
print-type-size field `.post`: 2 bytes
1515
print-type-size field `.val`: 4 bytes
1616
print-type-size variant `None`: 0 bytes
17-
print-type-size type: `MyOption<Union1<std::num::NonZeroU32>>`: 8 bytes, alignment: 4 bytes
17+
print-type-size type: `MyOption<Union1<std::num::NonZero<u32>>>`: 8 bytes, alignment: 4 bytes
1818
print-type-size discriminant: 4 bytes
1919
print-type-size variant `Some`: 4 bytes
2020
print-type-size field `.0`: 4 bytes
2121
print-type-size variant `None`: 0 bytes
22-
print-type-size type: `MyOption<Union2<std::num::NonZeroU32, std::num::NonZeroU32>>`: 8 bytes, alignment: 4 bytes
22+
print-type-size type: `MyOption<Union2<std::num::NonZero<u32>, std::num::NonZero<u32>>>`: 8 bytes, alignment: 4 bytes
2323
print-type-size discriminant: 4 bytes
2424
print-type-size variant `Some`: 4 bytes
2525
print-type-size field `.0`: 4 bytes
2626
print-type-size variant `None`: 0 bytes
27-
print-type-size type: `MyOption<Union2<std::num::NonZeroU32, u32>>`: 8 bytes, alignment: 4 bytes
27+
print-type-size type: `MyOption<Union2<std::num::NonZero<u32>, u32>>`: 8 bytes, alignment: 4 bytes
2828
print-type-size discriminant: 4 bytes
2929
print-type-size variant `Some`: 4 bytes
3030
print-type-size field `.0`: 4 bytes
@@ -53,22 +53,22 @@ print-type-size type: `MyOption<char>`: 4 bytes, alignment: 4 bytes
5353
print-type-size variant `Some`: 4 bytes
5454
print-type-size field `.0`: 4 bytes
5555
print-type-size variant `None`: 0 bytes
56-
print-type-size type: `MyOption<std::num::NonZeroU32>`: 4 bytes, alignment: 4 bytes
56+
print-type-size type: `MyOption<std::num::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
5757
print-type-size variant `Some`: 4 bytes
5858
print-type-size field `.0`: 4 bytes
5959
print-type-size variant `None`: 0 bytes
60-
print-type-size type: `Union1<std::num::NonZeroU32>`: 4 bytes, alignment: 4 bytes
60+
print-type-size type: `Union1<std::num::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
6161
print-type-size variant `Union1`: 4 bytes
6262
print-type-size field `.a`: 4 bytes
63-
print-type-size type: `Union2<std::num::NonZeroU32, std::num::NonZeroU32>`: 4 bytes, alignment: 4 bytes
63+
print-type-size type: `Union2<std::num::NonZero<u32>, std::num::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
6464
print-type-size variant `Union2`: 4 bytes
6565
print-type-size field `.a`: 4 bytes
6666
print-type-size field `.b`: 4 bytes, offset: 0 bytes, alignment: 4 bytes
67-
print-type-size type: `Union2<std::num::NonZeroU32, u32>`: 4 bytes, alignment: 4 bytes
67+
print-type-size type: `Union2<std::num::NonZero<u32>, u32>`: 4 bytes, alignment: 4 bytes
6868
print-type-size variant `Union2`: 4 bytes
6969
print-type-size field `.a`: 4 bytes
7070
print-type-size field `.b`: 4 bytes, offset: 0 bytes, alignment: 4 bytes
71-
print-type-size type: `std::num::NonZeroU32`: 4 bytes, alignment: 4 bytes
71+
print-type-size type: `std::num::NonZero<u32>`: 4 bytes, alignment: 4 bytes
7272
print-type-size field `.0`: 4 bytes
7373
print-type-size type: `Enum4<(), (), (), MyOption<u8>>`: 2 bytes, alignment: 1 bytes
7474
print-type-size variant `Four`: 2 bytes

‎tests/ui/traits/issue-77982.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(
4646
= note: multiple `impl`s satisfying `u32: From<_>` found in the `core` crate:
4747
- impl From<Char> for u32;
4848
- impl From<Ipv4Addr> for u32;
49-
- impl From<NonZeroU32> for u32;
49+
- impl From<NonZero<u32>> for u32;
5050
- impl From<bool> for u32;
5151
- impl From<char> for u32;
5252
- impl From<u16> for u32;

‎tests/ui/try-trait/bad-interconversion.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | Ok(Err(123_i32)?)
1111
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
1212
= help: the following other types implement trait `From<T>`:
1313
<u8 as From<bool>>
14-
<u8 as From<NonZeroU8>>
14+
<u8 as From<NonZero<u8>>>
1515
<u8 as From<Char>>
1616
= note: required for `Result<u64, u8>` to implement `FromResidual<Result<Infallible, i32>>`
1717

0 commit comments

Comments
 (0)
This repository has been archived.