Skip to content

Commit 78b1000

Browse files
committed
Auto merge of #156832 - hanna-kruppe:consistent-strict-provenance-lints, r=<try>
library: use strict provenance lints consistently try-job: dist-ohos-armv7
2 parents 39e7b2a + 732998a commit 78b1000

25 files changed

Lines changed: 51 additions & 29 deletions

File tree

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
// Lints:
7474
#![deny(unsafe_op_in_unsafe_fn)]
7575
#![deny(fuzzy_provenance_casts)]
76+
#![deny(lossy_provenance_casts)]
7677
#![warn(deprecated_in_future)]
7778
#![warn(missing_debug_implementations)]
7879
#![warn(missing_docs)]

library/alloctests/benches/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(strict_provenance_lints)]
88
#![feature(test)]
99
#![deny(fuzzy_provenance_casts)]
10+
#![deny(lossy_provenance_casts)]
1011

1112
extern crate test;
1213

library/alloctests/tests/boxed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ fn box_clone_from_ptr_stability() {
4747
for size in (0..8).map(|i| 2usize.pow(i)) {
4848
let control = vec![Dummy { _data: 42 }; size].into_boxed_slice();
4949
let mut copy = vec![Dummy { _data: 84 }; size].into_boxed_slice();
50-
let copy_raw = copy.as_ptr() as usize;
50+
let copy_raw = copy.as_ptr();
5151
copy.clone_from(&control);
52-
assert_eq!(copy.as_ptr() as usize, copy_raw);
52+
assert_eq!(copy.as_ptr(), copy_raw);
5353
}
5454
}
5555

library/alloctests/tests/heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn check_overalign_requests<T: Allocator>(allocator: T) {
2525
.collect();
2626
for &ptr in &pointers {
2727
assert_eq!(
28-
(ptr.as_non_null_ptr().as_ptr() as usize) % align,
28+
ptr.as_non_null_ptr().as_ptr().addr() % align,
2929
0,
3030
"Got a pointer less aligned than requested"
3131
)

library/alloctests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#![feature(ptr_cast_slice)]
4545
#![allow(internal_features)]
4646
#![deny(fuzzy_provenance_casts)]
47+
#![deny(lossy_provenance_casts)]
4748
#![deny(unsafe_op_in_unsafe_fn)]
4849

4950
extern crate alloc;

library/alloctests/tests/sort/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ fn self_cmp<T: Ord + Clone + Debug, S: Sort>(
746746
pattern_fn(len).into_iter().map(|val| type_into_fn(val)).collect::<Vec<_>>();
747747

748748
let comparison_fn = |a: &T, b: &T| {
749-
assert_ne!(a as *const T as usize, b as *const T as usize);
749+
assert_ne!(a as *const T, b as *const T);
750750
a.cmp(b)
751751
};
752752

library/alloctests/tests/vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ fn test_into_iter_zst() {
11101110
struct AlignedZstWithDrop([u64; 0]);
11111111
impl Drop for AlignedZstWithDrop {
11121112
fn drop(&mut self) {
1113-
let addr = self as *mut _ as usize;
1113+
let addr = (self as *mut Self).addr();
11141114
assert!(hint::black_box(addr) % align_of::<u64>() == 0);
11151115
}
11161116
}
@@ -1356,10 +1356,10 @@ fn overaligned_allocations() {
13561356
for i in 0..0x1000 {
13571357
v.reserve_exact(i);
13581358
assert!(v[0].0 == 273);
1359-
assert!(v.as_ptr() as usize & 0xff == 0);
1359+
assert!(v.as_ptr().addr() & 0xff == 0);
13601360
v.shrink_to_fit();
13611361
assert!(v[0].0 == 273);
1362-
assert!(v.as_ptr() as usize & 0xff == 0);
1362+
assert!(v.as_ptr().addr() & 0xff == 0);
13631363
}
13641364
}
13651365

@@ -2574,7 +2574,7 @@ fn test_box_zero_allocator() {
25742574

25752575
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
25762576
if layout.size() == 0 {
2577-
let addr = ptr.as_ptr() as usize;
2577+
let addr = ptr.as_ptr().addr();
25782578
let mut state = self.state.borrow_mut();
25792579
std::println!("freeing {addr}");
25802580
assert!(state.0.remove(&addr), "ZST free that wasn't allocated");

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![deny(rust_2021_incompatible_or_patterns)]
8181
#![deny(unsafe_op_in_unsafe_fn)]
8282
#![deny(fuzzy_provenance_casts)]
83+
#![deny(lossy_provenance_casts)]
8384
#![warn(deprecated_in_future)]
8485
#![warn(missing_debug_implementations)]
8586
#![warn(missing_docs)]

library/core/src/ptr/const_ptr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl<T: PointeeSized> *const T {
183183
/// [`with_exposed_provenance`]: with_exposed_provenance
184184
#[inline(always)]
185185
#[stable(feature = "exposed_provenance", since = "1.84.0")]
186+
#[expect(lossy_provenance_casts, reason = "this *is* the replacement")]
186187
pub fn expose_provenance(self) -> usize {
187188
self.cast::<()>() as usize
188189
}

library/core/src/ptr/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,21 +2618,21 @@ impl<F: FnPtr> Ord for F {
26182618
#[stable(feature = "fnptr_impls", since = "1.4.0")]
26192619
impl<F: FnPtr> hash::Hash for F {
26202620
fn hash<HH: hash::Hasher>(&self, state: &mut HH) {
2621-
state.write_usize(self.addr() as _)
2621+
state.write_usize(self.addr().addr())
26222622
}
26232623
}
26242624

26252625
#[stable(feature = "fnptr_impls", since = "1.4.0")]
26262626
impl<F: FnPtr> fmt::Pointer for F {
26272627
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2628-
fmt::pointer_fmt_inner(self.addr() as _, f)
2628+
fmt::pointer_fmt_inner(self.addr().addr(), f)
26292629
}
26302630
}
26312631

26322632
#[stable(feature = "fnptr_impls", since = "1.4.0")]
26332633
impl<F: FnPtr> fmt::Debug for F {
26342634
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2635-
fmt::pointer_fmt_inner(self.addr() as _, f)
2635+
fmt::pointer_fmt_inner(self.addr().addr(), f)
26362636
}
26372637
}
26382638

0 commit comments

Comments
 (0)