mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Normalize lint messages
This commit is contained in:
parent
fdccfe7bca
commit
5ac08b0cc9
45 changed files with 133 additions and 127 deletions
|
@ -209,7 +209,7 @@ fn lint_misrefactored_assign_op(
|
|||
db.span_suggestion(
|
||||
expr.span,
|
||||
&format!(
|
||||
"Did you mean {} = {} {} {} or {}? Consider replacing it with",
|
||||
"Did you mean `{} = {} {} {}` or `{}`? Consider replacing it with",
|
||||
snip_a,
|
||||
snip_a,
|
||||
op.node.as_str(),
|
||||
|
|
|
@ -449,7 +449,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
|
|||
EMPTY_LINE_AFTER_OUTER_ATTR,
|
||||
begin_of_attr_to_item,
|
||||
"Found an empty line after an outer attribute. \
|
||||
Perhaps you forgot to add a '!' to make it an inner attribute?",
|
||||
Perhaps you forgot to add a `!` to make it an inner attribute?",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ impl EarlyLintPass for DeprecatedCfgAttribute {
|
|||
cx,
|
||||
DEPRECATED_CFG_ATTR,
|
||||
attr.span,
|
||||
"`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",
|
||||
"#[rustfmt::skip]".to_string(),
|
||||
Applicability::MachineApplicable,
|
||||
|
|
|
@ -68,8 +68,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition";
|
||||
const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks or closures with blocks; \
|
||||
instead, move the block or closure higher and bind it with a 'let'";
|
||||
const COMPLEX_BLOCK_MESSAGE: &str = "in an `if` condition, avoid complex blocks or closures with blocks; \
|
||||
instead, move the block or closure higher and bind it with a `let`";
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
|
|
|
@ -138,7 +138,7 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
|
|||
if expr.span.ctxt() != inner.span.ctxt() {
|
||||
return;
|
||||
}
|
||||
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| {
|
||||
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |db| {
|
||||
let lhs = Sugg::ast(cx, check, "..");
|
||||
let rhs = Sugg::ast(cx, check_inner, "..");
|
||||
db.span_suggestion(
|
||||
|
|
|
@ -38,7 +38,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub IFS_SAME_COND,
|
||||
correctness,
|
||||
"consecutive `ifs` with the same condition"
|
||||
"consecutive `if`s with the same condition"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -85,7 +85,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub SAME_FUNCTIONS_IN_IF_CONDITION,
|
||||
pedantic,
|
||||
"consecutive `ifs` with the same function call"
|
||||
"consecutive `if`s with the same function call"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -106,7 +106,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub IF_SAME_THEN_ELSE,
|
||||
correctness,
|
||||
"if with the same *then* and *else* blocks"
|
||||
"`if` with the same `then` and `else` blocks"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -206,7 +206,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
|
|||
cx,
|
||||
IFS_SAME_COND,
|
||||
j.span,
|
||||
"this `if` has the same condition as a previous if",
|
||||
"this `if` has the same condition as a previous `if`",
|
||||
i.span,
|
||||
"same as this",
|
||||
);
|
||||
|
@ -234,7 +234,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
|
|||
cx,
|
||||
SAME_FUNCTIONS_IN_IF_CONDITION,
|
||||
j.span,
|
||||
"this `if` has the same function call as a previous if",
|
||||
"this `if` has the same function call as a previous `if`",
|
||||
i.span,
|
||||
"same as this",
|
||||
);
|
||||
|
@ -300,7 +300,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
|
|||
db.span_note(
|
||||
i.body.span,
|
||||
&format!(
|
||||
"`{}` has the same arm body as the `_` wildcard, consider removing it`",
|
||||
"`{}` has the same arm body as the `_` wildcard, consider removing it",
|
||||
lhs
|
||||
),
|
||||
);
|
||||
|
|
|
@ -26,7 +26,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub DEFAULT_TRAIT_ACCESS,
|
||||
pedantic,
|
||||
"checks for literal calls to Default::default()"
|
||||
"checks for literal calls to `Default::default()`"
|
||||
}
|
||||
|
||||
declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]);
|
||||
|
@ -62,7 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
|
|||
cx,
|
||||
DEFAULT_TRAIT_ACCESS,
|
||||
expr.span,
|
||||
&format!("Calling {} is more clear than this expression", replacement),
|
||||
&format!("Calling `{}` is more clear than this expression", replacement),
|
||||
"try",
|
||||
replacement,
|
||||
Applicability::Unspecified, // First resolve the TODO above
|
||||
|
|
|
@ -102,9 +102,9 @@ const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference inste
|
|||
Dropping a reference does nothing.";
|
||||
const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \
|
||||
Forgetting a reference does nothing.";
|
||||
const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements Copy. \
|
||||
const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \
|
||||
Dropping a copy leaves the original intact.";
|
||||
const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements Copy. \
|
||||
const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \
|
||||
Forgetting a copy leaves the original intact.";
|
||||
|
||||
declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]);
|
||||
|
@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
|
|||
expr.span,
|
||||
&msg,
|
||||
arg.span,
|
||||
&format!("argument has type {}", arg_ty));
|
||||
&format!("argument has type `{}`", arg_ty));
|
||||
} else if is_copy(cx, arg_ty) {
|
||||
if match_def_path(cx, def_id, &paths::DROP) {
|
||||
lint = DROP_COPY;
|
||||
|
|
|
@ -43,7 +43,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub ELSE_IF_WITHOUT_ELSE,
|
||||
restriction,
|
||||
"if expression with an `else if`, but without a final `else` branch"
|
||||
"`if` expression with an `else if`, but without a final `else` branch"
|
||||
}
|
||||
|
||||
declare_lint_pass!(ElseIfWithoutElse => [ELSE_IF_WITHOUT_ELSE]);
|
||||
|
@ -60,7 +60,7 @@ impl EarlyLintPass for ElseIfWithoutElse {
|
|||
cx,
|
||||
ELSE_IF_WITHOUT_ELSE,
|
||||
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",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat {
|
|||
|
||||
// Operate on the only argument of `alloc::fmt::format`.
|
||||
if let Some(sugg) = on_new_v1(cx, expr) {
|
||||
span_useless_format(cx, span, "consider using .to_string()", sugg);
|
||||
span_useless_format(cx, span, "consider using `.to_string()`", sugg);
|
||||
} else if let Some(sugg) = on_new_v1_fmt(cx, expr) {
|
||||
span_useless_format(cx, span, "consider using .to_string()", sugg);
|
||||
span_useless_format(cx, span, "consider using `.to_string()`", sugg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ impl EarlyLintPass for IfNotElse {
|
|||
IF_NOT_ELSE,
|
||||
item.span,
|
||||
"Unnecessary boolean `not` operation",
|
||||
"remove the `!` and swap the blocks of the if/else",
|
||||
"remove the `!` and swap the blocks of the `if`/`else`",
|
||||
);
|
||||
},
|
||||
ExprKind::Binary(ref kind, _, _) if kind.node == BinOpKind::Ne => {
|
||||
|
@ -70,7 +70,7 @@ impl EarlyLintPass for IfNotElse {
|
|||
IF_NOT_ELSE,
|
||||
item.span,
|
||||
"Unnecessary `!=` operation",
|
||||
"change to `==` and swap the blocks of the if/else",
|
||||
"change to `==` and swap the blocks of the `if`/`else`",
|
||||
);
|
||||
},
|
||||
_ => (),
|
||||
|
|
|
@ -51,7 +51,7 @@ fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str)
|
|||
let outer_span = outer_span.source_callsite();
|
||||
let inner_span = inner_span.source_callsite();
|
||||
|
||||
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
|
||||
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing `return` statement", |db| {
|
||||
if let Some(snippet) = snippet_opt(cx, inner_span) {
|
||||
db.span_suggestion(
|
||||
outer_span,
|
||||
|
@ -102,7 +102,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
|||
expr_match(cx, &arm.body);
|
||||
}
|
||||
} else {
|
||||
expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body);
|
||||
expr_match(cx, &arms.first().expect("`if let` doesn't have a single arm").body);
|
||||
}
|
||||
},
|
||||
// skip if it already has a return statement
|
||||
|
|
|
@ -38,7 +38,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub INFALLIBLE_DESTRUCTURING_MATCH,
|
||||
style,
|
||||
"a match statement with a single infallible arm instead of a `let`"
|
||||
"a `match` statement with a single infallible arm instead of a `let`"
|
||||
}
|
||||
|
||||
declare_lint_pass!(InfallibleDestructingMatch => [INFALLIBLE_DESTRUCTURING_MATCH]);
|
||||
|
@ -61,7 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfallibleDestructingMatch {
|
|||
cx,
|
||||
INFALLIBLE_DESTRUCTURING_MATCH,
|
||||
local.span,
|
||||
"you seem to be trying to use match to destructure a single infallible pattern. \
|
||||
"you seem to be trying to use `match` to destructure a single infallible pattern. \
|
||||
Consider using `let`",
|
||||
"try this",
|
||||
format!(
|
||||
|
|
|
@ -88,7 +88,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub INHERENT_TO_STRING_SHADOW_DISPLAY,
|
||||
correctness,
|
||||
"type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait "
|
||||
"type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait"
|
||||
}
|
||||
|
||||
declare_lint_pass!(InherentToString => [INHERENT_TO_STRING, INHERENT_TO_STRING_SHADOW_DISPLAY]);
|
||||
|
|
|
@ -32,7 +32,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub INT_PLUS_ONE,
|
||||
complexity,
|
||||
"instead of using x >= y + 1, use x > y"
|
||||
"instead of using `x >= y + 1`, use `x > y`"
|
||||
}
|
||||
|
||||
declare_lint_pass!(IntPlusOne => [INT_PLUS_ONE]);
|
||||
|
|
|
@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays {
|
|||
self.maximum_allowed_size
|
||||
),
|
||||
&format!(
|
||||
"consider allocating on the heap with vec!{}.into_boxed_slice()",
|
||||
"consider allocating on the heap with `vec!{}.into_boxed_slice()`",
|
||||
snippet(cx, expr.span, "[...]")
|
||||
),
|
||||
);
|
||||
|
|
|
@ -27,7 +27,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub LET_UNDERSCORE_MUST_USE,
|
||||
restriction,
|
||||
"non-binding let on a #[must_use] expression"
|
||||
"non-binding let on a `#[must_use]` expression"
|
||||
}
|
||||
|
||||
declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE]);
|
||||
|
@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
|
|||
cx,
|
||||
LET_UNDERSCORE_MUST_USE,
|
||||
stmt.span,
|
||||
"non-binding let on an expression with #[must_use] type",
|
||||
"non-binding let on an expression with `#[must_use]` type",
|
||||
"consider explicitly using expression value"
|
||||
)
|
||||
} else if is_must_use_func_call(cx, init) {
|
||||
|
@ -52,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
|
|||
cx,
|
||||
LET_UNDERSCORE_MUST_USE,
|
||||
stmt.span,
|
||||
"non-binding let on a result of a #[must_use] function",
|
||||
"non-binding let on a result of a `#[must_use]` function",
|
||||
"consider explicitly using function result"
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1353,7 +1353,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat<'_>, arg: &Expr<'_>, e
|
|||
EXPLICIT_INTO_ITER_LOOP,
|
||||
arg.span,
|
||||
"it is more concise to loop over containers instead of using explicit \
|
||||
iteration methods`",
|
||||
iteration methods",
|
||||
"to write this more concisely, try",
|
||||
object.to_string(),
|
||||
applicability,
|
||||
|
|
|
@ -112,7 +112,7 @@ fn lint_needless_cloning(cx: &LateContext<'_, '_>, root: Span, receiver: Span) {
|
|||
MAP_CLONE,
|
||||
root.trim_start(receiver).unwrap(),
|
||||
"You are needlessly cloning iterator elements",
|
||||
"Remove the map call",
|
||||
"Remove the `map` call",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
|
|
|
@ -48,7 +48,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub OPTION_MAP_UNIT_FN,
|
||||
complexity,
|
||||
"using `option.map(f)`, where f is a function or closure that returns ()"
|
||||
"using `option.map(f)`, where `f` is a function or closure that returns `()`"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -89,7 +89,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub RESULT_MAP_UNIT_FN,
|
||||
complexity,
|
||||
"using `result.map(f)`, where f is a function or closure that returns ()"
|
||||
"using `result.map(f)`, where `f` is a function or closure that returns `()`"
|
||||
}
|
||||
|
||||
declare_lint_pass!(MapUnit => [OPTION_MAP_UNIT_FN, RESULT_MAP_UNIT_FN]);
|
||||
|
@ -199,7 +199,7 @@ fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr<'_>) -> String
|
|||
#[must_use]
|
||||
fn suggestion_msg(function_type: &str, map_type: &str) -> String {
|
||||
format!(
|
||||
"called `map(f)` on an {0} value where `f` is a unit {1}",
|
||||
"called `map(f)` on an `{0}` value where `f` is a unit {1}",
|
||||
map_type, function_type
|
||||
)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub SINGLE_MATCH,
|
||||
style,
|
||||
"a match statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`"
|
||||
"a `match` statement with a single nontrivial arm (i.e., where the other arm is `_ => {}`) instead of `if let`"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -76,7 +76,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub SINGLE_MATCH_ELSE,
|
||||
pedantic,
|
||||
"a match statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
|
||||
"a `match` statement with two arms where the second arm's pattern is a placeholder instead of a specific match pattern"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -99,7 +99,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MATCH_REF_PATS,
|
||||
style,
|
||||
"a match or `if let` with all arms prefixed with `&` instead of deref-ing the match expression"
|
||||
"a `match` or `if let` with all arms prefixed with `&` instead of deref-ing the match expression"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -133,7 +133,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MATCH_BOOL,
|
||||
style,
|
||||
"a match on a boolean expression instead of an `if..else` block"
|
||||
"a `match` on a boolean expression instead of an `if..else` block"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -155,7 +155,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MATCH_OVERLAPPING_ARM,
|
||||
style,
|
||||
"a match with overlapping arms"
|
||||
"a `match` with overlapping arms"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -177,7 +177,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MATCH_WILD_ERR_ARM,
|
||||
style,
|
||||
"a match with `Err(_)` arm and take drastic actions"
|
||||
"a `match` with `Err(_)` arm and take drastic actions"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -198,7 +198,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MATCH_AS_REF,
|
||||
complexity,
|
||||
"a match on an Option value instead of using `as_ref()` or `as_mut`"
|
||||
"a `match` on an Option value instead of using `as_ref()` or `as_mut`"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -407,7 +407,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], e
|
|||
if let Some(sugg) = sugg {
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
"consider using an if/else expression",
|
||||
"consider using an `if`/`else` expression",
|
||||
sugg,
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
|
@ -461,10 +461,10 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>])
|
|||
span_note_and_lint(cx,
|
||||
MATCH_WILD_ERR_ARM,
|
||||
arm.pat.span,
|
||||
"Err(_) will match all errors, maybe not a good idea",
|
||||
"`Err(_)` will match all errors, maybe not a good idea",
|
||||
arm.pat.span,
|
||||
"to remove this warning, match each error separately \
|
||||
or use unreachable macro");
|
||||
or use `unreachable!` macro");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -650,7 +650,7 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>],
|
|||
cx,
|
||||
MATCH_AS_REF,
|
||||
expr.span,
|
||||
&format!("use {}() instead", suggestion),
|
||||
&format!("use `{}()` instead", suggestion),
|
||||
"try this",
|
||||
format!(
|
||||
"{}.{}(){}",
|
||||
|
|
|
@ -25,7 +25,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MEM_DISCRIMINANT_NON_ENUM,
|
||||
correctness,
|
||||
"calling mem::descriminant on non-enum type"
|
||||
"calling `mem::descriminant` on non-enum type"
|
||||
}
|
||||
|
||||
declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]);
|
||||
|
|
|
@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget {
|
|||
let forgot_ty = cx.tables.expr_ty(&args[0]);
|
||||
|
||||
if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) {
|
||||
span_lint(cx, MEM_FORGET, e.span, "usage of mem::forget on Drop type");
|
||||
span_lint(cx, MEM_FORGET, e.span, "usage of `mem::forget` on `Drop` type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1828,7 +1828,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &h
|
|||
cx,
|
||||
CLONE_ON_REF_PTR,
|
||||
expr.span,
|
||||
"using '.clone()' on a ref-counted pointer",
|
||||
"using `.clone()` on a ref-counted pointer",
|
||||
"try this",
|
||||
format!(
|
||||
"{}::<{}>::clone(&{})",
|
||||
|
@ -2220,8 +2220,8 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
|
|||
lint,
|
||||
expr.span,
|
||||
&format!(
|
||||
"used unwrap() on {} value. If you don't want to handle the {} case gracefully, consider \
|
||||
using expect() to provide a better panic \
|
||||
"used `unwrap()` on `{}` value. If you don't want to handle the `{}` case gracefully, consider \
|
||||
using `expect()` to provide a better panic \
|
||||
message",
|
||||
kind, none_value
|
||||
),
|
||||
|
@ -2247,7 +2247,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
|
|||
lint,
|
||||
expr.span,
|
||||
&format!(
|
||||
"used expect() on {} value. If this value is an {} it will panic",
|
||||
"used `expect()` on `{}` value. If this value is an `{}` it will panic",
|
||||
kind, none_value
|
||||
),
|
||||
);
|
||||
|
@ -2268,7 +2268,7 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, ok_args: &[hir
|
|||
cx,
|
||||
OK_EXPECT,
|
||||
expr.span,
|
||||
"called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`",
|
||||
"called `ok().expect()` on a `Result` value. You can call `expect()` directly on the `Result`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2286,7 +2286,7 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<
|
|||
span_lint_and_then(cx, MAP_FLATTEN, expr.span, msg, |db| {
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
"try using flat_map instead",
|
||||
"try using `flat_map` instead",
|
||||
hint,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
@ -2320,10 +2320,10 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
|
|||
|
||||
// lint message
|
||||
let msg = if is_option {
|
||||
"called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling \
|
||||
"called `map(f).unwrap_or_else(g)` on an `Option` value. This can be done more directly by calling \
|
||||
`map_or_else(g, f)` instead"
|
||||
} else {
|
||||
"called `map(f).unwrap_or_else(g)` on a Result value. This can be done more directly by calling \
|
||||
"called `map(f).unwrap_or_else(g)` on a `Result` value. This can be done more directly by calling \
|
||||
`.map_or_else(g, f)` instead"
|
||||
};
|
||||
// get snippets for args to map() and unwrap_or_else()
|
||||
|
@ -2380,7 +2380,7 @@ fn lint_map_or_none<'a, 'tcx>(
|
|||
|
||||
if map_or_arg_is_none {
|
||||
// lint message
|
||||
let msg = "called `map_or(None, f)` on an Option value. This can be done more directly by calling \
|
||||
let msg = "called `map_or(None, f)` on an `Option` value. This can be done more directly by calling \
|
||||
`and_then(f)` instead";
|
||||
let map_or_self_snippet = snippet(cx, map_or_args[0].span, "..");
|
||||
let map_or_func_snippet = snippet(cx, map_or_args[2].span, "..");
|
||||
|
@ -2388,7 +2388,7 @@ fn lint_map_or_none<'a, 'tcx>(
|
|||
span_lint_and_then(cx, OPTION_MAP_OR_NONE, expr.span, msg, |db| {
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
"try using and_then instead",
|
||||
"try using `and_then` instead",
|
||||
hint,
|
||||
Applicability::MachineApplicable, // snippet
|
||||
);
|
||||
|
@ -2860,7 +2860,7 @@ fn lint_single_char_pattern<'a, 'tcx>(
|
|||
SINGLE_CHAR_PATTERN,
|
||||
arg.span,
|
||||
"single-character string constant used as pattern",
|
||||
"try using a char instead",
|
||||
"try using a `char` instead",
|
||||
hint,
|
||||
applicability,
|
||||
);
|
||||
|
@ -2928,7 +2928,7 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, self_ref_ty: T
|
|||
INTO_ITER_ON_REF,
|
||||
method_span,
|
||||
&format!(
|
||||
"this .into_iter() call is equivalent to .{}() and will not move the {}",
|
||||
"this `.into_iter()` call is equivalent to `.{}()` and will not move the `{}`",
|
||||
method_name, kind,
|
||||
),
|
||||
"call directly",
|
||||
|
|
|
@ -60,7 +60,7 @@ pub(super) fn lint<'a, 'tcx>(
|
|||
"map_or(a, f)"
|
||||
};
|
||||
let msg = &format!(
|
||||
"called `map(f).unwrap_or({})` on an Option value. \
|
||||
"called `map(f).unwrap_or({})` on an `Option` value. \
|
||||
This can be done more directly by calling `{}` instead",
|
||||
arg, suggest
|
||||
);
|
||||
|
|
|
@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass {
|
|||
cx,
|
||||
MIN_MAX,
|
||||
expr.span,
|
||||
"this min/max combination leads to constant result",
|
||||
"this `min`/`max` combination leads to constant result",
|
||||
);
|
||||
},
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub CMP_NAN,
|
||||
correctness,
|
||||
"comparisons to NAN, which will always return false, probably not intended"
|
||||
"comparisons to `NAN`, which will always return false, probably not intended"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -194,7 +194,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub ZERO_PTR,
|
||||
style,
|
||||
"using 0 as *{const, mut} T"
|
||||
"using `0 as *{const, mut} T`"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -370,9 +370,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
}
|
||||
}
|
||||
let (lint, msg) = if is_named_constant(cx, left) || is_named_constant(cx, right) {
|
||||
(FLOAT_CMP_CONST, "strict comparison of f32 or f64 constant")
|
||||
(FLOAT_CMP_CONST, "strict comparison of `f32` or `f64` constant")
|
||||
} else {
|
||||
(FLOAT_CMP, "strict comparison of f32 or f64")
|
||||
(FLOAT_CMP, "strict comparison of `f32` or `f64`")
|
||||
};
|
||||
span_lint_and_then(cx, lint, expr.span, msg, |db| {
|
||||
let lhs = Sugg::hir(cx, left, "..");
|
||||
|
@ -388,7 +388,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
),
|
||||
Applicability::HasPlaceholders, // snippet
|
||||
);
|
||||
db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available.");
|
||||
db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
|
||||
});
|
||||
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
|
||||
span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");
|
||||
|
@ -456,7 +456,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) {
|
|||
cx,
|
||||
CMP_NAN,
|
||||
cmp_expr.span,
|
||||
"doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead",
|
||||
"doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
|
|||
cx.tcx.sess.span_err(span, &err);
|
||||
}
|
||||
} else {
|
||||
span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a const_fn");
|
||||
span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const_fn`");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MISSING_INLINE_IN_PUBLIC_ITEMS,
|
||||
restriction,
|
||||
"detects missing #[inline] attribute for public callables (functions, trait methods, methods...)"
|
||||
"detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)"
|
||||
}
|
||||
|
||||
fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
|
||||
|
|
|
@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MulAddCheck {
|
|||
cx,
|
||||
MANUAL_MUL_ADD,
|
||||
expr.span,
|
||||
"consider using mul_add() for better numerical precision",
|
||||
"consider using `mul_add()` for better numerical precision",
|
||||
"try",
|
||||
format!(
|
||||
"{}.mul_add({}, {})",
|
||||
|
@ -94,7 +94,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MulAddCheck {
|
|||
cx,
|
||||
MANUAL_MUL_ADD,
|
||||
expr.span,
|
||||
"consider using mul_add() for better numerical precision",
|
||||
"consider using `mul_add()` for better numerical precision",
|
||||
"try",
|
||||
format!(
|
||||
"{}.mul_add({}, {})",
|
||||
|
|
|
@ -47,7 +47,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub MUTABLE_KEY_TYPE,
|
||||
correctness,
|
||||
"Check for mutable Map/Set key type"
|
||||
"Check for mutable `Map`/`Set` key type"
|
||||
}
|
||||
|
||||
declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]);
|
||||
|
|
|
@ -63,8 +63,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex {
|
|||
let mutex_param = subst.type_at(0);
|
||||
if let Some(atomic_name) = get_atomic_name(mutex_param) {
|
||||
let msg = format!(
|
||||
"Consider using an {} instead of a Mutex here. If you just want the locking \
|
||||
behaviour and not the internal type, consider using Mutex<()>.",
|
||||
"Consider using an `{}` instead of a `Mutex` here. If you just want the locking \
|
||||
behavior and not the internal type, consider using `Mutex<()>`.",
|
||||
atomic_name
|
||||
);
|
||||
match mutex_param.kind {
|
||||
|
|
|
@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
|||
_ => (),
|
||||
}
|
||||
} else {
|
||||
panic!("IfExpr 'then' node is not an ExprKind::Block");
|
||||
panic!("IfExpr `then` node is not an `ExprKind::Block`");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -274,15 +274,15 @@ struct LintData<'a> {
|
|||
block_stmts: &'a [ast::Stmt],
|
||||
}
|
||||
|
||||
const MSG_REDUNDANT_ELSE_BLOCK: &str = "This else block is redundant.\n";
|
||||
const MSG_REDUNDANT_ELSE_BLOCK: &str = "This `else` block is redundant.\n";
|
||||
|
||||
const MSG_ELSE_BLOCK_NOT_NEEDED: &str = "There is no need for an explicit `else` block for this `if` \
|
||||
expression\n";
|
||||
|
||||
const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "Consider dropping the else clause and merging the code that \
|
||||
follows (in the loop) with the if block, like so:\n";
|
||||
const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "Consider dropping the `else` clause and merging the code that \
|
||||
follows (in the loop) with the `if` block, like so:\n";
|
||||
|
||||
const DROP_ELSE_BLOCK_MSG: &str = "Consider dropping the else clause, and moving out the code in the else \
|
||||
const DROP_ELSE_BLOCK_MSG: &str = "Consider dropping the `else` clause, and moving out the code in the `else` \
|
||||
block, like so:\n";
|
||||
|
||||
fn emit_warning<'a>(ctx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str, typ: LintType) {
|
||||
|
|
|
@ -206,7 +206,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
if let ty::Adt(def, ..) = ty.kind {
|
||||
if let Some(span) = cx.tcx.hir().span_if_local(def.did) {
|
||||
if cx.param_env.can_type_implement_copy(cx.tcx, ty).is_ok() {
|
||||
db.span_help(span, "consider marking this type as Copy");
|
||||
db.span_help(span, "consider marking this type as `Copy`");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub NEG_MULTIPLY,
|
||||
style,
|
||||
"multiplying integers with -1"
|
||||
"multiplying integers with `-1`"
|
||||
}
|
||||
|
||||
declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
|
||||
|
@ -48,7 +48,7 @@ fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_
|
|||
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit));
|
||||
if cx.tables.expr_ty(exp).is_integral();
|
||||
then {
|
||||
span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with -1");
|
||||
span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with `-1`");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub DECLARE_INTERIOR_MUTABLE_CONST,
|
||||
correctness,
|
||||
"declaring const with interior mutability"
|
||||
"declaring `const` with interior mutability"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -81,7 +81,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub BORROW_INTERIOR_MUTABLE_CONST,
|
||||
correctness,
|
||||
"referencing const with interior mutability"
|
||||
"referencing `const` with interior mutability"
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -98,12 +98,12 @@ impl Source {
|
|||
match self {
|
||||
Self::Item { item } | Self::Assoc { item, .. } => (
|
||||
DECLARE_INTERIOR_MUTABLE_CONST,
|
||||
"a const item should never be interior mutable",
|
||||
"a `const` item should never be interior mutable",
|
||||
*item,
|
||||
),
|
||||
Self::Expr { expr } => (
|
||||
BORROW_INTERIOR_MUTABLE_CONST,
|
||||
"a const item with interior mutability should not be borrowed",
|
||||
"a `const` item with interior mutability should not be borrowed",
|
||||
*expr,
|
||||
),
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
|
|||
cx,
|
||||
NONSENSICAL_OPEN_OPTIONS,
|
||||
span,
|
||||
"the method \"create\" is called more than once",
|
||||
"the method `create` is called more than once",
|
||||
);
|
||||
} else {
|
||||
create = true
|
||||
|
@ -136,7 +136,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
|
|||
cx,
|
||||
NONSENSICAL_OPEN_OPTIONS,
|
||||
span,
|
||||
"the method \"append\" is called more than once",
|
||||
"the method `append` is called more than once",
|
||||
);
|
||||
} else {
|
||||
append = true
|
||||
|
@ -149,7 +149,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
|
|||
cx,
|
||||
NONSENSICAL_OPEN_OPTIONS,
|
||||
span,
|
||||
"the method \"truncate\" is called more than once",
|
||||
"the method `truncate` is called more than once",
|
||||
);
|
||||
} else {
|
||||
truncate = true
|
||||
|
@ -162,7 +162,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
|
|||
cx,
|
||||
NONSENSICAL_OPEN_OPTIONS,
|
||||
span,
|
||||
"the method \"read\" is called more than once",
|
||||
"the method `read` is called more than once",
|
||||
);
|
||||
} else {
|
||||
read = true
|
||||
|
@ -175,7 +175,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
|
|||
cx,
|
||||
NONSENSICAL_OPEN_OPTIONS,
|
||||
span,
|
||||
"the method \"write\" is called more than once",
|
||||
"the method `write` is called more than once",
|
||||
);
|
||||
} else {
|
||||
write = true
|
||||
|
@ -190,7 +190,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
|
|||
cx,
|
||||
NONSENSICAL_OPEN_OPTIONS,
|
||||
span,
|
||||
"file opened with \"truncate\" and \"read\"",
|
||||
"file opened with `truncate` and `read`",
|
||||
);
|
||||
}
|
||||
if append && truncate && append_arg && truncate_arg {
|
||||
|
@ -198,7 +198,7 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
|
|||
cx,
|
||||
NONSENSICAL_OPEN_OPTIONS,
|
||||
span,
|
||||
"file opened with \"append\" and \"truncate\"",
|
||||
"file opened with `append` and `truncate`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
|
|||
cx,
|
||||
CMP_NULL,
|
||||
expr.span,
|
||||
"Comparing with null is better expressed by the .is_null() method",
|
||||
"Comparing with null is better expressed by the `.is_null()` method",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
|
|||
span_lint(cx,
|
||||
RANGE_ZIP_WITH_LEN,
|
||||
expr.span,
|
||||
&format!("It is more idiomatic to use {}.iter().enumerate()",
|
||||
&format!("It is more idiomatic to use `{}.iter().enumerate()`",
|
||||
snippet(cx, iter_args[0].span, "_")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ impl Return {
|
|||
return;
|
||||
}
|
||||
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| {
|
||||
if let Some(snippet) = snippet_opt(cx, inner_span) {
|
||||
db.span_suggestion(ret_span, "remove `return`", snippet, Applicability::MachineApplicable);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ impl Return {
|
|||
},
|
||||
None => match replacement {
|
||||
RetReplacement::Empty => {
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| {
|
||||
db.span_suggestion(
|
||||
ret_span,
|
||||
"remove `return`",
|
||||
|
@ -172,7 +172,7 @@ impl Return {
|
|||
});
|
||||
},
|
||||
RetReplacement::Block => {
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |db| {
|
||||
db.span_suggestion(
|
||||
ret_span,
|
||||
"replace `return` with an empty block",
|
||||
|
@ -211,9 +211,9 @@ impl Return {
|
|||
cx,
|
||||
LET_AND_RETURN,
|
||||
retexpr.span,
|
||||
"returning the result of a let binding from a block",
|
||||
"returning the result of a `let` binding from a block",
|
||||
|err| {
|
||||
err.span_label(local.span, "unnecessary let binding");
|
||||
err.span_label(local.span, "unnecessary `let` binding");
|
||||
|
||||
if let Some(snippet) = snippet_opt(cx, initexpr.span) {
|
||||
err.multipart_suggestion(
|
||||
|
|
|
@ -36,7 +36,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
///
|
||||
/// Will be converted to:
|
||||
/// ```rust
|
||||
/// ```rust
|
||||
/// ///
|
||||
/// /// Struct to hold two strings:
|
||||
/// /// - first one
|
||||
|
|
|
@ -141,7 +141,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub LINKEDLIST,
|
||||
pedantic,
|
||||
"usage of LinkedList, usually a vector is faster, or a more specialized data structure like a VecDeque"
|
||||
"usage of LinkedList, usually a vector is faster, or a more specialized data structure like a `VecDeque`"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -316,7 +316,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty<'_>, is_local: bool) {
|
|||
LINKEDLIST,
|
||||
hir_ty.span,
|
||||
"I see you're using a LinkedList! Perhaps you meant some other data structure?",
|
||||
"a VecDeque might work",
|
||||
"a `VecDeque` might work",
|
||||
);
|
||||
return; // don't recurse into the type
|
||||
}
|
||||
|
@ -464,7 +464,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub LET_UNIT_VALUE,
|
||||
style,
|
||||
"creating a let binding to a value of unit type, which usually can't be used afterwards"
|
||||
"creating a `let` binding to a value of unit type, which usually can't be used afterwards"
|
||||
}
|
||||
|
||||
declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]);
|
||||
|
@ -998,7 +998,7 @@ fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>,
|
|||
CAST_LOSSLESS,
|
||||
expr.span,
|
||||
&format!(
|
||||
"casting {} to {} may become silently lossy if you later change the type",
|
||||
"casting `{}` to `{}` may become silently lossy if you later change the type",
|
||||
cast_from, cast_to
|
||||
),
|
||||
"try",
|
||||
|
@ -1053,7 +1053,10 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>,
|
|||
cx,
|
||||
CAST_SIGN_LOSS,
|
||||
expr.span,
|
||||
&format!("casting {} to {} may lose the sign of the value", cast_from, cast_to),
|
||||
&format!(
|
||||
"casting `{}` to `{}` may lose the sign of the value",
|
||||
cast_from, cast_to
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1098,7 +1101,7 @@ fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast
|
|||
CAST_POSSIBLE_TRUNCATION,
|
||||
expr.span,
|
||||
&format!(
|
||||
"casting {} to {} may truncate the value{}",
|
||||
"casting `{}` to `{}` may truncate the value{}",
|
||||
cast_from,
|
||||
cast_to,
|
||||
match suffix_truncation {
|
||||
|
@ -1115,7 +1118,7 @@ fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast
|
|||
CAST_POSSIBLE_WRAP,
|
||||
expr.span,
|
||||
&format!(
|
||||
"casting {} to {} may wrap around the value{}",
|
||||
"casting `{}` to `{}` may wrap around the value{}",
|
||||
cast_from,
|
||||
cast_to,
|
||||
match suffix_wrap {
|
||||
|
@ -1194,7 +1197,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
|
|||
cx,
|
||||
UNNECESSARY_CAST,
|
||||
expr.span,
|
||||
&format!("casting integer literal to {} is unnecessary", cast_to),
|
||||
&format!("casting integer literal to `{}` is unnecessary", cast_to),
|
||||
"try",
|
||||
format!("{}_{}", n, cast_to),
|
||||
Applicability::MachineApplicable,
|
||||
|
@ -1256,14 +1259,17 @@ fn lint_numeric_casts<'tcx>(
|
|||
cx,
|
||||
CAST_POSSIBLE_TRUNCATION,
|
||||
expr.span,
|
||||
&format!("casting {} to {} may truncate the value", cast_from, cast_to),
|
||||
&format!("casting `{}` to `{}` may truncate the value", cast_from, cast_to),
|
||||
);
|
||||
if !cast_to.is_signed() {
|
||||
span_lint(
|
||||
cx,
|
||||
CAST_SIGN_LOSS,
|
||||
expr.span,
|
||||
&format!("casting {} to {} may lose the sign of the value", cast_from, cast_to),
|
||||
&format!(
|
||||
"casting `{}` to `{}` may lose the sign of the value",
|
||||
cast_from, cast_to
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -1278,7 +1284,7 @@ fn lint_numeric_casts<'tcx>(
|
|||
cx,
|
||||
CAST_POSSIBLE_TRUNCATION,
|
||||
expr.span,
|
||||
"casting f64 to f32 may truncate the value",
|
||||
"casting `f64` to `f32` may truncate the value",
|
||||
);
|
||||
}
|
||||
if let (&ty::Float(FloatTy::F32), &ty::Float(FloatTy::F64)) = (&cast_from.kind, &cast_to.kind) {
|
||||
|
@ -1550,7 +1556,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub CHAR_LIT_AS_U8,
|
||||
complexity,
|
||||
"casting a character literal to u8 truncates"
|
||||
"casting a character literal to `u8` truncates"
|
||||
}
|
||||
|
||||
declare_lint_pass!(CharLitAsU8 => [CHAR_LIT_AS_U8]);
|
||||
|
@ -1742,7 +1748,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
|
|||
AlwaysFalse => "this comparison is always false".to_owned(),
|
||||
AlwaysTrue => "this comparison is always true".to_owned(),
|
||||
InequalityImpossible => format!(
|
||||
"the case where the two sides are not equal never occurs, consider using {} == {} \
|
||||
"the case where the two sides are not equal never occurs, consider using `{} == {}` \
|
||||
instead",
|
||||
snippet(cx, lhs.span, "lhs"),
|
||||
snippet(cx, rhs.span, "rhs")
|
||||
|
@ -1750,7 +1756,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
|
|||
};
|
||||
|
||||
let help = format!(
|
||||
"because {} is the {} value for this type, {}",
|
||||
"because `{}` is the {} value for this type, {}",
|
||||
snippet(cx, culprit.expr.span, "x"),
|
||||
match culprit.which {
|
||||
Minimum => "minimum",
|
||||
|
@ -1813,7 +1819,7 @@ impl FullInt {
|
|||
impl PartialEq for FullInt {
|
||||
#[must_use]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.partial_cmp(other).expect("partial_cmp only returns Some(_)") == Ordering::Equal
|
||||
self.partial_cmp(other).expect("`partial_cmp` only returns `Some(_)`") == Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1832,7 +1838,7 @@ impl Ord for FullInt {
|
|||
#[must_use]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other)
|
||||
.expect("partial_cmp for FullInt can never return None")
|
||||
.expect("`partial_cmp` for FullInt can never return `None`")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2404,7 +2410,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut {
|
|||
cx,
|
||||
CAST_REF_TO_MUT,
|
||||
expr.span,
|
||||
"casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell",
|
||||
"casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>,
|
|||
UNSAFE_REMOVED_FROM_NAME,
|
||||
span,
|
||||
&format!(
|
||||
"removed \"unsafe\" from the name of `{}` in use as `{}`",
|
||||
"removed `unsafe` from the name of `{}` in use as `{}`",
|
||||
old_str, new_str
|
||||
),
|
||||
);
|
||||
|
|
|
@ -35,7 +35,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub UNNECESSARY_UNWRAP,
|
||||
complexity,
|
||||
"checks for calls of unwrap[_err]() that cannot fail"
|
||||
"checks for calls of `unwrap[_err]()` that cannot fail"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -58,7 +58,7 @@ declare_clippy_lint! {
|
|||
/// This code will always panic. The if condition should probably be inverted.
|
||||
pub PANICKING_UNWRAP,
|
||||
correctness,
|
||||
"checks for calls of unwrap[_err]() that will always fail"
|
||||
"checks for calls of `unwrap[_err]()` that will always fail"
|
||||
}
|
||||
|
||||
/// Visitor that keeps track of which variables are unwrappable.
|
||||
|
|
|
@ -20,7 +20,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
pub ZERO_DIVIDED_BY_ZERO,
|
||||
complexity,
|
||||
"usage of `0.0 / 0.0` to obtain NaN instead of std::f32::NaN or std::f64::NaN"
|
||||
"usage of `0.0 / 0.0` to obtain NaN instead of `std::f32::NAN` or `std::f64::NAN`"
|
||||
}
|
||||
|
||||
declare_lint_pass!(ZeroDiv => [ZERO_DIVIDED_BY_ZERO]);
|
||||
|
@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ZeroDiv {
|
|||
cx,
|
||||
ZERO_DIVIDED_BY_ZERO,
|
||||
expr.span,
|
||||
"constant division of 0.0 with 0.0 will always result in NaN",
|
||||
"constant division of `0.0` with `0.0` will always result in NaN",
|
||||
&format!(
|
||||
"Consider using `std::{}::NAN` if you would like a constant representing NaN",
|
||||
float_type,
|
||||
|
|
Loading…
Reference in a new issue