Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions clippy_lints/src/types/rc_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use rustc_hir::{QPath, Ty, TyKind};
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
use std::borrow::Cow;
use std::fmt;

use super::RC_BUFFER;

pub(super) fn check(cx: &LateContext<'_>, hir_ty: &Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
let mut app = Applicability::Unspecified;
let kind = match cx.tcx.get_diagnostic_name(def_id) {
Some(sym::Rc) => RcKind::Rc,
Some(sym::Arc) => RcKind::Arc,
let rc = match cx.tcx.get_diagnostic_name(def_id) {
Some(sym::Rc) => "Rc",
Some(sym::Arc) => "Arc",
_ => return false,
};
if let Some(ty) = qpath_generic_tys(qpath).next()
Expand All @@ -26,7 +25,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &Ty<'_>, qpath: &QPath<'_>, de
cx,
RC_BUFFER,
hir_ty.span,
format!("usage of `{kind}<T>` when `T` is a buffer type"),
format!("usage of `{rc}<T>` when `T` is a buffer type"),
|diag| {
diag.span_suggestion_verbose(ty.span, "try", alternate, app);
},
Expand All @@ -37,20 +36,6 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &Ty<'_>, qpath: &QPath<'_>, de
}
}

enum RcKind {
Rc,
Arc,
}

impl fmt::Display for RcKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Rc => f.write_str("Rc"),
Self::Arc => f.write_str("Arc"),
}
}
}

fn match_buffer_type(
cx: &LateContext<'_>,
ty: &Ty<'_>,
Expand Down