Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
// return `Bound::Excluded`. (And we have tests checking that we
// handle the attribute correctly.)
// We don't add a span since users cannot declare such types anyway.
(Bound::Included(lo), _) if lo > 0 => {
(Bound::Included(lo), Bound::Included(hi)) if 0 < lo && lo < hi => {
return Some((format!("`{}` must be non-null", ty), None));
}
(Bound::Included(lo), Bound::Unbounded) if 0 < lo => {
return Some((format!("`{}` must be non-null", ty), None));
}
(Bound::Included(_), _) | (_, Bound::Included(_))
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/lint/invalid_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ enum TwoUninhabited {
B(Void),
}

#[rustc_layout_scalar_valid_range_start(254)]
#[rustc_layout_scalar_valid_range_end(1)]
pub(crate) struct WrapAroundRange(u8);

#[allow(unused)]
fn generic<T: 'static>() {
unsafe {
Expand Down Expand Up @@ -131,6 +135,9 @@ fn main() {
let _val: *const [()] = mem::zeroed();
let _val: *const [()] = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized

let _val: WrapAroundRange = mem::zeroed();
let _val: WrapAroundRange = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized

// Things where 0 is okay due to rustc implementation details,
// but that are not guaranteed to keep working.
let _val: Result<i32, i32> = mem::zeroed();
Expand Down
Loading