Skip to content

Commit 175884d

Browse files
committed
Rename lint to cast_slice_reference_from_raw_parts
1 parent 83e63a1 commit 175884d

9 files changed

+29
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3481,6 +3481,7 @@ Released 2018-09-13
34813481
[`cast_ref_to_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_ref_to_mut
34823482
[`cast_sign_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss
34833483
[`cast_slice_different_sizes`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_different_sizes
3484+
[`cast_slice_reference_from_raw_parts`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_reference_from_raw_parts
34843485
[`char_lit_as_u8`]: https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8
34853486
[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp
34863487
[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp
@@ -3842,7 +3843,6 @@ Released 2018-09-13
38423843
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
38433844
[`range_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_step_by_zero
38443845
[`range_zip_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
3845-
[`raw_slice_pointer_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#raw_slice_pointer_cast
38463846
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
38473847
[`rc_clone_in_vec_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_clone_in_vec_init
38483848
[`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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod fn_to_numeric_cast;
1313
mod fn_to_numeric_cast_any;
1414
mod fn_to_numeric_cast_with_truncation;
1515
mod ptr_as_ptr;
16-
mod raw_slice_pointer_cast;
16+
mod cast_slice_reference_from_raw_parts;
1717
mod unnecessary_cast;
1818
mod utils;
1919

@@ -529,9 +529,9 @@ declare_clippy_lint! {
529529
/// ```
530530
/// [safety requirements]: https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html#safety
531531
#[clippy::version = "1.64.0"]
532-
pub RAW_SLICE_POINTER_CAST,
532+
pub CAST_SLICE_REFERENCE_FROM_RAW_PARTS,
533533
suspicious,
534-
"casting a raw slice to a slice pointer"
534+
"casting a slice created from a pointer and length to a slice pointer"
535535
}
536536

537537
pub struct Casts {
@@ -563,7 +563,7 @@ impl_lint_pass!(Casts => [
563563
CAST_ENUM_TRUNCATION,
564564
CAST_ENUM_CONSTRUCTOR,
565565
CAST_ABS_TO_UNSIGNED,
566-
RAW_SLICE_POINTER_CAST
566+
CAST_SLICE_REFERENCE_FROM_RAW_PARTS
567567
]);
568568

569569
impl<'tcx> LateLintPass<'tcx> for Casts {
@@ -588,7 +588,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
588588
if unnecessary_cast::check(cx, expr, cast_expr, cast_from, cast_to) {
589589
return;
590590
}
591-
raw_slice_pointer_cast::check(cx, expr, cast_expr, cast_to, self.msrv);
591+
cast_slice_reference_from_raw_parts::check(cx, expr, cast_expr, cast_to, self.msrv);
592592
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
593593
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);
594594
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
@@ -28,10 +28,10 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
2828
LintId::of(casts::CAST_ENUM_TRUNCATION),
2929
LintId::of(casts::CAST_REF_TO_MUT),
3030
LintId::of(casts::CAST_SLICE_DIFFERENT_SIZES),
31+
LintId::of(casts::CAST_SLICE_REFERENCE_FROM_RAW_PARTS),
3132
LintId::of(casts::CHAR_LIT_AS_U8),
3233
LintId::of(casts::FN_TO_NUMERIC_CAST),
3334
LintId::of(casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
34-
LintId::of(casts::RAW_SLICE_POINTER_CAST),
3535
LintId::of(casts::UNNECESSARY_CAST),
3636
LintId::of(collapsible_if::COLLAPSIBLE_ELSE_IF),
3737
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
@@ -81,12 +81,12 @@ store.register_lints(&[
8181
casts::CAST_REF_TO_MUT,
8282
casts::CAST_SIGN_LOSS,
8383
casts::CAST_SLICE_DIFFERENT_SIZES,
84+
casts::CAST_SLICE_REFERENCE_FROM_RAW_PARTS,
8485
casts::CHAR_LIT_AS_U8,
8586
casts::FN_TO_NUMERIC_CAST,
8687
casts::FN_TO_NUMERIC_CAST_ANY,
8788
casts::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
8889
casts::PTR_AS_PTR,
89-
casts::RAW_SLICE_POINTER_CAST,
9090
casts::UNNECESSARY_CAST,
9191
checked_conversions::CHECKED_CONVERSIONS,
9292
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)