fix(single_range_in_vec_init): don't apply the suggestion automatically

This commit is contained in:
Ada Alakbarova
2026-01-08 20:04:50 +01:00
parent 3b282feee6
commit 156b08184e
3 changed files with 29 additions and 1 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
&& snippet.starts_with(suggested_type.starts_with())
&& snippet.ends_with(suggested_type.ends_with())
{
let mut applicability = Applicability::MachineApplicable;
let mut applicability = Applicability::MaybeIncorrect;
let (start_snippet, _) = snippet_with_context(cx, start.expr.span, span.ctxt(), "..", &mut applicability);
let (end_snippet, _) = snippet_with_context(cx, end.expr.span, span.ctxt(), "..", &mut applicability);
@@ -0,0 +1,12 @@
//@no-rustfix
#![warn(clippy::single_range_in_vec_init)]
use std::ops::Range;
fn issue16306(v: &[i32]) {
fn takes_range_slice(_: &[Range<i64>]) {}
let len = v.len();
takes_range_slice(&[0..len as i64]);
//~^ single_range_in_vec_init
}
@@ -0,0 +1,16 @@
error: an array of `Range` that is only one element
--> tests/ui/single_range_in_vec_init_unfixable.rs:10:24
|
LL | takes_range_slice(&[0..len as i64]);
| ^^^^^^^^^^^^^^^
|
= note: `-D clippy::single-range-in-vec-init` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::single_range_in_vec_init)]`
help: if you wanted a `Vec` that contains the entire range, try
|
LL - takes_range_slice(&[0..len as i64]);
LL + takes_range_slice(&(0..len as i64).collect::<std::vec::Vec<i64>>());
|
error: aborting due to 1 previous error