Skip to content

Commit 0bbe812

Browse files
committed
use is_integer_const, add split_off on sym.rs
1 parent 872de81 commit 0bbe812

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

clippy_lints/src/unnecessary_split_off.rs

Lines changed: 4 additions & 5 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::sym;
2+
use clippy_utils::{is_integer_const, sym, ty};
33
use rustc_errors::Applicability;
44
use rustc_hir::{Expr, ExprKind};
55
use rustc_lint::{LateContext, LateLintPass};
@@ -30,15 +30,14 @@ declare_lint_pass!(UnnecessarySplitOff => [UNNECESSARY_SPLIT_OFF]);
3030
impl<'tcx> LateLintPass<'tcx> for UnnecessarySplitOff {
3131
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
3232
if let ExprKind::MethodCall(path, value, args, span) = &expr.kind
33-
// FIXME: sym::split_off does not exist, but this still triggers the lint to use it.
34-
&& path.ident.name.as_str() == "split_off"
33+
&& path.ident.name == sym::split_off
3534
{
3635
let ty = cx.typeck_results().expr_ty(value);
37-
if clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Vec) {
36+
if ty::is_type_diagnostic_item(cx, ty, sym::Vec) {
3837
let &[arg] = args else {
3938
return;
4039
};
41-
if clippy_utils::is_integer_literal(arg, 0) || clippy_utils::is_integer_const(cx, arg, 0) {
40+
if is_integer_const(cx, arg, 0) {
4241
span_lint_and_sugg(
4342
cx,
4443
UNNECESSARY_SPLIT_OFF,

clippy_utils/src/sym.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ macro_rules! generate {
3434
//
3535
// `cargo dev fmt` ensures that the content of the `generate!()` macro call stays sorted.
3636
generate! {
37+
<<<<<<< Updated upstream,
38+
=======,
39+
>>>>>>> Stashed changes,
3740
AsyncReadExt,
3841
AsyncWriteExt,
3942
BACKSLASH_SINGLE_QUOTE: r"\'",
@@ -307,6 +310,7 @@ generate! {
307310
split_at_mut,
308311
split_at_mut_checked,
309312
split_inclusive,
313+
split_off,
310314
split_once,
311315
split_terminator,
312316
split_whitespace,

tests/ui/unnecessary_split_off.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ impl A {
77
fn split_off(&mut self, _: usize) {}
88
}
99

10-
const ZERO: usize = 0;
11-
1210
fn main() {
1311
let mut vec1 = vec![1, 2, 3];
1412

@@ -17,12 +15,17 @@ fn main() {
1715

1816
let vec3: Vec<_> = vec1.split_off(1);
1917

18+
const ZERO: usize = 0;
2019
let vec4: Vec<_> = vec1.split_off(ZERO);
2120
//~^ unnecessary_split_off
2221

2322
let vec5: Vec<_> = vec1.split_off(const { 0 });
2423
//~^ unnecessary_split_off
2524

25+
let zero = 0;
26+
let vec6: Vec<_> = vec1.split_off(zero);
27+
//~^ unnecessary_split_off
28+
2629
let mut a = A;
2730
a.split_off(0);
2831
}

0 commit comments

Comments
 (0)