Import declared lints at the top of the file

This commit is contained in:
Yoshitomo Nakanishi 2021-02-16 22:18:53 +09:00
parent 2afa7df564
commit bb8208da2b
3 changed files with 9 additions and 3 deletions

View File

@ -9,6 +9,8 @@ use if_chain::if_chain;
use crate::utils::{match_path, paths, snippet, span_lint_and_sugg};
use super::BORROWED_BOX;
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, mut_ty: &MutTy<'_>) -> bool {
match mut_ty.ty.kind {
TyKind::Path(ref qpath) => {
@ -61,7 +63,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
};
span_lint_and_sugg(
cx,
super::BORROWED_BOX,
BORROWED_BOX,
hir_ty.span,
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
"try",

View File

@ -3,11 +3,13 @@ use rustc_lint::LateContext;
use crate::utils::{match_def_path, paths, span_lint_and_help};
use super::LINKEDLIST;
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, def_id: DefId) -> bool {
if match_def_path(cx, def_id, &paths::LINKED_LIST) {
span_lint_and_help(
cx,
super::LINKEDLIST,
LINKEDLIST,
hir_ty.span,
"you seem to be using a `LinkedList`! Perhaps you meant some other data structure?",
None,

View File

@ -4,12 +4,14 @@ use rustc_span::symbol::sym;
use crate::utils::{is_ty_param_diagnostic_item, span_lint};
use super::OPTION_OPTION;
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
if cx.tcx.is_diagnostic_item(sym::option_type, def_id) {
if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
span_lint(
cx,
super::OPTION_OPTION,
OPTION_OPTION,
hir_ty.span,
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
enum if you need to distinguish all 3 cases",