Skip to content
Myr

Resolve ptr_cast_constness pedantic clippy lint

Before adoption: this commit came in with the history the project adopted, so no landing records it.

warning: `as` casting between raw pointers while changing only its constness --> src/error.rs:782:32 | 782 | NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object) as *mut E) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness = note: `-W clippy::ptr-cast-constness` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::ptr_cast_constness)]` warning: `as` casting between raw pointers while changing only its constness --> src/error.rs:819:40 | 819 | NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object) as *mut E) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness warning: `as` casting between raw pointers while changing only its constness --> src/ptr.rs:116:9 | 116 | self.ptr.as_ptr() as *const T | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `self.ptr.as_ptr().cast_const()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness warning: `as` casting between raw pointers while changing only its constness --> tests/test_ensure.rs:540:30 | 540 | let test = || Ok(ensure!(0 as *const () as *mut _ == 1 as *mut ())); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `(0 as *const ()).cast_mut()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness = note: `-W clippy::ptr-cast-constness` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::ptr_cast_constness)]`

authored by David Tolnay · committed by David Tolnay · parent a14e2ca · Browse files · 3 files+4 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+4 added−3 removed

  • tests:+1 added−0 removed
  • other:+3 added−3 removed

3 files+4 added−3 removed

modified:src/error.rs+2 added-2 removed
777 unmodified lines
778{779 // Attach E's native StdError vtable onto a pointer to self._object.780 let unerased_ref = e.cast::<ErrorImpl<E>>();781 Ref::from_raw(unsafe {782 NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object) as *mut E)782 NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut())783 })784}785786// Safety: requires layout of *e to match ErrorImpl<E>.
28 unmodified lines
815 // pointer to its E field.816 let unerased_ref = e.cast::<ErrorImpl<E>>();817 Some(818 Ref::from_raw(unsafe {819 NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object) as *mut E)819 NonNull::new_unchecked(ptr::addr_of!((*unerased_ref.as_ptr())._object).cast_mut())820 })821 .cast::<()>(),822 )823 } else {
263 unmodified lines
modified:src/ptr.rs+1 added-1 removed
111 unmodified lines
112 }113 }114115 pub fn as_ptr(self) -> *const T {116 self.ptr.as_ptr() as *const T116 self.ptr.as_ptr().cast_const()117 }118119 pub unsafe fn deref(self) -> &'a T {120 unsafe { &*self.ptr.as_ptr() }
67 unmodified lines
modified:tests/test_ensure.rs+1 added
14 unmodified lines
15 clippy::match_bool,16 clippy::needless_else,17 clippy::never_loop,18 clippy::overly_complex_bool_expr,19 clippy::ptr_cast_constness,20 clippy::redundant_closure_call,21 clippy::redundant_pattern_matching,22 clippy::too_many_lines,23 clippy::uninlined_format_args,
733 unmodified lines