-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update
borrow_as_ptr
to suggest &raw
when the MSRV allows it
- Loading branch information
Showing
6 changed files
with
84 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![warn(clippy::borrow_as_ptr)] | ||
#![allow(clippy::useless_vec)] | ||
|
||
fn a() -> i32 { | ||
0 | ||
} | ||
|
||
#[clippy::msrv = "1.82"] | ||
fn main() { | ||
let val = 1; | ||
let _p = &raw const val; | ||
let _p = &0 as *const i32; | ||
let _p = &a() as *const i32; | ||
let vec = vec![1]; | ||
let _p = &vec.len() as *const usize; | ||
|
||
let mut val_mut = 1; | ||
let _p_mut = &raw mut val_mut; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![warn(clippy::borrow_as_ptr)] | ||
#![allow(clippy::useless_vec)] | ||
|
||
fn a() -> i32 { | ||
0 | ||
} | ||
|
||
#[clippy::msrv = "1.82"] | ||
fn main() { | ||
let val = 1; | ||
let _p = &val as *const i32; | ||
let _p = &0 as *const i32; | ||
let _p = &a() as *const i32; | ||
let vec = vec![1]; | ||
let _p = &vec.len() as *const usize; | ||
|
||
let mut val_mut = 1; | ||
let _p_mut = &mut val_mut as *mut i32; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: borrow as raw pointer | ||
--> tests/ui/borrow_as_ptr_raw_ref.rs:11:14 | ||
| | ||
LL | let _p = &val as *const i32; | ||
| ^^^^^^^^^^^^^^^^^^ help: try: `&raw const val` | ||
| | ||
= note: `-D clippy::borrow-as-ptr` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` | ||
|
||
error: borrow as raw pointer | ||
--> tests/ui/borrow_as_ptr_raw_ref.rs:18:18 | ||
| | ||
LL | let _p_mut = &mut val_mut as *mut i32; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&raw mut val_mut` | ||
|
||
error: aborting due to 2 previous errors | ||
|