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(),
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?",
);
}
}
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,
}
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<'_>) {
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(
/// ```
pub IFS_SAME_COND,
correctness,
- "consecutive `ifs` with the same condition"
+ "consecutive `if`s with the same condition"
}
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! {
/// ```
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! {
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",
);
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",
);
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
),
);
/// ```
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]);
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
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]);
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;
/// ```
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]);
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",
);
}
// 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);
}
}
}
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 => {
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`",
);
},
_ => (),
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,
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
/// ```
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]);
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!(
/// ```
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]);
/// ```
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]);
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, "[...]")
),
);
/// ```
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]);
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) {
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"
)
}
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,
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,
)
/// ```
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! {
/// ```
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]);
#[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
)
}
/// ```
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! {
/// ```
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! {
/// ```
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! {
/// ```
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! {
/// ```
pub MATCH_OVERLAPPING_ARM,
style,
- "a match with overlapping arms"
+ "a `match` with overlapping arms"
}
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! {
/// ```
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! {
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,
);
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");
}
}
}
cx,
MATCH_AS_REF,
expr.span,
- &format!("use {}() instead", suggestion),
+ &format!("use `{}()` instead", suggestion),
"try this",
format!(
"{}.{}(){}",
/// ```
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]);
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");
}
}
}
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(&{})",
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
),
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
),
);
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`",
);
}
}
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,
);
// 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()
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, "..");
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
);
SINGLE_CHAR_PATTERN,
arg.span,
"single-character string constant used as pattern",
- "try using a char instead",
+ "try using a `char` instead",
hint,
applicability,
);
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",
"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
);
cx,
MIN_MAX,
expr.span,
- "this min/max combination leads to constant result",
+ "this `min`/`max` combination leads to constant result",
);
},
}
/// ```
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! {
/// ```
pub ZERO_PTR,
style,
- "using 0 as *{const, mut} T"
+ "using `0 as *{const, mut} T`"
}
declare_clippy_lint! {
}
}
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, "..");
),
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");
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",
);
}
}
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`");
}
}
}
/// ```
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) {
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({}, {})",
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({}, {})",
/// ```
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 ]);
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 {
_ => (),
}
} else {
- panic!("IfExpr 'then' node is not an ExprKind::Block");
+ panic!("IfExpr `then` node is not an `ExprKind::Block`");
}
}
}
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) {
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`");
}
}
}
/// ```
pub NEG_MULTIPLY,
style,
- "multiplying integers with -1"
+ "multiplying integers with `-1`"
}
declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
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`");
}
}
}
/// ```
pub DECLARE_INTERIOR_MUTABLE_CONST,
correctness,
- "declaring const with interior mutability"
+ "declaring `const` with interior mutability"
}
declare_clippy_lint! {
/// ```
pub BORROW_INTERIOR_MUTABLE_CONST,
correctness,
- "referencing const with interior mutability"
+ "referencing `const` with interior mutability"
}
#[allow(dead_code)]
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,
),
}
cx,
NONSENSICAL_OPEN_OPTIONS,
span,
- "the method \"create\" is called more than once",
+ "the method `create` is called more than once",
);
} else {
create = true
cx,
NONSENSICAL_OPEN_OPTIONS,
span,
- "the method \"append\" is called more than once",
+ "the method `append` is called more than once",
);
} else {
append = true
cx,
NONSENSICAL_OPEN_OPTIONS,
span,
- "the method \"truncate\" is called more than once",
+ "the method `truncate` is called more than once",
);
} else {
truncate = true
cx,
NONSENSICAL_OPEN_OPTIONS,
span,
- "the method \"read\" is called more than once",
+ "the method `read` is called more than once",
);
} else {
read = true
cx,
NONSENSICAL_OPEN_OPTIONS,
span,
- "the method \"write\" is called more than once",
+ "the method `write` is called more than once",
);
} else {
write = true
cx,
NONSENSICAL_OPEN_OPTIONS,
span,
- "file opened with \"truncate\" and \"read\"",
+ "file opened with `truncate` and `read`",
);
}
if append && truncate && append_arg && truncate_arg {
cx,
NONSENSICAL_OPEN_OPTIONS,
span,
- "file opened with \"append\" and \"truncate\"",
+ "file opened with `append` and `truncate`",
);
}
}
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",
);
}
}
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, "_")));
}
}
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);
}
},
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`",
});
},
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",
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(
/// ```
///
/// Will be converted to:
- /// ```rust
+ /// ```rust
/// ///
/// /// Struct to hold two strings:
/// /// - first one
/// ```
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! {
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
}
/// ```
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]);
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",
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
+ ),
);
}
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 {
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 {
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,
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
+ ),
);
}
},
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) {
/// ```
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]);
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")
};
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",
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
}
}
#[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`")
}
}
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`",
);
}
}
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
),
);
/// ```
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! {
/// 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.
/// ```
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]);
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,