Skip to content

Commit 1b3ddae

Browse files
committed
Rename lint to cast_slice_reference_from_raw_parts
1 parent 7f3989c commit 1b3ddae

9 files changed

+29
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3627,6 +3627,7 @@ Released 2018-09-13
36273627
[`cast_ref_to_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_ref_to_mut
36283628
[`cast_sign_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss
36293629
[`cast_slice_different_sizes`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_different_sizes
3630+
[`cast_slice_reference_from_raw_parts`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_reference_from_raw_parts
36303631
[`char_lit_as_u8`]: https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8
36313632
[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp
36323633
[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp
@@ -3998,7 +3999,6 @@ Released 2018-09-13
39983999
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
39994000
[`range_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_step_by_zero
40004001
[`range_zip_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
4001-
[`raw_slice_pointer_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#raw_slice_pointer_cast
40024002
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
40034003
[`rc_clone_in_vec_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_clone_in_vec_init
40044004
[`rc_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex

clippy_lints/src/casts/raw_slice_pointer_cast.rs renamed to clippy_lints/src/casts/cast_slice_reference_from_raw_parts.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::source::{snippet, snippet_with_applicability};
2+
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::{match_def_path, meets_msrv, msrvs, paths};
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
@@ -8,7 +8,7 @@ use rustc_lint::LateContext;
88
use rustc_middle::ty::{self, Ty};
99
use rustc_semver::RustcVersion;
1010

11-
use super::RAW_SLICE_POINTER_CAST;
11+
use super::CAST_SLICE_REFERENCE_FROM_RAW_PARTS;
1212

1313
enum RawPartsKind {
1414
Immutable,
@@ -47,16 +47,17 @@ pub(super) fn check(
4747
};
4848
let span = expr.span;
4949
let mut applicability = Applicability::MachineApplicable;
50-
let func_snippet = snippet_with_applicability(cx, fun.span, func, &mut applicability);
51-
let ptr = snippet(cx, ptr_arg.span, "ptr");
52-
let len = snippet(cx, len_arg.span, "len");
53-
span_lint_and_sugg(cx,
54-
RAW_SLICE_POINTER_CAST,
50+
let ptr = snippet_with_applicability(cx, ptr_arg.span, "ptr", &mut applicability);
51+
let len = snippet_with_applicability(cx, len_arg.span, "len", &mut applicability);
52+
span_lint_and_sugg(
53+
cx,
54+
CAST_SLICE_REFERENCE_FROM_RAW_PARTS,
5555
span,
56-
&format!("casting the result of `{}` to {cast_to}", func_snippet),
56+
&format!("casting the result of `{func}` to {cast_to}"),
5757
"replace with",
5858
format!("core::ptr::slice_{func}({ptr}, {len})"),
59-
applicability);
59+
applicability
60+
);
6061
}
6162
}
6263
}

clippy_lints/src/casts/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod fn_to_numeric_cast;
1515
mod fn_to_numeric_cast_any;
1616
mod fn_to_numeric_cast_with_truncation;
1717
mod ptr_as_ptr;
18-
mod raw_slice_pointer_cast;
18+
mod cast_slice_reference_from_raw_parts;
1919
mod unnecessary_cast;
2020
mod utils;
2121

@@ -590,9 +590,9 @@ declare_clippy_lint! {
590590
/// ```
591591
/// [safety requirements]: https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html#safety
592592
#[clippy::version = "1.64.0"]
593-
pub RAW_SLICE_POINTER_CAST,
593+
pub CAST_SLICE_REFERENCE_FROM_RAW_PARTS,
594594
suspicious,
595-
"casting a raw slice to a slice pointer"
595+
"casting a slice created from a pointer and length to a slice pointer"
596596
}
597597

598598
pub struct Casts {
@@ -627,6 +627,7 @@ impl_lint_pass!(Casts => [
627627
AS_UNDERSCORE,
628628
BORROW_AS_PTR,
629629
RAW_SLICE_POINTER_CAST
630+
CAST_SLICE_REFERENCE_FROM_RAW_PARTS
630631
]);
631632

632633
impl<'tcx> LateLintPass<'tcx> for Casts {
@@ -651,7 +652,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
651652
if unnecessary_cast::check(cx, expr, cast_expr, cast_from, cast_to) {
652653
return;
653654
}
654-
raw_slice_pointer_cast::check(cx, expr, cast_expr, cast_to, self.msrv);
655+
cast_slice_reference_from_raw_parts::check(cx, expr, cast_expr, cast_to, self.msrv);
655656
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
656657
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);
657658
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_expr, cast_from, cast_to);

clippy_lints/src/lib.register_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
2525
LintId::of(casts::CAST_ENUM_TRUNCATION),
2626
LintId::of(casts::CAST_REF_TO_MUT),
2727
LintId::of(casts::CAST_SLICE_DIFFERENT_SIZES),
28+
LintId::of(casts::CAST_SLICE_REFERENCE_FROM_RAW_PARTS),
2829
LintId::of(casts::CHAR_LIT_AS_U8),
2930
LintId::of(casts::FN_TO_NUMERIC_CAST),
3031
LintId::of(casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
31-
LintId::of(casts::RAW_SLICE_POINTER_CAST),
3232
LintId::of(casts::UNNECESSARY_CAST),
3333
LintId::of(collapsible_if::COLLAPSIBLE_ELSE_IF),
3434
LintId::of(collapsible_if::COLLAPSIBLE_IF),

clippy_lints/src/lib.register_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ store.register_lints(&[
7777
casts::CAST_REF_TO_MUT,
7878
casts::CAST_SIGN_LOSS,
7979
casts::CAST_SLICE_DIFFERENT_SIZES,
80+
casts::CAST_SLICE_REFERENCE_FROM_RAW_PARTS,
8081
casts::CHAR_LIT_AS_U8,
8182
casts::FN_TO_NUMERIC_CAST,
8283
casts::FN_TO_NUMERIC_CAST_ANY,
8384
casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
8485
casts::PTR_AS_PTR,
85-
casts::RAW_SLICE_POINTER_CAST,
8686
casts::UNNECESSARY_CAST,
8787
checked_conversions::CHECKED_CONVERSIONS,
8888
cognitive_complexity::COGNITIVE_COMPLEXITY,

clippy_lints/src/lib.register_suspicious.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
1111
LintId::of(casts::CAST_ABS_TO_UNSIGNED),
1212
LintId::of(casts::CAST_ENUM_CONSTRUCTOR),
1313
LintId::of(casts::CAST_ENUM_TRUNCATION),
14-
LintId::of(casts::RAW_SLICE_POINTER_CAST),
14+
LintId::of(casts::CAST_SLICE_REFERENCE_FROM_RAW_PARTS),
1515
LintId::of(crate_in_macro_def::CRATE_IN_MACRO_DEF),
1616
LintId::of(drop_forget_ref::DROP_NON_DROP),
1717
LintId::of(drop_forget_ref::FORGET_NON_DROP),

tests/ui/cast_raw_slice_pointer_cast.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::raw_slice_pointer_cast)]
2+
#![warn(clippy::cast_slice_reference_from_raw_parts)]
33

44
#[allow(unused_imports, unused_unsafe)]
55
fn main() {

tests/ui/cast_raw_slice_pointer_cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::raw_slice_pointer_cast)]
2+
#![warn(clippy::cast_slice_reference_from_raw_parts)]
33

44
#[allow(unused_imports, unused_unsafe)]
55
fn main() {

tests/ui/cast_raw_slice_pointer_cast.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
error: casting the result of `std::slice::from_raw_parts` to *const [u8]
1+
error: casting the result of `from_raw_parts` to *const [u8]
22
--> $DIR/cast_raw_slice_pointer_cast.rs:9:35
33
|
44
LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) as *const [u8] };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)`
66
|
7-
= note: `-D clippy::raw-slice-pointer-cast` implied by `-D warnings`
7+
= note: `-D clippy::cast-slice-reference-from-raw-parts` implied by `-D warnings`
88

9-
error: casting the result of `std::slice::from_raw_parts_mut` to *mut [u8]
9+
error: casting the result of `from_raw_parts_mut` to *mut [u8]
1010
--> $DIR/cast_raw_slice_pointer_cast.rs:10:35
1111
|
1212
LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts_mut(mptr, 1) as *mut [u8] };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts_mut(mptr, 1)`
1414

15-
error: casting the result of `std::slice::from_raw_parts` to *const [u8]
15+
error: casting the result of `from_raw_parts` to *const [u8]
1616
--> $DIR/cast_raw_slice_pointer_cast.rs:11:26
1717
|
1818
LL | let _: *const [u8] = unsafe { std::slice::from_raw_parts(ptr, 1) } as *const [u8];
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)`
2020

21-
error: casting the result of `slice::from_raw_parts` to *const [u8]
21+
error: casting the result of `from_raw_parts` to *const [u8]
2222
--> $DIR/cast_raw_slice_pointer_cast.rs:14:30
2323
|
2424
LL | let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8];
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)`
2626

27-
error: casting the result of `one::from_raw_parts` to *const [u8]
27+
error: casting the result of `from_raw_parts` to *const [u8]
2828
--> $DIR/cast_raw_slice_pointer_cast.rs:16:30
2929
|
3030
LL | let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8];
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)`
3232

33-
error: casting the result of `slice::from_raw_parts` to *const [u8]
33+
error: casting the result of `from_raw_parts` to *const [u8]
3434
--> $DIR/cast_raw_slice_pointer_cast.rs:20:30
3535
|
3636
LL | let _: *const [u8] = unsafe { slice::from_raw_parts(ptr, 1) } as *const [u8];
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `core::ptr::slice_from_raw_parts(ptr, 1)`
3838

39-
error: casting the result of `one::from_raw_parts` to *const [u8]
39+
error: casting the result of `from_raw_parts` to *const [u8]
4040
--> $DIR/cast_raw_slice_pointer_cast.rs:22:30
4141
|
4242
LL | let _: *const [u8] = unsafe { one::from_raw_parts(ptr, 1) } as *const [u8];

0 commit comments

Comments
 (0)