From 831411ddd5ba5cdc19d186c84e4dfcaab58f39ee Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 10 Dec 2025 20:58:00 +0000 Subject: [PATCH] fix: clippy::ref_as_ptr https://rust-lang.github.io/rust-clippy/master/index.html#ref_as_ptr Part of #12136 --- src/ast.rs | 4 ++-- src/complete.rs | 4 ++-- src/global_safety.rs | 6 ++---- src/io.rs | 4 ++-- src/parse_execution.rs | 2 +- src/parser.rs | 4 ++-- src/reader/reader.rs | 2 +- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index a234d075a..0412bf0b2 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -242,8 +242,8 @@ pub fn is_same_node(lhs: &dyn Node, rhs: &dyn Node) -> bool { // Note this is performance-sensitive. // Different base pointers => not the same. - let lptr = lhs as *const dyn Node as *const (); - let rptr = rhs as *const dyn Node as *const (); + let lptr = std::ptr::from_ref(lhs) as *const (); + let rptr = std::ptr::from_ref(rhs) as *const (); if !std::ptr::eq(lptr, rptr) { return false; } diff --git a/src/complete.rs b/src/complete.rs index 7a9d02fbb..b938ec837 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -1879,8 +1879,8 @@ fn apply_var_assignments>( let vars = parser.vars(); assert_eq!( - self.ctx.vars() as *const _ as *const (), - vars as *const _ as *const (), + std::ptr::from_ref(self.ctx.vars()) as *const (), + std::ptr::from_ref(vars) as *const (), "Don't know how to tab complete with a parser but a different variable set" ); diff --git a/src/global_safety.rs b/src/global_safety.rs index 98c598e51..7ab8448dc 100644 --- a/src/global_safety.rs +++ b/src/global_safety.rs @@ -35,9 +35,7 @@ fn clone(&self) -> Self { impl AtomicRef { pub const fn new(value: &'static &'static T) -> Self { - Self(AtomicPtr::new( - value as *const &'static T as *mut &'static T, - )) + Self(AtomicPtr::new(std::ptr::from_ref(value) as *mut &'static T)) } pub fn load(&self) -> &'static T { @@ -46,7 +44,7 @@ pub fn load(&self) -> &'static T { pub fn store(&self, value: &'static &'static T) { self.0.store( - value as *const &'static T as *mut &'static T, + std::ptr::from_ref(value) as *mut &'static T, Ordering::Relaxed, ) } diff --git a/src/io.rs b/src/io.rs index 9c888150b..7d78e5959 100644 --- a/src/io.rs +++ b/src/io.rs @@ -494,11 +494,11 @@ pub fn new() -> Self { } pub fn remove(&mut self, element: &dyn IoData) { // Discard vtable pointers when comparing. - let e1 = element as *const dyn IoData as *const (); + let e1 = std::ptr::from_ref(element) as *const (); let idx = self .0 .iter() - .position(|e2| Arc::as_ref(e2) as *const dyn IoData as *const () == e1) + .position(|e2| Arc::as_ptr(e2) as *const () == e1) .expect("Element not found"); self.0.remove(idx); } diff --git a/src/parse_execution.rs b/src/parse_execution.rs index 578db3bb2..5c30a6778 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -1525,7 +1525,7 @@ fn run_1_job( // Save the executing node. let _saved_node = self .line_counter - .scoped_set(job_node as *const _, |s| &mut s.node); + .scoped_set(std::ptr::from_ref(job_node), |s| &mut s.node); // Profiling support. let profile_item_id = ctx.parser().create_profile_item(); diff --git a/src/parser.rs b/src/parser.rs index f16a271a4..a3500b0cd 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2208,7 +2208,7 @@ fn test_line_counter() { assert_eq!(line_counter.line_offset_of_node(), None); for (idx, &node) in pipelines.iter().enumerate() { - line_counter.node = node as *const _; + line_counter.node = std::ptr::from_ref(node); assert_eq!( line_counter.source_offset_of_node(), Some(node.source_range().start()) @@ -2217,7 +2217,7 @@ fn test_line_counter() { } for (idx, &node) in pipelines.iter().enumerate().rev() { - line_counter.node = node as *const _; + line_counter.node = std::ptr::from_ref(node); assert_eq!( line_counter.source_offset_of_node(), Some(node.source_range().start()) diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 6398b7601..b8691aa8f 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -1633,7 +1633,7 @@ fn combine_command_and_autosuggestion( if !last_token_contains_uppercase { // Use the autosuggestion's case. let start: usize = unsafe { - (line.as_char_slice().first().unwrap() as *const char) + std::ptr::from_ref(line.as_char_slice().first().unwrap()) .offset_from(&cmdline.as_char_slice()[0]) } .try_into()