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

Fixes https://github.com/rust-lang/rust-clippy/issues/16306

changelog: [`single_range_in_vec_init`]: don't apply the suggestion
automatically
This commit is contained in:
Samuel Tardieu 2026-01-08 19:16:47 +00:00 committed by GitHub
commit 1a5bb37fb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View file

@ -98,7 +98,7 @@ impl LateLintPass<'_> for SingleRangeInVecInit {
&& 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);

View file

@ -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
}

View file

@ -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