Rename span_help_and_lint
to span_lint_and_help
This commit is contained in:
parent
4f65bec39a
commit
f60f12f71f
32 changed files with 90 additions and 90 deletions
|
@ -3,7 +3,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
|
|
||||||
use crate::utils::span_help_and_lint;
|
use crate::utils::span_lint_and_help;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for usage of `as` conversions.
|
/// **What it does:** Checks for usage of `as` conversions.
|
||||||
|
@ -45,7 +45,7 @@ impl EarlyLintPass for AsConversions {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ExprKind::Cast(_, _) = expr.kind {
|
if let ExprKind::Cast(_, _) = expr.kind {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
AS_CONVERSIONS,
|
AS_CONVERSIONS,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::consts::{constant, Constant};
|
use crate::consts::{constant, Constant};
|
||||||
use crate::utils::paths;
|
use crate::utils::paths;
|
||||||
use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, snippet_opt, span_help_and_lint};
|
use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, snippet_opt, span_lint_and_help};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
|
@ -34,7 +34,7 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||||
let lint_true = |is_debug: bool| {
|
let lint_true = |is_debug: bool| {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
ASSERTIONS_ON_CONSTANTS,
|
ASSERTIONS_ON_CONSTANTS,
|
||||||
e.span,
|
e.span,
|
||||||
|
@ -47,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
let lint_false_without_message = || {
|
let lint_false_without_message = || {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
ASSERTIONS_ON_CONSTANTS,
|
ASSERTIONS_ON_CONSTANTS,
|
||||||
e.span,
|
e.span,
|
||||||
|
@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
let lint_false_with_message = |panic_message: String| {
|
let lint_false_with_message = |panic_message: String| {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
ASSERTIONS_ON_CONSTANTS,
|
ASSERTIONS_ON_CONSTANTS,
|
||||||
e.span,
|
e.span,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::{match_def_path, span_help_and_lint};
|
use crate::utils::{match_def_path, span_lint_and_help};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -80,7 +80,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||||
then {
|
then {
|
||||||
if method == "load" &&
|
if method == "load" &&
|
||||||
match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) {
|
match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
INVALID_ATOMIC_ORDERING,
|
INVALID_ATOMIC_ORDERING,
|
||||||
ordering_arg.span,
|
ordering_arg.span,
|
||||||
|
@ -89,7 +89,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||||
);
|
);
|
||||||
} else if method == "store" &&
|
} else if method == "store" &&
|
||||||
match_ordering_def_path(cx, ordering_def_id, &["Acquire", "AcqRel"]) {
|
match_ordering_def_path(cx, ordering_def_id, &["Acquire", "AcqRel"]) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
INVALID_ATOMIC_ORDERING,
|
INVALID_ATOMIC_ORDERING,
|
||||||
ordering_arg.span,
|
ordering_arg.span,
|
||||||
|
@ -113,7 +113,7 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||||
if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id();
|
if let Some(ordering_def_id) = cx.tables.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id();
|
||||||
if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]);
|
if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]);
|
||||||
then {
|
then {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
INVALID_ATOMIC_ORDERING,
|
INVALID_ATOMIC_ORDERING,
|
||||||
args[0].span,
|
args[0].span,
|
||||||
|
|
|
@ -89,7 +89,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
||||||
if expr.span.from_expansion() || differing_macro_contexts(expr.span, ex.span) {
|
if expr.span.from_expansion() || differing_macro_contexts(expr.span, ex.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
BLOCK_IN_IF_CONDITION_EXPR,
|
BLOCK_IN_IF_CONDITION_EXPR,
|
||||||
check.span,
|
check.span,
|
||||||
|
@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// move block higher
|
// move block higher
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
BLOCK_IN_IF_CONDITION_STMT,
|
BLOCK_IN_IF_CONDITION_STMT,
|
||||||
check.span,
|
check.span,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rustc_span::source_map::Span;
|
||||||
use rustc_span::BytePos;
|
use rustc_span::BytePos;
|
||||||
use syntax::ast::Attribute;
|
use syntax::ast::Attribute;
|
||||||
|
|
||||||
use crate::utils::{match_type, paths, snippet_opt, span_help_and_lint, LimitStack};
|
use crate::utils::{match_type, paths, snippet_opt, span_lint_and_help, LimitStack};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for methods with high cognitive complexity.
|
/// **What it does:** Checks for methods with high cognitive complexity.
|
||||||
|
@ -96,7 +96,7 @@ impl CognitiveComplexity {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
COGNITIVE_COMPLEXITY,
|
COGNITIVE_COMPLEXITY,
|
||||||
fn_span,
|
fn_span,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
get_trait_def_id, if_sequence, implements_trait, parent_node_is_if_expr, paths, span_help_and_lint, SpanlessEq,
|
get_trait_def_id, if_sequence, implements_trait, parent_node_is_if_expr, paths, span_lint_and_help, SpanlessEq,
|
||||||
};
|
};
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
|
@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
COMPARISON_CHAIN,
|
COMPARISON_CHAIN,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::{snippet_opt, span_help_and_lint, span_lint_and_sugg};
|
use crate::utils::{snippet_opt, span_lint_and_help, span_lint_and_sugg};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
@ -43,7 +43,7 @@ impl EarlyLintPass for DbgMacro {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
DBG_MACRO,
|
DBG_MACRO,
|
||||||
mac.span(),
|
mac.span(),
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
|
|
||||||
use crate::utils::span_help_and_lint;
|
use crate::utils::span_lint_and_help;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
|
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
|
||||||
|
@ -56,7 +56,7 @@ impl EarlyLintPass for ElseIfWithoutElse {
|
||||||
|
|
||||||
while let ExprKind::If(_, _, Some(ref els)) = item.kind {
|
while let ExprKind::If(_, _, Some(ref els)) = item.kind {
|
||||||
if let ExprKind::If(_, _, None) = els.kind {
|
if let ExprKind::If(_, _, None) = els.kind {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
ELSE_IF_WITHOUT_ELSE,
|
ELSE_IF_WITHOUT_ELSE,
|
||||||
els.span,
|
els.span,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! lint on enum variants that are prefixed or suffixed by the same characters
|
//! lint on enum variants that are prefixed or suffixed by the same characters
|
||||||
|
|
||||||
use crate::utils::{camel_case, is_present_in_source};
|
use crate::utils::{camel_case, is_present_in_source};
|
||||||
use crate::utils::{span_help_and_lint, span_lint};
|
use crate::utils::{span_lint, span_lint_and_help};
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass, Lint};
|
use rustc_lint::{EarlyContext, EarlyLintPass, Lint};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
|
@ -201,7 +201,7 @@ fn check_variant(
|
||||||
(false, _) => ("pre", pre),
|
(false, _) => ("pre", pre),
|
||||||
(true, false) => ("post", post),
|
(true, false) => ("post", post),
|
||||||
};
|
};
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
lint,
|
lint,
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::{differing_macro_contexts, snippet_opt, span_help_and_lint, span_note_and_lint};
|
use crate::utils::{differing_macro_contexts, snippet_opt, span_lint_and_help, span_note_and_lint};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::lint::in_external_macro;
|
use rustc::lint::in_external_macro;
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||||
|
@ -178,7 +178,7 @@ fn check_unop(cx: &EarlyContext<'_>, expr: &Expr) {
|
||||||
then {
|
then {
|
||||||
let unop_str = UnOp::to_string(op);
|
let unop_str = UnOp::to_string(op);
|
||||||
let eqop_span = lhs.span.between(un_rhs.span);
|
let eqop_span = lhs.span.between(un_rhs.span);
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
SUSPICIOUS_UNARY_OP_FORMATTING,
|
SUSPICIOUS_UNARY_OP_FORMATTING,
|
||||||
eqop_span,
|
eqop_span,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
attr_by_name, attrs::is_proc_macro, is_must_use_ty, iter_input_pats, match_def_path, must_use_attr, qpath_res,
|
attr_by_name, attrs::is_proc_macro, is_must_use_ty, iter_input_pats, match_def_path, must_use_attr, qpath_res,
|
||||||
return_ty, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then, trait_ref_of_method,
|
return_ty, snippet, snippet_opt, span_lint, span_lint_and_help, span_lint_and_then, trait_ref_of_method,
|
||||||
type_is_unsafe_function,
|
type_is_unsafe_function,
|
||||||
};
|
};
|
||||||
use matches::matches;
|
use matches::matches;
|
||||||
|
@ -433,7 +433,7 @@ fn check_needless_must_use(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else if !attr.is_value_str() && is_must_use_ty(cx, return_ty(cx, item_id)) {
|
} else if !attr.is_value_str() && is_must_use_ty(cx, return_ty(cx, item_id)) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
DOUBLE_MUST_USE,
|
DOUBLE_MUST_USE,
|
||||||
fn_header_span,
|
fn_header_span,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
|
|
||||||
use crate::utils::span_help_and_lint;
|
use crate::utils::span_lint_and_help;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for usage of `!` or `!=` in an if condition with an
|
/// **What it does:** Checks for usage of `!` or `!=` in an if condition with an
|
||||||
|
@ -56,7 +56,7 @@ impl EarlyLintPass for IfNotElse {
|
||||||
if let ExprKind::Block(..) = els.kind {
|
if let ExprKind::Block(..) = els.kind {
|
||||||
match cond.kind {
|
match cond.kind {
|
||||||
ExprKind::Unary(UnOp::Not, _) => {
|
ExprKind::Unary(UnOp::Not, _) => {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
IF_NOT_ELSE,
|
IF_NOT_ELSE,
|
||||||
item.span,
|
item.span,
|
||||||
|
@ -65,7 +65,7 @@ impl EarlyLintPass for IfNotElse {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
ExprKind::Binary(ref kind, _, _) if kind.node == BinOpKind::Ne => {
|
ExprKind::Binary(ref kind, _, _) if kind.node == BinOpKind::Ne => {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
IF_NOT_ELSE,
|
IF_NOT_ELSE,
|
||||||
item.span,
|
item.span,
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
||||||
(None, None) => return, // [..] is ok.
|
(None, None) => return, // [..] is ok.
|
||||||
};
|
};
|
||||||
|
|
||||||
utils::span_help_and_lint(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
|
utils::span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
|
||||||
} else {
|
} else {
|
||||||
// Catchall non-range index, i.e., [n] or [n << m]
|
// Catchall non-range index, i.e., [n] or [n << m]
|
||||||
if let ty::Array(..) = ty.kind {
|
if let ty::Array(..) = ty.kind {
|
||||||
|
@ -147,7 +147,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::span_help_and_lint(
|
utils::span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
INDEXING_SLICING,
|
INDEXING_SLICING,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
get_trait_def_id, implements_trait, match_type, paths, return_ty, span_help_and_lint, trait_ref_of_method,
|
get_trait_def_id, implements_trait, match_type, paths, return_ty, span_lint_and_help, trait_ref_of_method,
|
||||||
walk_ptrs_ty,
|
walk_ptrs_ty,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) {
|
||||||
|
|
||||||
// Emit either a warning or an error
|
// Emit either a warning or an error
|
||||||
if implements_trait(cx, self_type, display_trait_id, &[]) {
|
if implements_trait(cx, self_type, display_trait_id, &[]) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
INHERENT_TO_STRING_SHADOW_DISPLAY,
|
INHERENT_TO_STRING_SHADOW_DISPLAY,
|
||||||
item.span,
|
item.span,
|
||||||
|
@ -141,7 +141,7 @@ fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) {
|
||||||
&format!("remove the inherent method from type `{}`", self_type.to_string())
|
&format!("remove the inherent method from type `{}`", self_type.to_string())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
INHERENT_TO_STRING,
|
INHERENT_TO_STRING,
|
||||||
item.span,
|
item.span,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::span_help_and_lint;
|
use crate::utils::span_lint_and_help;
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
|
@ -30,7 +30,7 @@ declare_lint_pass!(IntegerDivision => [INTEGER_DIVISION]);
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||||
if is_integer_division(cx, expr) {
|
if is_integer_division(cx, expr) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
INTEGER_DIVISION,
|
INTEGER_DIVISION,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
|
||||||
use crate::rustc_target::abi::LayoutOf;
|
use crate::rustc_target::abi::LayoutOf;
|
||||||
use crate::utils::{snippet, span_help_and_lint};
|
use crate::utils::{snippet, span_lint_and_help};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for local arrays that may be too large.
|
/// **What it does:** Checks for local arrays that may be too large.
|
||||||
|
@ -49,7 +49,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays {
|
||||||
if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes());
|
if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes());
|
||||||
if self.maximum_allowed_size < element_count * element_size;
|
if self.maximum_allowed_size < element_count * element_size;
|
||||||
then {
|
then {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
LARGE_STACK_ARRAYS,
|
LARGE_STACK_ARRAYS,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rustc_hir::*;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
|
||||||
use crate::utils::{is_must_use_func_call, is_must_use_ty, span_help_and_lint};
|
use crate::utils::{is_must_use_func_call, is_must_use_ty, span_lint_and_help};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for `let _ = <expr>`
|
/// **What it does:** Checks for `let _ = <expr>`
|
||||||
|
@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
|
||||||
if let Some(ref init) = local.init;
|
if let Some(ref init) = local.init;
|
||||||
then {
|
then {
|
||||||
if is_must_use_ty(cx, cx.tables.expr_ty(init)) {
|
if is_must_use_ty(cx, cx.tables.expr_ty(init)) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
LET_UNDERSCORE_MUST_USE,
|
LET_UNDERSCORE_MUST_USE,
|
||||||
stmt.span,
|
stmt.span,
|
||||||
|
@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
|
||||||
"consider explicitly using expression value"
|
"consider explicitly using expression value"
|
||||||
)
|
)
|
||||||
} else if is_must_use_func_call(cx, init) {
|
} else if is_must_use_func_call(cx, init) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
LET_UNDERSCORE_MUST_USE,
|
LET_UNDERSCORE_MUST_USE,
|
||||||
stmt.span,
|
stmt.span,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::utils::usage::{is_unused, mutated_variables};
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
get_enclosing_block, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait,
|
get_enclosing_block, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait,
|
||||||
is_integer_const, is_no_std_crate, is_refutable, last_path_segment, match_trait_method, match_type, match_var,
|
is_integer_const, is_no_std_crate, is_refutable, last_path_segment, match_trait_method, match_type, match_var,
|
||||||
multispan_sugg, snippet, snippet_opt, snippet_with_applicability, span_help_and_lint, span_lint,
|
multispan_sugg, snippet, snippet_opt, snippet_with_applicability, span_lint, span_lint_and_help,
|
||||||
span_lint_and_sugg, span_lint_and_then, SpanlessEq,
|
span_lint_and_sugg, span_lint_and_then, SpanlessEq,
|
||||||
};
|
};
|
||||||
use crate::utils::{is_type_diagnostic_item, qpath_res, same_tys, sext, sugg};
|
use crate::utils::{is_type_diagnostic_item, qpath_res, same_tys, sext, sugg};
|
||||||
|
@ -1390,7 +1390,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e
|
||||||
fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
||||||
let ty = cx.tables.expr_ty(arg);
|
let ty = cx.tables.expr_ty(arg);
|
||||||
if match_type(cx, ty, &paths::OPTION) {
|
if match_type(cx, ty, &paths::OPTION) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
FOR_LOOP_OVER_OPTION,
|
FOR_LOOP_OVER_OPTION,
|
||||||
arg.span,
|
arg.span,
|
||||||
|
@ -1406,7 +1406,7 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if match_type(cx, ty, &paths::RESULT) {
|
} else if match_type(cx, ty, &paths::RESULT) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
FOR_LOOP_OVER_RESULT,
|
FOR_LOOP_OVER_RESULT,
|
||||||
arg.span,
|
arg.span,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use rustc_hir::{Crate, Expr, ExprKind, QPath};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
|
|
||||||
use crate::utils::{is_entrypoint_fn, is_no_std_crate, snippet, span_help_and_lint};
|
use crate::utils::{is_entrypoint_fn, is_no_std_crate, snippet, span_lint_and_help};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
|
@ -48,7 +48,7 @@ impl LateLintPass<'_, '_> for MainRecursion {
|
||||||
if let Some(def_id) = path.res.opt_def_id();
|
if let Some(def_id) = path.res.opt_def_id();
|
||||||
if is_entrypoint_fn(cx, def_id);
|
if is_entrypoint_fn(cx, def_id);
|
||||||
then {
|
then {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
MAIN_RECURSION,
|
MAIN_RECURSION,
|
||||||
func.span,
|
func.span,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::utils::sugg::Sugg;
|
||||||
use crate::utils::usage::is_unused;
|
use crate::utils::usage::is_unused;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
expr_block, is_allowed, is_expn_of, is_wild, match_qpath, match_type, multispan_sugg, remove_blocks, snippet,
|
expr_block, is_allowed, is_expn_of, is_wild, match_qpath, match_type, multispan_sugg, remove_blocks, snippet,
|
||||||
snippet_with_applicability, span_help_and_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint,
|
snippet_with_applicability, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, span_note_and_lint,
|
||||||
walk_ptrs_ty,
|
walk_ptrs_ty,
|
||||||
};
|
};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
@ -700,7 +700,7 @@ fn check_wild_in_or_pats(cx: &LateContext<'_, '_>, arms: &[Arm<'_>]) {
|
||||||
if let PatKind::Or(ref fields) = arm.pat.kind {
|
if let PatKind::Or(ref fields) = arm.pat.kind {
|
||||||
// look for multiple fields in this arm that contains at least one Wild pattern
|
// look for multiple fields in this arm that contains at least one Wild pattern
|
||||||
if fields.len() > 1 && fields.iter().any(is_wild) {
|
if fields.len() > 1 && fields.iter().any(is_wild) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
WILDCARD_IN_OR_PATTERNS,
|
WILDCARD_IN_OR_PATTERNS,
|
||||||
arm.pat.span,
|
arm.pat.span,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
in_macro, match_def_path, match_qpath, paths, snippet, snippet_with_applicability, span_help_and_lint,
|
in_macro, match_def_path, match_qpath, paths, snippet, snippet_with_applicability, span_lint_and_help,
|
||||||
span_lint_and_sugg, span_lint_and_then,
|
span_lint_and_sugg, span_lint_and_then,
|
||||||
};
|
};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
@ -142,7 +142,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span
|
||||||
if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
|
if let Some(repl_def_id) = cx.tables.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
|
||||||
then {
|
then {
|
||||||
if match_def_path(cx, repl_def_id, &paths::MEM_UNINITIALIZED) {
|
if match_def_path(cx, repl_def_id, &paths::MEM_UNINITIALIZED) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
MEM_REPLACE_WITH_UNINIT,
|
MEM_REPLACE_WITH_UNINIT,
|
||||||
expr_span,
|
expr_span,
|
||||||
|
@ -151,7 +151,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_, '_>, src: &Expr<'_>, expr_span
|
||||||
);
|
);
|
||||||
} else if match_def_path(cx, repl_def_id, &paths::MEM_ZEROED) &&
|
} else if match_def_path(cx, repl_def_id, &paths::MEM_ZEROED) &&
|
||||||
!cx.tables.expr_ty(src).is_primitive() {
|
!cx.tables.expr_ty(src).is_primitive() {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
MEM_REPLACE_WITH_UNINIT,
|
MEM_REPLACE_WITH_UNINIT,
|
||||||
expr_span,
|
expr_span,
|
||||||
|
|
|
@ -28,7 +28,7 @@ use crate::utils::{
|
||||||
is_ctor_or_promotable_const_function, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment,
|
is_ctor_or_promotable_const_function, is_expn_of, is_type_diagnostic_item, iter_input_pats, last_path_segment,
|
||||||
match_def_path, match_qpath, match_trait_method, match_type, match_var, method_calls, method_chain_args, paths,
|
match_def_path, match_qpath, match_trait_method, match_type, match_var, method_calls, method_chain_args, paths,
|
||||||
remove_blocks, return_ty, same_tys, single_segment_path, snippet, snippet_with_applicability,
|
remove_blocks, return_ty, same_tys, single_segment_path, snippet, snippet_with_applicability,
|
||||||
snippet_with_macro_callsite, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then,
|
snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then,
|
||||||
span_note_and_lint, sugg, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq,
|
span_note_and_lint, sugg, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2133,7 +2133,7 @@ fn lint_iter_nth<'a, 'tcx>(
|
||||||
return; // caller is not a type that we want to lint
|
return; // caller is not a type that we want to lint
|
||||||
};
|
};
|
||||||
|
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
ITER_NTH,
|
ITER_NTH,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -2242,7 +2242,7 @@ fn lint_get_unwrap<'a, 'tcx>(
|
||||||
fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
|
fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
|
||||||
// lint if caller of skip is an Iterator
|
// lint if caller of skip is an Iterator
|
||||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
ITER_SKIP_NEXT,
|
ITER_SKIP_NEXT,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -2303,7 +2303,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((lint, kind, none_value)) = mess {
|
if let Some((lint, kind, none_value)) = mess {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
lint,
|
lint,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -2330,7 +2330,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((lint, kind, none_value)) = mess {
|
if let Some((lint, kind, none_value)) = mess {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
lint,
|
lint,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -2350,7 +2350,7 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir
|
||||||
if has_debug_impl(error_type, cx);
|
if has_debug_impl(error_type, cx);
|
||||||
|
|
||||||
then {
|
then {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
OK_EXPECT,
|
OK_EXPECT,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -2588,7 +2588,7 @@ fn lint_skip_while_next<'a, 'tcx>(
|
||||||
) {
|
) {
|
||||||
// lint if caller of `.skip_while().next()` is an Iterator
|
// lint if caller of `.skip_while().next()` is an Iterator
|
||||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
SKIP_WHILE_NEXT,
|
SKIP_WHILE_NEXT,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -2609,7 +2609,7 @@ fn lint_filter_map<'a, 'tcx>(
|
||||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||||
let msg = "called `filter(p).map(q)` on an `Iterator`";
|
let msg = "called `filter(p).map(q)` on an `Iterator`";
|
||||||
let hint = "this is more succinctly expressed by calling `.filter_map(..)` instead";
|
let hint = "this is more succinctly expressed by calling `.filter_map(..)` instead";
|
||||||
span_help_and_lint(cx, FILTER_MAP, expr.span, msg, hint);
|
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2649,7 +2649,7 @@ fn lint_find_map<'a, 'tcx>(
|
||||||
if match_trait_method(cx, &map_args[0], &paths::ITERATOR) {
|
if match_trait_method(cx, &map_args[0], &paths::ITERATOR) {
|
||||||
let msg = "called `find(p).map(q)` on an `Iterator`";
|
let msg = "called `find(p).map(q)` on an `Iterator`";
|
||||||
let hint = "this is more succinctly expressed by calling `.find_map(..)` instead";
|
let hint = "this is more succinctly expressed by calling `.find_map(..)` instead";
|
||||||
span_help_and_lint(cx, FIND_MAP, expr.span, msg, hint);
|
span_lint_and_help(cx, FIND_MAP, expr.span, msg, hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2664,7 +2664,7 @@ fn lint_filter_map_map<'a, 'tcx>(
|
||||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||||
let msg = "called `filter_map(p).map(q)` on an `Iterator`";
|
let msg = "called `filter_map(p).map(q)` on an `Iterator`";
|
||||||
let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
|
let hint = "this is more succinctly expressed by only calling `.filter_map(..)` instead";
|
||||||
span_help_and_lint(cx, FILTER_MAP, expr.span, msg, hint);
|
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2680,7 +2680,7 @@ fn lint_filter_flat_map<'a, 'tcx>(
|
||||||
let msg = "called `filter(p).flat_map(q)` on an `Iterator`";
|
let msg = "called `filter(p).flat_map(q)` on an `Iterator`";
|
||||||
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
|
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
|
||||||
and filtering by returning `iter::empty()`";
|
and filtering by returning `iter::empty()`";
|
||||||
span_help_and_lint(cx, FILTER_MAP, expr.span, msg, hint);
|
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2696,7 +2696,7 @@ fn lint_filter_map_flat_map<'a, 'tcx>(
|
||||||
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`";
|
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`";
|
||||||
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
|
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
|
||||||
and filtering by returning `iter::empty()`";
|
and filtering by returning `iter::empty()`";
|
||||||
span_help_and_lint(cx, FILTER_MAP, expr.span, msg, hint);
|
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3077,7 +3077,7 @@ fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
|
fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
SUSPICIOUS_MAP,
|
SUSPICIOUS_MAP,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
@ -3436,5 +3436,5 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &
|
||||||
}
|
}
|
||||||
let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
|
let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
|
||||||
let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
|
let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
|
||||||
span_help_and_lint(cx, FILETYPE_IS_FILE, span, &lint_msg, &help_msg);
|
span_lint_and_help(cx, FILETYPE_IS_FILE, span, &lint_msg, &help_msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
constants, snippet_opt, snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg,
|
constants, snippet_opt, snippet_with_applicability, span_lint, span_lint_and_help, span_lint_and_sugg,
|
||||||
span_lint_and_then,
|
span_lint_and_then,
|
||||||
};
|
};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
@ -305,7 +305,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !pfields.is_empty() && wilds == pfields.len() {
|
if !pfields.is_empty() && wilds == pfields.len() {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
UNNEEDED_FIELD_PATTERN,
|
UNNEEDED_FIELD_PATTERN,
|
||||||
pat.span,
|
pat.span,
|
||||||
|
@ -338,7 +338,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
||||||
"You matched a field with a wildcard pattern. Consider using `..` instead",
|
"You matched a field with a wildcard pattern. Consider using `..` instead",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
UNNEEDED_FIELD_PATTERN,
|
UNNEEDED_FIELD_PATTERN,
|
||||||
field.span,
|
field.span,
|
||||||
|
|
|
@ -39,7 +39,7 @@ use rustc_span::source_map::{original_sp, DUMMY_SP};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
|
||||||
use crate::utils::{snippet, snippet_block, span_help_and_lint, trim_multiline};
|
use crate::utils::{snippet, snippet_block, span_lint_and_help, trim_multiline};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** The lint checks for `if`-statements appearing in loops
|
/// **What it does:** The lint checks for `if`-statements appearing in loops
|
||||||
|
@ -300,7 +300,7 @@ fn emit_warning<'a>(ctx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str
|
||||||
data.if_expr,
|
data.if_expr,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
span_help_and_lint(ctx, NEEDLESS_CONTINUE, expr.span, message, &snip);
|
span_lint_and_help(ctx, NEEDLESS_CONTINUE, expr.span, message, &snip);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggestion_snippet_for_continue_inside_if<'a>(
|
fn suggestion_snippet_for_continue_inside_if<'a>(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::consts::{constant, Constant};
|
use crate::consts::{constant, Constant};
|
||||||
use crate::utils::{is_expn_of, match_def_path, match_type, paths, span_help_and_lint, span_lint};
|
use crate::utils::{is_expn_of, match_def_path, match_type, paths, span_lint, span_lint_and_help};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
|
@ -208,7 +208,7 @@ fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8:
|
||||||
match parser.parse(r) {
|
match parser.parse(r) {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
if let Some(repl) = is_trivial_regex(&r) {
|
if let Some(repl) = is_trivial_regex(&r) {
|
||||||
span_help_and_lint(cx, TRIVIAL_REGEX, expr.span, "trivial regex", repl);
|
span_lint_and_help(cx, TRIVIAL_REGEX, expr.span, "trivial regex", repl);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(regex_syntax::Error::Parse(e)) => {
|
Err(regex_syntax::Error::Parse(e)) => {
|
||||||
|
@ -236,7 +236,7 @@ fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8:
|
||||||
match parser.parse(&r) {
|
match parser.parse(&r) {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
if let Some(repl) = is_trivial_regex(&r) {
|
if let Some(repl) = is_trivial_regex(&r) {
|
||||||
span_help_and_lint(cx, TRIVIAL_REGEX, expr.span, "trivial regex", repl);
|
span_lint_and_help(cx, TRIVIAL_REGEX, expr.span, "trivial regex", repl);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(regex_syntax::Error::Parse(e)) => {
|
Err(regex_syntax::Error::Parse(e)) => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::{in_macro, snippet, span_help_and_lint, SpanlessHash};
|
use crate::utils::{in_macro, snippet, span_lint_and_help, SpanlessHash};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
|
@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds {
|
||||||
}
|
}
|
||||||
hint_string.truncate(hint_string.len() - 2);
|
hint_string.truncate(hint_string.len() - 2);
|
||||||
hint_string.push('`');
|
hint_string.push('`');
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
TYPE_REPETITION_IN_BOUNDS,
|
TYPE_REPETITION_IN_BOUNDS,
|
||||||
p.span,
|
p.span,
|
||||||
|
|
|
@ -27,7 +27,7 @@ use crate::utils::paths;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, last_path_segment, match_def_path,
|
clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, last_path_segment, match_def_path,
|
||||||
match_path, method_chain_args, multispan_sugg, qpath_res, same_tys, sext, snippet, snippet_opt,
|
match_path, method_chain_args, multispan_sugg, qpath_res, same_tys, sext, snippet, snippet_opt,
|
||||||
snippet_with_applicability, snippet_with_macro_callsite, span_help_and_lint, span_lint, span_lint_and_sugg,
|
snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg,
|
||||||
span_lint_and_then, unsext,
|
span_lint_and_then, unsext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ impl Types {
|
||||||
if let Some(def_id) = res.opt_def_id() {
|
if let Some(def_id) = res.opt_def_id() {
|
||||||
if Some(def_id) == cx.tcx.lang_items().owned_box() {
|
if Some(def_id) == cx.tcx.lang_items().owned_box() {
|
||||||
if match_type_parameter(cx, qpath, &paths::VEC) {
|
if match_type_parameter(cx, qpath, &paths::VEC) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
BOX_VEC,
|
BOX_VEC,
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
|
@ -321,7 +321,7 @@ impl Types {
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}
|
}
|
||||||
} else if match_def_path(cx, def_id, &paths::LINKED_LIST) {
|
} else if match_def_path(cx, def_id, &paths::LINKED_LIST) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
LINKEDLIST,
|
LINKEDLIST,
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
|
@ -1785,7 +1785,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
|
||||||
conclusion
|
conclusion
|
||||||
);
|
);
|
||||||
|
|
||||||
span_help_and_lint(cx, ABSURD_EXTREME_COMPARISONS, expr.span, msg, &help);
|
span_lint_and_help(cx, ABSURD_EXTREME_COMPARISONS, expr.span, msg, &help);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_hir::{AssocItemKind, HirId, ImplItem, ImplItemKind, ImplItemRef, ItemK
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
|
||||||
use crate::utils::span_help_and_lint;
|
use crate::utils::span_lint_and_help;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks methods that contain a `self` argument but don't use it
|
/// **What it does:** Checks methods that contain a `self` argument but don't use it
|
||||||
|
@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
|
||||||
};
|
};
|
||||||
visitor.visit_body(body);
|
visitor.visit_body(body);
|
||||||
if !visitor.uses_self {
|
if !visitor.uses_self {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
UNUSED_SELF,
|
UNUSED_SELF,
|
||||||
self_param.span,
|
self_param.span,
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<Mult
|
||||||
/// |
|
/// |
|
||||||
/// = help: Consider using `std::f64::NAN` if you would like a constant representing NaN
|
/// = help: Consider using `std::f64::NAN` if you would like a constant representing NaN
|
||||||
/// ```
|
/// ```
|
||||||
pub fn span_help_and_lint<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, help: &str) {
|
pub fn span_lint_and_help<'a, T: LintContext>(cx: &'a T, lint: &'static Lint, span: Span, msg: &str, help: &str) {
|
||||||
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, span, msg));
|
let mut db = DiagnosticWrapper(cx.struct_span_lint(lint, span, msg));
|
||||||
db.0.help(help);
|
db.0.help(help);
|
||||||
db.docs_link(lint);
|
db.docs_link(lint);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
is_expn_of, match_def_path, match_type, method_calls, paths, span_help_and_lint, span_lint, span_lint_and_sugg,
|
is_expn_of, match_def_path, match_type, method_calls, paths, span_lint, span_lint_and_help, span_lint_and_sugg,
|
||||||
walk_ptrs_ty,
|
walk_ptrs_ty,
|
||||||
};
|
};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
@ -319,7 +319,7 @@ impl CompilerLintFunctions {
|
||||||
map.insert("struct_span_lint", "utils::span_lint");
|
map.insert("struct_span_lint", "utils::span_lint");
|
||||||
map.insert("lint", "utils::span_lint");
|
map.insert("lint", "utils::span_lint");
|
||||||
map.insert("span_lint_note", "utils::span_note_and_lint");
|
map.insert("span_lint_note", "utils::span_note_and_lint");
|
||||||
map.insert("span_lint_help", "utils::span_help_and_lint");
|
map.insert("span_lint_help", "utils::span_lint_and_help");
|
||||||
Self { map }
|
Self { map }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions {
|
||||||
if match_type(cx, ty, &paths::EARLY_CONTEXT)
|
if match_type(cx, ty, &paths::EARLY_CONTEXT)
|
||||||
|| match_type(cx, ty, &paths::LATE_CONTEXT);
|
|| match_type(cx, ty, &paths::LATE_CONTEXT);
|
||||||
then {
|
then {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
COMPILER_LINT_FUNCTIONS,
|
COMPILER_LINT_FUNCTIONS,
|
||||||
path.ident.span,
|
path.ident.span,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::consts::{constant_simple, Constant};
|
use crate::consts::{constant_simple, Constant};
|
||||||
use crate::utils::span_help_and_lint;
|
use crate::utils::span_lint_and_help;
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
|
@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv {
|
||||||
| (_, Constant::F64(_)) => "f64",
|
| (_, Constant::F64(_)) => "f64",
|
||||||
_ => "f32"
|
_ => "f32"
|
||||||
};
|
};
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
ZERO_DIVIDED_BY_ZERO,
|
ZERO_DIVIDED_BY_ZERO,
|
||||||
expr.span,
|
expr.span,
|
||||||
|
|
|
@ -249,14 +249,14 @@ Depending on how complex we want our lint message to be, we can choose from a
|
||||||
variety of lint emission functions. They can all be found in
|
variety of lint emission functions. They can all be found in
|
||||||
[`clippy_lints/src/utils/diagnostics.rs`][diagnostics].
|
[`clippy_lints/src/utils/diagnostics.rs`][diagnostics].
|
||||||
|
|
||||||
`span_help_and_lint` seems most appropriate in this case. It allows us to
|
`span_lint_and_help` seems most appropriate in this case. It allows us to
|
||||||
provide an extra help message and we can't really suggest a better name
|
provide an extra help message and we can't really suggest a better name
|
||||||
automatically. This is how it looks:
|
automatically. This is how it looks:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl EarlyLintPass for FooFunctions {
|
impl EarlyLintPass for FooFunctions {
|
||||||
fn check_fn(&mut self, cx: &EarlyContext<'_>, _: FnKind<'_>, _: &FnDecl, span: Span, _: NodeId) {
|
fn check_fn(&mut self, cx: &EarlyContext<'_>, _: FnKind<'_>, _: &FnDecl, span: Span, _: NodeId) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
FOO_FUNCTIONS,
|
FOO_FUNCTIONS,
|
||||||
span,
|
span,
|
||||||
|
@ -284,7 +284,7 @@ With that we can expand our `check_fn` method to:
|
||||||
impl EarlyLintPass for FooFunctions {
|
impl EarlyLintPass for FooFunctions {
|
||||||
fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: &FnDecl, span: Span, _: NodeId) {
|
fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: &FnDecl, span: Span, _: NodeId) {
|
||||||
if is_foo_fn(fn_kind) {
|
if is_foo_fn(fn_kind) {
|
||||||
span_help_and_lint(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
FOO_FUNCTIONS,
|
FOO_FUNCTIONS,
|
||||||
span,
|
span,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue