Add Applicability::Unspecified to span_lint_and_sugg functions
This commit is contained in:
parent
fad267c3b3
commit
9096269610
31 changed files with 207 additions and 101 deletions
|
@ -532,6 +532,7 @@ impl EarlyLintPass for CfgAttrPass {
|
||||||
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
|
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
|
||||||
"use",
|
"use",
|
||||||
format!("{}rustfmt::skip]", attr_style),
|
format!("{}rustfmt::skip]", attr_style),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,14 @@
|
||||||
|
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::ty;
|
use crate::rustc::ty;
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::{Name, UintTy};
|
use crate::syntax::ast::{Name, UintTy};
|
||||||
use crate::utils::{contains_name, get_pat_name, match_type, paths, single_segment_path, snippet, span_lint_and_sugg,
|
use crate::utils::{
|
||||||
walk_ptrs_ty};
|
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet, span_lint_and_sugg, walk_ptrs_ty,
|
||||||
|
};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
|
||||||
/// **What it does:** Checks for naive byte counts
|
/// **What it does:** Checks for naive byte counts
|
||||||
///
|
///
|
||||||
|
@ -89,14 +91,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
|
||||||
} else {
|
} else {
|
||||||
&filter_args[0]
|
&filter_args[0]
|
||||||
};
|
};
|
||||||
span_lint_and_sugg(cx,
|
span_lint_and_sugg(
|
||||||
|
cx,
|
||||||
NAIVE_BYTECOUNT,
|
NAIVE_BYTECOUNT,
|
||||||
expr.span,
|
expr.span,
|
||||||
"You appear to be counting bytes the naive way",
|
"You appear to be counting bytes the naive way",
|
||||||
"Consider using the bytecount crate",
|
"Consider using the bytecount crate",
|
||||||
format!("bytecount::count({}, {})",
|
format!("bytecount::count({}, {})",
|
||||||
snippet(cx, haystack.span, ".."),
|
snippet(cx, haystack.span, ".."),
|
||||||
snippet(cx, needle.span, "..")));
|
snippet(cx, needle.span, "..")),
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,12 +128,15 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
|
||||||
then {
|
then {
|
||||||
match else_.node {
|
match else_.node {
|
||||||
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {
|
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {
|
||||||
span_lint_and_sugg(cx,
|
span_lint_and_sugg(
|
||||||
|
cx,
|
||||||
COLLAPSIBLE_IF,
|
COLLAPSIBLE_IF,
|
||||||
block.span,
|
block.span,
|
||||||
"this `else { if .. }` block can be collapsed",
|
"this `else { if .. }` block can be collapsed",
|
||||||
"try",
|
"try",
|
||||||
snippet_block(cx, else_.span, "..").into_owned());
|
snippet_block(cx, else_.span, "..").into_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,10 @@
|
||||||
|
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::ty::TyKind;
|
use crate::rustc::ty::TyKind;
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
|
use if_chain::if_chain;
|
||||||
|
|
||||||
use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
|
use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
|
||||||
|
|
||||||
|
@ -80,7 +81,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("Calling {} is more clear than this expression", replacement),
|
&format!("Calling {} is more clear than this expression", replacement),
|
||||||
"try",
|
"try",
|
||||||
replacement);
|
replacement,
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
QPath::TypeRelative(..) => {},
|
QPath::TypeRelative(..) => {},
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::source_map::Span;
|
use crate::syntax::source_map::Span;
|
||||||
|
|
||||||
use crate::utils::{snippet, span_lint_and_sugg, SpanlessEq};
|
use crate::utils::{snippet, span_lint_and_sugg, SpanlessEq};
|
||||||
|
@ -73,9 +74,15 @@ impl<'a, 'tcx> Pass {
|
||||||
let lhs_str = snippet(cx, llhs.span, "");
|
let lhs_str = snippet(cx, llhs.span, "");
|
||||||
let rhs_str = snippet(cx, lrhs.span, "");
|
let rhs_str = snippet(cx, lrhs.span, "");
|
||||||
let sugg = format!("{} {} {}", lhs_str, stringify!($op), rhs_str);
|
let sugg = format!("{} {} {}", lhs_str, stringify!($op), rhs_str);
|
||||||
span_lint_and_sugg(cx, DOUBLE_COMPARISONS, span,
|
span_lint_and_sugg(
|
||||||
|
cx,
|
||||||
|
DOUBLE_COMPARISONS,
|
||||||
|
span,
|
||||||
"This binary expression can be simplified",
|
"This binary expression can be simplified",
|
||||||
"try", sugg);
|
"try",
|
||||||
|
sugg,
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
match (op, lkind, rkind) {
|
match (op, lkind, rkind) {
|
||||||
|
|
|
@ -11,8 +11,9 @@
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use if_chain::if_chain;
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::source_map::Spanned;
|
use crate::syntax::source_map::Spanned;
|
||||||
|
use if_chain::if_chain;
|
||||||
|
|
||||||
use crate::consts::{constant, Constant};
|
use crate::consts::{constant, Constant};
|
||||||
use crate::utils::paths;
|
use crate::utils::paths;
|
||||||
|
@ -67,6 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
|
||||||
&format!("Calling `{}()` is more concise than this calculation", suggested_fn),
|
&format!("Calling `{}()` is more concise than this calculation", suggested_fn),
|
||||||
"try",
|
"try",
|
||||||
format!("{}.{}()", snippet(cx, args[0].span, "_"), suggested_fn),
|
format!("{}.{}()", snippet(cx, args[0].span, "_"), suggested_fn),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, in_external_macro, LintContext};
|
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, in_external_macro, LintContext};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::*;
|
use crate::syntax::ast::*;
|
||||||
|
|
||||||
use crate::utils::span_lint_and_sugg;
|
use crate::utils::span_lint_and_sugg;
|
||||||
|
@ -72,7 +73,8 @@ impl EarlyLintPass for ElseIfWithoutElse {
|
||||||
els.span,
|
els.span,
|
||||||
"if expression with an `else if`, but without a final `else`",
|
"if expression with an `else if`, but without a final `else`",
|
||||||
"add an `else` block here",
|
"add an `else` block here",
|
||||||
String::new()
|
String::new(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,16 @@
|
||||||
|
|
||||||
use crate::rustc::hir;
|
use crate::rustc::hir;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::ty::TyKind;
|
use crate::rustc::ty::TyKind;
|
||||||
use std::f32;
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use std::f64;
|
use crate::rustc_errors::Applicability;
|
||||||
use std::fmt;
|
|
||||||
use crate::syntax::ast::*;
|
use crate::syntax::ast::*;
|
||||||
use crate::syntax_pos::symbol::Symbol;
|
use crate::syntax_pos::symbol::Symbol;
|
||||||
use crate::utils::span_lint_and_sugg;
|
use crate::utils::span_lint_and_sugg;
|
||||||
|
use if_chain::if_chain;
|
||||||
|
use std::f32;
|
||||||
|
use std::f64;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
/// **What it does:** Checks for float literals with a precision greater
|
/// **What it does:** Checks for float literals with a precision greater
|
||||||
/// than that supported by the underlying type
|
/// than that supported by the underlying type
|
||||||
|
@ -68,6 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
|
||||||
"float has excessive precision",
|
"float has excessive precision",
|
||||||
"consider changing the type or truncating it to",
|
"consider changing the type or truncating it to",
|
||||||
sugg,
|
sugg,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ use super::utils::{get_arg_name, match_var, remove_blocks, snippet, span_lint_an
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
|
||||||
/// **What it does:** Checks for matches being used to destructure a single-variant enum
|
/// **What it does:** Checks for matches being used to destructure a single-variant enum
|
||||||
|
@ -84,6 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
snippet(cx, local.pat.span, ".."),
|
snippet(cx, local.pat.span, ".."),
|
||||||
snippet(cx, target.span, ".."),
|
snippet(cx, target.span, ".."),
|
||||||
),
|
),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,10 @@
|
||||||
use crate::rustc::hir::def_id::DefId;
|
use crate::rustc::hir::def_id::DefId;
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use crate::rustc::ty;
|
use crate::rustc::ty;
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use crate::rustc_data_structures::fx::FxHashSet;
|
use crate::rustc_data_structures::fx::FxHashSet;
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::{Lit, LitKind, Name};
|
use crate::syntax::ast::{Lit, LitKind, Name};
|
||||||
use crate::syntax::source_map::{Span, Spanned};
|
use crate::syntax::source_map::{Span, Spanned};
|
||||||
use crate::utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_sugg, walk_ptrs_ty};
|
use crate::utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_sugg, walk_ptrs_ty};
|
||||||
|
@ -242,6 +243,7 @@ fn check_len(cx: &LateContext<'_, '_>, span: Span, method_name: Name, args: &[Ex
|
||||||
&format!("length comparison to {}", if compare_to == 0 { "zero" } else { "one" }),
|
&format!("length comparison to {}", if compare_to == 0 { "zero" } else { "one" }),
|
||||||
"using `is_empty` is clearer and more explicit",
|
"using `is_empty` is clearer and more explicit",
|
||||||
format!("{}{}.is_empty()", op, snippet(cx, args[0].span, "_")),
|
format!("{}{}.is_empty()", op, snippet(cx, args[0].span, "_")),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
use crate::rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
|
use crate::rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::*;
|
use crate::syntax::ast::*;
|
||||||
use crate::syntax_pos;
|
use crate::syntax_pos;
|
||||||
use crate::utils::{snippet_opt, span_lint_and_sugg};
|
use crate::utils::{snippet_opt, span_lint_and_sugg};
|
||||||
|
@ -300,6 +301,7 @@ impl WarningType {
|
||||||
"mistyped literal suffix",
|
"mistyped literal suffix",
|
||||||
"did you mean to write",
|
"did you mean to write",
|
||||||
grouping_hint.to_string(),
|
grouping_hint.to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
),
|
),
|
||||||
WarningType::UnreadableLiteral => span_lint_and_sugg(
|
WarningType::UnreadableLiteral => span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
|
@ -308,6 +310,7 @@ impl WarningType {
|
||||||
"long literal lacking separators",
|
"long literal lacking separators",
|
||||||
"consider",
|
"consider",
|
||||||
grouping_hint.to_owned(),
|
grouping_hint.to_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
),
|
),
|
||||||
WarningType::LargeDigitGroups => span_lint_and_sugg(
|
WarningType::LargeDigitGroups => span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
|
@ -316,6 +319,7 @@ impl WarningType {
|
||||||
"digit groups should be smaller",
|
"digit groups should be smaller",
|
||||||
"consider",
|
"consider",
|
||||||
grouping_hint.to_owned(),
|
grouping_hint.to_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
),
|
),
|
||||||
WarningType::InconsistentDigitGrouping => span_lint_and_sugg(
|
WarningType::InconsistentDigitGrouping => span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
|
@ -324,6 +328,7 @@ impl WarningType {
|
||||||
"digits grouped inconsistently by underscores",
|
"digits grouped inconsistently by underscores",
|
||||||
"consider",
|
"consider",
|
||||||
grouping_hint.to_owned(),
|
grouping_hint.to_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
),
|
),
|
||||||
WarningType::DecimalRepresentation => span_lint_and_sugg(
|
WarningType::DecimalRepresentation => span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
|
@ -332,6 +337,7 @@ impl WarningType {
|
||||||
"integer literal has a better hexadecimal representation",
|
"integer literal has a better hexadecimal representation",
|
||||||
"consider",
|
"consider",
|
||||||
grouping_hint.to_owned(),
|
grouping_hint.to_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,6 +512,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
snippet(cx, arms[0].pats[0].span, ".."),
|
snippet(cx, arms[0].pats[0].span, ".."),
|
||||||
snippet(cx, matchexpr.span, "..")
|
snippet(cx, matchexpr.span, "..")
|
||||||
),
|
),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -549,6 +550,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
"this loop could be written as a `for` loop",
|
"this loop could be written as a `for` loop",
|
||||||
"try",
|
"try",
|
||||||
format!("for {} in {} {{ .. }}", loop_var, iterator),
|
format!("for {} in {} {{ .. }}", loop_var, iterator),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1027,6 +1029,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
|
||||||
"it looks like you're manually copying between slices",
|
"it looks like you're manually copying between slices",
|
||||||
"try replacing the loop by",
|
"try replacing the loop by",
|
||||||
big_sugg,
|
big_sugg,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1316,6 +1319,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_
|
||||||
iteration methods",
|
iteration methods",
|
||||||
"to write this more concisely, try",
|
"to write this more concisely, try",
|
||||||
format!("&{}{}", muta, object),
|
format!("&{}{}", muta, object),
|
||||||
|
Applicability::Unspecified,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1354,6 +1358,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex
|
||||||
iteration methods`",
|
iteration methods`",
|
||||||
"to write this more concisely, try",
|
"to write this more concisely, try",
|
||||||
object.to_string(),
|
object.to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if method_name == "next" && match_trait_method(cx, arg, &paths::ITERATOR) {
|
} else if method_name == "next" && match_trait_method(cx, arg, &paths::ITERATOR) {
|
||||||
|
|
|
@ -11,15 +11,12 @@
|
||||||
use crate::rustc::hir;
|
use crate::rustc::hir;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
|
use crate::syntax::ast::Ident;
|
||||||
use crate::syntax::source_map::Span;
|
use crate::syntax::source_map::Span;
|
||||||
use crate::utils::paths;
|
use crate::utils::paths;
|
||||||
use crate::utils::{
|
use crate::utils::{in_macro, match_trait_method, match_type, remove_blocks, snippet, span_lint_and_sugg};
|
||||||
in_macro, match_trait_method, match_type,
|
|
||||||
remove_blocks, snippet,
|
|
||||||
span_lint_and_sugg,
|
|
||||||
};
|
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use crate::syntax::ast::Ident;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Pass;
|
pub struct Pass;
|
||||||
|
@ -102,6 +99,7 @@ fn lint(cx: &LateContext<'_, '_>, replace: Span, root: Span, name: Ident, path:
|
||||||
"You are using an explicit closure for cloning elements",
|
"You are using an explicit closure for cloning elements",
|
||||||
"Consider calling the dedicated `cloned` method",
|
"Consider calling the dedicated `cloned` method",
|
||||||
format!("{}.cloned()", snippet(cx, root, "..")),
|
format!("{}.cloned()", snippet(cx, root, "..")),
|
||||||
|
Applicability::Unspecified,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,8 +268,9 @@ fn report_single_match_single_pattern(cx: &LateContext<'_, '_>, ex: &Expr, arms:
|
||||||
snippet(cx, arms[0].pats[0].span, ".."),
|
snippet(cx, arms[0].pats[0].span, ".."),
|
||||||
snippet(cx, ex.span, ".."),
|
snippet(cx, ex.span, ".."),
|
||||||
expr_block(cx, &arms[0].body, None, ".."),
|
expr_block(cx, &arms[0].body, None, ".."),
|
||||||
els_str
|
els_str,
|
||||||
),
|
),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,7 +484,8 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("use {}() instead", suggestion),
|
&format!("use {}() instead", suggestion),
|
||||||
"try this",
|
"try this",
|
||||||
format!("{}.{}()", snippet(cx, ex.span, "_"), suggestion)
|
format!("{}.{}()", snippet(cx, ex.span, "_"), suggestion),
|
||||||
|
Applicability::Unspecified,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
use crate::rustc::hir::{Expr, ExprKind, MutMutable, QPath};
|
use crate::rustc::hir::{Expr, ExprKind, MutMutable, QPath};
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::utils::{match_def_path, match_qpath, opt_def_id, paths, snippet, span_lint_and_sugg};
|
use crate::utils::{match_def_path, match_qpath, opt_def_id, paths, snippet, span_lint_and_sugg};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
|
||||||
|
@ -85,7 +86,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
|
||||||
expr.span,
|
expr.span,
|
||||||
"replacing an `Option` with `None`",
|
"replacing an `Option` with `None`",
|
||||||
"consider `Option::take()` instead",
|
"consider `Option::take()` instead",
|
||||||
format!("{}.take()", snippet(cx, replaced_path.span, ""))
|
format!("{}.take()", snippet(cx, replaced_path.span, "")),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1042,6 +1042,7 @@ fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Spa
|
||||||
&format!("use of `{}` followed by a call to `{}`", name, path),
|
&format!("use of `{}` followed by a call to `{}`", name, path),
|
||||||
"try this",
|
"try this",
|
||||||
format!("{}.unwrap_or_default()", snippet(cx, self_expr.span, "_")),
|
format!("{}.unwrap_or_default()", snippet(cx, self_expr.span, "_")),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1111,6 +1112,7 @@ fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Spa
|
||||||
&format!("use of `{}` followed by a function call", name),
|
&format!("use of `{}` followed by a function call", name),
|
||||||
"try this",
|
"try this",
|
||||||
format!("{}_{}({})", name, suffix, sugg),
|
format!("{}_{}({})", name, suffix, sugg),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1224,6 +1226,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
||||||
&format!("use of `{}` followed by a function call", name),
|
&format!("use of `{}` followed by a function call", name),
|
||||||
"try this",
|
"try this",
|
||||||
format!("unwrap_or_else({} panic!({}))", closure, sugg),
|
format!("unwrap_or_else({} panic!({}))", closure, sugg),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -1238,6 +1241,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
||||||
&format!("use of `{}` followed by a function call", name),
|
&format!("use of `{}` followed by a function call", name),
|
||||||
"try this",
|
"try this",
|
||||||
format!("unwrap_or_else({} {{ let msg = {}; panic!(msg) }}))", closure, sugg),
|
format!("unwrap_or_else({} {{ let msg = {}; panic!(msg) }}))", closure, sugg),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1354,6 +1358,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::
|
||||||
"using '.clone()' on a ref-counted pointer",
|
"using '.clone()' on a ref-counted pointer",
|
||||||
"try this",
|
"try this",
|
||||||
format!("{}::<{}>::clone(&{})", caller_type, subst.type_at(0), snippet(cx, arg.span, "_")),
|
format!("{}::<{}>::clone(&{})", caller_type, subst.type_at(0), snippet(cx, arg.span, "_")),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1384,6 +1389,7 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::E
|
||||||
ref_str,
|
ref_str,
|
||||||
snippet(cx, target.span, "_")
|
snippet(cx, target.span, "_")
|
||||||
),
|
),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1482,6 +1488,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
|
||||||
"this `.fold` can be written more succinctly using another method",
|
"this `.fold` can be written more succinctly using another method",
|
||||||
"try",
|
"try",
|
||||||
sugg,
|
sugg,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1589,6 +1596,7 @@ fn lint_get_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr, get_args: &[hir::
|
||||||
snippet(cx, get_args[0].span, "_"),
|
snippet(cx, get_args[0].span, "_"),
|
||||||
get_args_str
|
get_args_str
|
||||||
),
|
),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2010,7 +2018,8 @@ fn lint_chars_cmp(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
span_lint_and_sugg(cx,
|
span_lint_and_sugg(
|
||||||
|
cx,
|
||||||
lint,
|
lint,
|
||||||
info.expr.span,
|
info.expr.span,
|
||||||
&format!("you should use the `{}` method", suggest),
|
&format!("you should use the `{}` method", suggest),
|
||||||
|
@ -2019,7 +2028,9 @@ fn lint_chars_cmp(
|
||||||
if info.eq { "" } else { "!" },
|
if info.eq { "" } else { "!" },
|
||||||
snippet(cx, args[0][0].span, "_"),
|
snippet(cx, args[0][0].span, "_"),
|
||||||
suggest,
|
suggest,
|
||||||
snippet(cx, arg_char[0].span, "_")));
|
snippet(cx, arg_char[0].span, "_")),
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2065,7 +2076,8 @@ fn lint_chars_cmp_with_unwrap<'a, 'tcx>(
|
||||||
if info.eq { "" } else { "!" },
|
if info.eq { "" } else { "!" },
|
||||||
snippet(cx, args[0][0].span, "_"),
|
snippet(cx, args[0][0].span, "_"),
|
||||||
suggest,
|
suggest,
|
||||||
c)
|
c),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -2105,6 +2117,7 @@ fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx h
|
||||||
"single-character string constant used as pattern",
|
"single-character string constant used as pattern",
|
||||||
"try using a char instead",
|
"try using a char instead",
|
||||||
hint,
|
hint,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2129,6 +2142,7 @@ fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_re
|
||||||
&format!("this call to `{}` does nothing", call_name),
|
&format!("this call to `{}` does nothing", call_name),
|
||||||
"try this",
|
"try this",
|
||||||
snippet(cx, recvr.span, "_").into_owned(),
|
snippet(cx, recvr.span, "_").into_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2194,6 +2208,7 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: ty::T
|
||||||
),
|
),
|
||||||
"call directly",
|
"call directly",
|
||||||
method_name.to_owned(),
|
method_name.to_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,14 @@
|
||||||
//!
|
//!
|
||||||
//! This lint is **warn** by default
|
//! This lint is **warn** by default
|
||||||
|
|
||||||
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::LitKind;
|
use crate::syntax::ast::LitKind;
|
||||||
use crate::syntax::source_map::Spanned;
|
use crate::syntax::source_map::Spanned;
|
||||||
use crate::utils::{in_macro, snippet, span_lint, span_lint_and_sugg};
|
|
||||||
use crate::utils::sugg::Sugg;
|
use crate::utils::sugg::Sugg;
|
||||||
|
use crate::utils::{in_macro, snippet, span_lint, span_lint_and_sugg};
|
||||||
|
|
||||||
/// **What it does:** Checks for expressions of the form `if c { true } else {
|
/// **What it does:** Checks for expressions of the form `if c { true } else {
|
||||||
/// false }`
|
/// false }`
|
||||||
|
@ -89,6 +90,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
||||||
"this if-then-else expression returns a bool literal",
|
"this if-then-else expression returns a bool literal",
|
||||||
"you can reduce it to",
|
"you can reduce it to",
|
||||||
hint,
|
hint,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
if let ExprKind::Block(ref then_block, _) = then_block.node {
|
if let ExprKind::Block(ref then_block, _) = then_block.node {
|
||||||
|
@ -150,6 +152,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
|
||||||
"equality checks against true are unnecessary",
|
"equality checks against true are unnecessary",
|
||||||
"try simplifying it as shown",
|
"try simplifying it as shown",
|
||||||
hint,
|
hint,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
(Other, Bool(true)) => {
|
(Other, Bool(true)) => {
|
||||||
|
@ -161,6 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
|
||||||
"equality checks against true are unnecessary",
|
"equality checks against true are unnecessary",
|
||||||
"try simplifying it as shown",
|
"try simplifying it as shown",
|
||||||
hint,
|
hint,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
(Bool(false), Other) => {
|
(Bool(false), Other) => {
|
||||||
|
@ -172,6 +176,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
|
||||||
"equality checks against false can be replaced by a negation",
|
"equality checks against false can be replaced by a negation",
|
||||||
"try simplifying it as shown",
|
"try simplifying it as shown",
|
||||||
(!hint).to_string(),
|
(!hint).to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
(Other, Bool(false)) => {
|
(Other, Bool(false)) => {
|
||||||
|
@ -183,6 +188,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
|
||||||
"equality checks against false can be replaced by a negation",
|
"equality checks against false can be replaced by a negation",
|
||||||
"try simplifying it as shown",
|
"try simplifying it as shown",
|
||||||
(!hint).to_string(),
|
(!hint).to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -8,10 +8,11 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use crate::rustc::hir::def::Def;
|
use crate::rustc::hir::def::Def;
|
||||||
use crate::rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource};
|
use crate::rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource};
|
||||||
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::utils::{has_drop, in_macro, snippet_opt, span_lint, span_lint_and_sugg};
|
use crate::utils::{has_drop, in_macro, snippet_opt, span_lint, span_lint_and_sugg};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
@ -131,6 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
"statement can be reduced",
|
"statement can be reduced",
|
||||||
"replace it with",
|
"replace it with",
|
||||||
snippet,
|
snippet,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::*;
|
use crate::syntax::ast::*;
|
||||||
use crate::syntax::source_map::Spanned;
|
use crate::syntax::source_map::Spanned;
|
||||||
use crate::utils::{in_macro, snippet, span_lint_and_sugg};
|
use crate::utils::{in_macro, snippet, span_lint_and_sugg};
|
||||||
|
@ -61,6 +62,7 @@ impl EarlyLintPass for Precedence {
|
||||||
"operator precedence can trip the unwary",
|
"operator precedence can trip the unwary",
|
||||||
"consider parenthesizing your expression",
|
"consider parenthesizing your expression",
|
||||||
sugg,
|
sugg,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,6 +114,7 @@ impl EarlyLintPass for Precedence {
|
||||||
"unary minus has lower precedence than method call",
|
"unary minus has lower precedence than method call",
|
||||||
"consider adding parentheses to clarify your intent",
|
"consider adding parentheses to clarify your intent",
|
||||||
format!("-({})", snippet(cx, rhs.span, "..")),
|
format!("-({})", snippet(cx, rhs.span, "..")),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
|
|
||||||
use crate::rustc::{declare_tool_lint, hir, lint, lint_array};
|
use crate::rustc::{declare_tool_lint, hir, lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
@ -69,7 +70,15 @@ impl<'a, 'tcx> lint::LateLintPass<'a, 'tcx> for Pass {
|
||||||
|
|
||||||
let msg = format!("use of `{}` with a `usize` casted to an `isize`", method);
|
let msg = format!("use of `{}` with a `usize` casted to an `isize`", method);
|
||||||
if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
|
if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
|
||||||
utils::span_lint_and_sugg(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg, "try", sugg);
|
utils::span_lint_and_sugg(
|
||||||
|
cx,
|
||||||
|
PTR_OFFSET_WITH_CAST,
|
||||||
|
expr.span,
|
||||||
|
&msg,
|
||||||
|
"try",
|
||||||
|
sugg,
|
||||||
|
Applicability::Unspecified,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
utils::span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
|
utils::span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::*;
|
use crate::syntax::ast::*;
|
||||||
use crate::utils::{span_lint_and_sugg};
|
use crate::utils::{span_lint_and_sugg};
|
||||||
|
|
||||||
|
@ -64,7 +65,8 @@ impl EarlyLintPass for RedundantFieldNames {
|
||||||
field.span,
|
field.span,
|
||||||
"redundant field names in struct initialization",
|
"redundant field names in struct initialization",
|
||||||
"replace it with",
|
"replace it with",
|
||||||
field.ident.to_string()
|
field.ident.to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,12 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
use crate::syntax::ast::{Expr, ExprKind, UnOp};
|
|
||||||
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use if_chain::if_chain;
|
use crate::rustc_errors::Applicability;
|
||||||
|
use crate::syntax::ast::{Expr, ExprKind, UnOp};
|
||||||
use crate::utils::{snippet, span_lint_and_sugg};
|
use crate::utils::{snippet, span_lint_and_sugg};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
|
||||||
/// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
|
/// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
|
||||||
///
|
///
|
||||||
|
@ -61,6 +62,7 @@ impl EarlyLintPass for Pass {
|
||||||
"immediately dereferencing a reference",
|
"immediately dereferencing a reference",
|
||||||
"try this",
|
"try this",
|
||||||
format!("{}", snippet(cx, addrof_target.span, "_")),
|
format!("{}", snippet(cx, addrof_target.span, "_")),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,8 @@ impl EarlyLintPass for DerefPass {
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
snippet(cx, inner.span, "_"),
|
snippet(cx, inner.span, "_"),
|
||||||
snippet(cx, field_name.span, "_")
|
snippet(cx, field_name.span, "_")
|
||||||
)
|
),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,13 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::hir;
|
use crate::rustc::hir;
|
||||||
use crate::rustc::hir::def::Def;
|
use crate::rustc::hir::def::Def;
|
||||||
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::utils::{match_def_path, span_lint_and_sugg};
|
use crate::utils::{match_def_path, span_lint_and_sugg};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
|
||||||
/// **What it does:** Checks for usage of `ATOMIC_X_INIT`, `ONCE_INIT`, and
|
/// **What it does:** Checks for usage of `ATOMIC_X_INIT`, `ONCE_INIT`, and
|
||||||
/// `uX/iX::MIN/MAX`.
|
/// `uX/iX::MIN/MAX`.
|
||||||
|
@ -61,6 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts {
|
||||||
&format!("using `{}`", const_path.last().expect("empty path")),
|
&format!("using `{}`", const_path.last().expect("empty path")),
|
||||||
"try this",
|
"try this",
|
||||||
repl_snip.to_string(),
|
repl_snip.to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::source_map::Spanned;
|
use crate::syntax::source_map::Spanned;
|
||||||
use crate::utils::SpanlessEq;
|
use crate::utils::SpanlessEq;
|
||||||
use crate::utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty};
|
use crate::utils::{get_parent_expr, is_allowed, match_type, paths, span_lint, span_lint_and_sugg, walk_ptrs_ty};
|
||||||
|
@ -185,6 +186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
|
||||||
"calling `as_bytes()` on `include_str!(..)`",
|
"calling `as_bytes()` on `include_str!(..)`",
|
||||||
"consider using `include_bytes!(..)` instead",
|
"consider using `include_bytes!(..)` instead",
|
||||||
snippet(cx, args[0].span, r#""foo""#).replacen("include_str", "include_bytes", 1),
|
snippet(cx, args[0].span, r#""foo""#).replacen("include_str", "include_bytes", 1),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
} else if callsite == expanded
|
} else if callsite == expanded
|
||||||
&& lit_content.as_str().chars().all(|c| c.is_ascii())
|
&& lit_content.as_str().chars().all(|c| c.is_ascii())
|
||||||
|
@ -197,6 +199,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
|
||||||
"calling `as_bytes()` on a string literal",
|
"calling `as_bytes()` on a string literal",
|
||||||
"consider using a byte string literal instead",
|
"consider using a byte string literal instead",
|
||||||
format!("b{}", snippet(cx, args[0].span, r#""foo""#)),
|
format!("b{}", snippet(cx, args[0].span, r#""foo""#)),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,21 +10,21 @@
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use matches::matches;
|
|
||||||
use crate::rustc::hir;
|
use crate::rustc::hir;
|
||||||
use crate::rustc::hir::*;
|
|
||||||
use crate::rustc::hir::intravisit::FnKind;
|
use crate::rustc::hir::intravisit::FnKind;
|
||||||
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::ty::TyKind;
|
|
||||||
use crate::rustc::ty::FnSig;
|
|
||||||
use crate::rustc::session::config::Config as SessionConfig;
|
use crate::rustc::session::config::Config as SessionConfig;
|
||||||
use crate::rustc_target::spec::abi::Abi;
|
use crate::rustc::ty::TyKind;
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::rustc_target::abi::LayoutOf;
|
use crate::rustc_target::abi::LayoutOf;
|
||||||
|
use crate::rustc_target::spec::abi::Abi;
|
||||||
use crate::syntax::ast::NodeId;
|
use crate::syntax::ast::NodeId;
|
||||||
use crate::syntax_pos::Span;
|
use crate::syntax_pos::Span;
|
||||||
use crate::utils::{in_macro, is_copy, is_self_ty, span_lint_and_sugg, snippet};
|
use crate::utils::{in_macro, is_copy, is_self, snippet, span_lint_and_sugg};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
use matches::matches;
|
||||||
|
|
||||||
/// **What it does:** Checks for functions taking arguments by reference, where
|
/// **What it does:** Checks for functions taking arguments by reference, where
|
||||||
/// the argument type is `Copy` and small enough to be more efficient to always
|
/// the argument type is `Copy` and small enough to be more efficient to always
|
||||||
|
|
|
@ -10,28 +10,31 @@
|
||||||
|
|
||||||
#![allow(clippy::default_hash_types)]
|
#![allow(clippy::default_hash_types)]
|
||||||
|
|
||||||
|
use crate::consts::{constant, Constant};
|
||||||
use crate::reexport::*;
|
use crate::reexport::*;
|
||||||
use crate::rustc::hir;
|
use crate::rustc::hir;
|
||||||
use crate::rustc::hir::*;
|
|
||||||
use crate::rustc::hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
|
use crate::rustc::hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass, in_external_macro, LintContext};
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::ty::{self, Ty, TyCtxt, TypeckTables};
|
|
||||||
use crate::rustc::ty::layout::LayoutOf;
|
use crate::rustc::ty::layout::LayoutOf;
|
||||||
|
use crate::rustc::ty::{self, Ty, TyCtxt, TypeckTables};
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
|
use crate::rustc_target::spec::abi::Abi;
|
||||||
use crate::rustc_typeck::hir_ty_to_ty;
|
use crate::rustc_typeck::hir_ty_to_ty;
|
||||||
|
use crate::syntax::ast::{FloatTy, IntTy, UintTy};
|
||||||
|
use crate::syntax::errors::DiagnosticBuilder;
|
||||||
|
use crate::syntax::source_map::Span;
|
||||||
|
use crate::utils::paths;
|
||||||
|
use crate::utils::{
|
||||||
|
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, int_bits, last_path_segment,
|
||||||
|
match_def_path, match_path, match_type, multispan_sugg, opt_def_id, same_tys, sext, snippet, snippet_opt,
|
||||||
|
span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
|
||||||
|
};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::borrow::Cow;
|
|
||||||
use crate::syntax::ast::{FloatTy, IntTy, UintTy};
|
|
||||||
use crate::syntax::source_map::Span;
|
|
||||||
use crate::syntax::errors::DiagnosticBuilder;
|
|
||||||
use crate::rustc_target::spec::abi::Abi;
|
|
||||||
use crate::utils::{comparisons, differing_macro_contexts, higher, in_constant, in_macro, last_path_segment, match_def_path, match_path,
|
|
||||||
match_type, multispan_sugg, opt_def_id, same_tys, snippet, snippet_opt, span_help_and_lint, span_lint,
|
|
||||||
span_lint_and_sugg, span_lint_and_then, clip, unsext, sext, int_bits};
|
|
||||||
use crate::utils::paths;
|
|
||||||
use crate::consts::{constant, Constant};
|
|
||||||
|
|
||||||
/// Handles all the linting of funky types
|
/// Handles all the linting of funky types
|
||||||
pub struct TypePass;
|
pub struct TypePass;
|
||||||
|
@ -338,12 +341,14 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, ast_ty: &hir::Ty, is_local: bool, lt:
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
span_lint_and_sugg(cx,
|
span_lint_and_sugg(
|
||||||
|
cx,
|
||||||
BORROWED_BOX,
|
BORROWED_BOX,
|
||||||
ast_ty.span,
|
ast_ty.span,
|
||||||
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
|
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
|
||||||
"try",
|
"try",
|
||||||
format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, ".."))
|
format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}
|
}
|
||||||
|
@ -537,6 +542,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
||||||
"passing a unit value to a function",
|
"passing a unit value to a function",
|
||||||
"if you intended to pass a unit value, use a unit literal instead",
|
"if you intended to pass a unit value, use a unit literal instead",
|
||||||
"()".to_string(),
|
"()".to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -874,6 +880,7 @@ fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_fro
|
||||||
&format!("casting {} to {} may become silently lossy if types change", cast_from, cast_to),
|
&format!("casting {} to {} may become silently lossy if types change", cast_from, cast_to),
|
||||||
"try",
|
"try",
|
||||||
format!("{}::from({})", cast_to, sugg),
|
format!("{}::from({})", cast_to, sugg),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,7 +1110,8 @@ fn lint_fn_to_numeric_cast(cx: &LateContext<'_, '_>, expr: &Expr, cast_expr: &Ex
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("casting function pointer `{}` to `{}`, which truncates the value", from_snippet, cast_to),
|
&format!("casting function pointer `{}` to `{}`, which truncates the value", from_snippet, cast_to),
|
||||||
"try",
|
"try",
|
||||||
format!("{} as usize", from_snippet)
|
format!("{} as usize", from_snippet),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if cast_to.sty != ty::Uint(UintTy::Usize) {
|
} else if cast_to.sty != ty::Uint(UintTy::Usize) {
|
||||||
|
@ -1113,7 +1121,8 @@ fn lint_fn_to_numeric_cast(cx: &LateContext<'_, '_>, expr: &Expr, cast_expr: &Ex
|
||||||
expr.span,
|
expr.span,
|
||||||
&format!("casting function pointer `{}` to `{}`", from_snippet, cast_to),
|
&format!("casting function pointer `{}` to `{}`", from_snippet, cast_to),
|
||||||
"try",
|
"try",
|
||||||
format!("{} as usize", from_snippet)
|
format!("{} as usize", from_snippet),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,15 +8,16 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
use crate::utils::{in_macro, span_lint_and_sugg};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::hir::intravisit::{walk_path, walk_ty, NestedVisitorMap, Visitor};
|
use crate::rustc::hir::intravisit::{walk_path, walk_ty, NestedVisitorMap, Visitor};
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::ty;
|
use crate::rustc::ty;
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use crate::syntax_pos::symbol::keywords::SelfType;
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::NodeId;
|
use crate::syntax::ast::NodeId;
|
||||||
|
use crate::syntax_pos::symbol::keywords::SelfType;
|
||||||
|
use crate::utils::{in_macro, span_lint_and_sugg};
|
||||||
|
use if_chain::if_chain;
|
||||||
|
|
||||||
/// **What it does:** Checks for unnecessary repetition of structure name when a
|
/// **What it does:** Checks for unnecessary repetition of structure name when a
|
||||||
/// replacement with `Self` is applicable.
|
/// replacement with `Self` is applicable.
|
||||||
|
@ -70,6 +71,7 @@ fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path) {
|
||||||
"unnecessary structure name repetition",
|
"unnecessary structure name repetition",
|
||||||
"use the applicable keyword",
|
"use the applicable keyword",
|
||||||
"Self".to_owned(),
|
"Self".to_owned(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ use crate::rustc::hir::*;
|
||||||
use crate::rustc::hir::def::Def;
|
use crate::rustc::hir::def::Def;
|
||||||
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use crate::syntax::ast::{Crate as AstCrate, Ident, ItemKind, Name};
|
use crate::syntax::ast::{Crate as AstCrate, Ident, ItemKind, Name};
|
||||||
use crate::syntax::source_map::Span;
|
use crate::syntax::source_map::Span;
|
||||||
|
@ -281,6 +282,7 @@ impl EarlyLintPass for DefaultHashTypes {
|
||||||
&msg,
|
&msg,
|
||||||
"use",
|
"use",
|
||||||
replace.to_string(),
|
replace.to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -657,9 +657,10 @@ pub fn span_lint_and_sugg<'a, 'tcx: 'a, T: LintContext<'tcx>>(
|
||||||
msg: &str,
|
msg: &str,
|
||||||
help: &str,
|
help: &str,
|
||||||
sugg: String,
|
sugg: String,
|
||||||
|
applicability: Applicability,
|
||||||
) {
|
) {
|
||||||
span_lint_and_then(cx, lint, sp, msg, |db| {
|
span_lint_and_then(cx, lint, sp, msg, |db| {
|
||||||
db.span_suggestion_with_applicability(sp, help, sugg, Applicability::Unspecified);
|
db.span_suggestion_with_applicability(sp, help, sugg, applicability);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,15 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
|
use crate::consts::constant;
|
||||||
use crate::rustc::hir::*;
|
use crate::rustc::hir::*;
|
||||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
|
||||||
use if_chain::if_chain;
|
|
||||||
use crate::rustc::ty::{self, Ty};
|
use crate::rustc::ty::{self, Ty};
|
||||||
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::source_map::Span;
|
use crate::syntax::source_map::Span;
|
||||||
use crate::utils::{higher, is_copy, snippet, span_lint_and_sugg};
|
use crate::utils::{higher, is_copy, snippet, span_lint_and_sugg};
|
||||||
use crate::consts::constant;
|
use if_chain::if_chain;
|
||||||
|
|
||||||
/// **What it does:** Checks for usage of `&vec![..]` when using `&[..]` would
|
/// **What it does:** Checks for usage of `&vec![..]` when using `&[..]` would
|
||||||
/// be possible.
|
/// be possible.
|
||||||
|
@ -100,6 +101,7 @@ fn check_vec_macro<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, vec_args: &higher::VecA
|
||||||
"useless use of `vec!`",
|
"useless use of `vec!`",
|
||||||
"you can use a slice directly",
|
"you can use a slice directly",
|
||||||
snippet,
|
snippet,
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,14 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
use crate::utils::{snippet, span_lint, span_lint_and_sugg};
|
|
||||||
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||||
use crate::rustc::{declare_tool_lint, lint_array};
|
use crate::rustc::{declare_tool_lint, lint_array};
|
||||||
use std::borrow::Cow;
|
use crate::rustc_errors::Applicability;
|
||||||
use crate::syntax::ast::*;
|
use crate::syntax::ast::*;
|
||||||
use crate::syntax::parse::{parser, token};
|
use crate::syntax::parse::{parser, token};
|
||||||
use crate::syntax::tokenstream::{ThinTokenStream, TokenStream};
|
use crate::syntax::tokenstream::{ThinTokenStream, TokenStream};
|
||||||
|
use crate::utils::{snippet, span_lint, span_lint_and_sugg};
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
/// **What it does:** This lint warns when you use `println!("")` to
|
/// **What it does:** This lint warns when you use `println!("")` to
|
||||||
/// print a newline.
|
/// print a newline.
|
||||||
|
@ -199,6 +200,7 @@ impl EarlyLintPass for Pass {
|
||||||
"using `println!(\"\")`",
|
"using `println!(\"\")`",
|
||||||
"replace it with",
|
"replace it with",
|
||||||
"println!()".to_string(),
|
"println!()".to_string(),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,6 +250,7 @@ impl EarlyLintPass for Pass {
|
||||||
format!("using `writeln!({}, \"\")`", suggestion).as_str(),
|
format!("using `writeln!({}, \"\")`", suggestion).as_str(),
|
||||||
"replace it with",
|
"replace it with",
|
||||||
format!("writeln!({})", suggestion),
|
format!("writeln!({})", suggestion),
|
||||||
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue