Skip to content

Commit aac0bc8

Browse files
committed
fix: single_range_in_vec_init FP for explicit Range
1 parent 8ed05ab commit aac0bc8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clippy_lints/src/single_range_in_vec_init.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_errors::Applicability;
99
use rustc_hir::{Expr, ExprKind, LangItem, StructTailExpr};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_session::declare_lint_pass;
12+
use rustc_span::DesugaringKind;
1213
use std::fmt::{self, Display, Formatter};
1314

1415
declare_clippy_lint! {
@@ -91,6 +92,7 @@ impl LateLintPass<'_> for SingleRangeInVecInit {
9192
};
9293

9394
if cx.tcx.qpath_is_lang_item(qpath, LangItem::Range)
95+
&& inner_expr.span.is_desugaring(DesugaringKind::RangeExpr)
9496
&& let ty = cx.typeck_results().expr_ty(start.expr)
9597
&& let Some(snippet) = span.get_source_text(cx)
9698
// `is_from_proc_macro` will skip any `vec![]`. Let's not!

tests/ui/single_range_in_vec_init.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ fn main() {
6666
vec![0..200];
6767
}
6868
}
69+
70+
fn issue16042() {
71+
use std::ops::Range;
72+
73+
let input = vec![Range { start: 0, end: 5 }];
74+
}

0 commit comments

Comments
 (0)