Skip to content

Commit f683b96

Browse files
committed
Highlight lint bug.
1 parent 01ec46f commit f683b96

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/rustc_lint/src/types.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ fn get_nullable_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>>
10561056

10571057
/// Check if this enum can be safely exported based on the "nullable pointer optimization". If it
10581058
/// can, return the type that `ty` can be safely converted to, otherwise return `None`.
1059-
/// Currently restricted to function pointers, boxes, references, `core::num::NonZero*`,
1059+
/// Currently restricted to function pointers, boxes, references, `core::num::NonZero`,
10601060
/// `core::ptr::NonNull`, and `#[repr(transparent)]` newtypes.
10611061
/// FIXME: This duplicates code in codegen.
10621062
pub(crate) fn repr_nullable_ptr<'tcx>(
@@ -1102,7 +1102,13 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
11021102
return Some(get_nullable_type(tcx, field_ty).unwrap());
11031103
}
11041104
WrappingRange { start: 1, .. } => {
1105-
return Some(get_nullable_type(tcx, field_ty).unwrap());
1105+
let nullable_type = get_nullable_type(tcx, field_ty);
1106+
1107+
if nullable_type.is_none() {
1108+
bug!("cannot get nullable type for field_ty {field_ty:?}");
1109+
}
1110+
1111+
return Some(nullable_type.unwrap());
11061112
}
11071113
WrappingRange { start, end } => {
11081114
unreachable!("Unhandled start and end range: ({}, {})", start, end)

library/core/src/num/nonzero.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl_zeroable_primitive!(
103103
/// ```
104104
#[unstable(feature = "generic_nonzero", issue = "120257")]
105105
#[repr(transparent)]
106+
#[rustc_nonnull_optimization_guaranteed]
106107
#[rustc_diagnostic_item = "NonZero"]
107108
pub struct NonZero<T: ZeroablePrimitive>(T::NonZeroInner);
108109

0 commit comments

Comments
 (0)