use rustc_span::sym;
declare_clippy_lint! {
- /// **What it does:** Checks for `match vec[idx]` or `match vec[n..m]`.
+ /// ### What it does
+ /// Checks for `match vec[idx]` or `match vec[n..m]`.
///
- /// **Why is this bad?** This can panic at runtime.
+ /// ### Why is this bad?
+ /// This can panic at runtime.
///
- /// **Known problems:** None.
- ///
- /// **Example:**
+ /// ### Example
/// ```rust, no_run
/// let arr = vec![0, 1, 2, 3];
/// let idx = 1;
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if_chain! {
if !in_external_macro(cx.sess(), expr.span);
- if let ExprKind::Match(ref match_expr, _, MatchSource::Normal) = expr.kind;
+ if let ExprKind::Match(match_expr, _, MatchSource::Normal) = expr.kind;
if let Some(idx_expr) = is_vec_indexing(cx, match_expr);
if let ExprKind::Index(vec, idx) = idx_expr.kind;
fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
if_chain! {
- if let ExprKind::Index(ref array, ref index) = expr.kind;
+ if let ExprKind::Index(array, index) = expr.kind;
if is_vector(cx, array);
if !is_full_range(cx, index);
fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
let ty = cx.typeck_results().expr_ty(expr);
let ty = ty.peel_refs();
- is_type_diagnostic_item(cx, ty, sym::vec_type)
+ is_type_diagnostic_item(cx, ty, sym::Vec)
}
fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {