mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-21 00:18:46 +00:00
Migrating restriction lints to span_lint_and_then
(a -> d)
This commit is contained in:
parent
1ea827fa03
commit
a9d72c7107
16 changed files with 266 additions and 270 deletions
|
@ -1,4 +1,4 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_help;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::is_from_proc_macro;
|
use clippy_utils::is_from_proc_macro;
|
||||||
use rustc_hir::{Expr, ExprKind};
|
use rustc_hir::{Expr, ExprKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
|
@ -52,13 +52,15 @@ impl<'tcx> LateLintPass<'tcx> for AsConversions {
|
||||||
&& !in_external_macro(cx.sess(), expr.span)
|
&& !in_external_macro(cx.sess(), expr.span)
|
||||||
&& !is_from_proc_macro(cx, expr)
|
&& !is_from_proc_macro(cx, expr)
|
||||||
{
|
{
|
||||||
span_lint_and_help(
|
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
|
||||||
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
AS_CONVERSIONS,
|
AS_CONVERSIONS,
|
||||||
expr.span,
|
expr.span,
|
||||||
"using a potentially dangerous silent `as` conversion",
|
"using a potentially dangerous silent `as` conversion",
|
||||||
None,
|
|diag| {
|
||||||
"consider using a safe wrapper for this conversion",
|
diag.help("consider using a safe wrapper for this conversion");
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
|
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
|
||||||
use clippy_utils::source::snippet_with_context;
|
use clippy_utils::source::snippet_with_context;
|
||||||
use clippy_utils::ty::{has_debug_impl, is_copy, is_type_diagnostic_item};
|
use clippy_utils::ty::{has_debug_impl, is_copy, is_type_diagnostic_item};
|
||||||
|
@ -68,39 +68,29 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let semicolon = if is_expr_final_block_expr(cx.tcx, e) { ";" } else { "" };
|
let (message, replacement) = match method_segment.ident.as_str() {
|
||||||
let mut app = Applicability::MachineApplicable;
|
|
||||||
match method_segment.ident.as_str() {
|
|
||||||
"is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => {
|
"is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => {
|
||||||
span_lint_and_sugg(
|
("called `assert!` with `Result::is_ok`", "unwrap")
|
||||||
cx,
|
|
||||||
ASSERTIONS_ON_RESULT_STATES,
|
|
||||||
macro_call.span,
|
|
||||||
"called `assert!` with `Result::is_ok`",
|
|
||||||
"replace with",
|
|
||||||
format!(
|
|
||||||
"{}.unwrap(){semicolon}",
|
|
||||||
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
|
|
||||||
),
|
|
||||||
app,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
"is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => {
|
"is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => {
|
||||||
span_lint_and_sugg(
|
("called `assert!` with `Result::is_err`", "unwrap_err")
|
||||||
cx,
|
|
||||||
ASSERTIONS_ON_RESULT_STATES,
|
|
||||||
macro_call.span,
|
|
||||||
"called `assert!` with `Result::is_err`",
|
|
||||||
"replace with",
|
|
||||||
format!(
|
|
||||||
"{}.unwrap_err(){semicolon}",
|
|
||||||
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
|
|
||||||
),
|
|
||||||
app,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => return,
|
||||||
};
|
};
|
||||||
|
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
|
||||||
|
span_lint_and_then(cx, ASSERTIONS_ON_RESULT_STATES, macro_call.span, message, |diag| {
|
||||||
|
let semicolon = if is_expr_final_block_expr(cx.tcx, e) { ";" } else { "" };
|
||||||
|
let mut app = Applicability::MachineApplicable;
|
||||||
|
diag.span_suggestion(
|
||||||
|
macro_call.span,
|
||||||
|
"replace with",
|
||||||
|
format!(
|
||||||
|
"{}.{replacement}(){semicolon}",
|
||||||
|
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
|
||||||
|
),
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::ALLOW_ATTRIBUTES;
|
use super::ALLOW_ATTRIBUTES;
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::is_from_proc_macro;
|
use clippy_utils::is_from_proc_macro;
|
||||||
use rustc_ast::{AttrStyle, Attribute};
|
use rustc_ast::{AttrStyle, Attribute};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
|
@ -13,14 +13,14 @@ pub fn check<'cx>(cx: &LateContext<'cx>, attr: &'cx Attribute) {
|
||||||
&& let Some(ident) = attr.ident()
|
&& let Some(ident) = attr.ident()
|
||||||
&& !is_from_proc_macro(cx, attr)
|
&& !is_from_proc_macro(cx, attr)
|
||||||
{
|
{
|
||||||
span_lint_and_sugg(
|
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
|
||||||
cx,
|
span_lint_and_then(cx, ALLOW_ATTRIBUTES, ident.span, "#[allow] attribute found", |diag| {
|
||||||
ALLOW_ATTRIBUTES,
|
diag.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"#[allow] attribute found",
|
"replace it with",
|
||||||
"replace it with",
|
"expect",
|
||||||
"expect".into(),
|
Applicability::MachineApplicable,
|
||||||
Applicability::MachineApplicable,
|
);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{Attribute, ALLOW_ATTRIBUTES_WITHOUT_REASON};
|
use super::{Attribute, ALLOW_ATTRIBUTES_WITHOUT_REASON};
|
||||||
use clippy_utils::diagnostics::span_lint_and_help;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::is_from_proc_macro;
|
use clippy_utils::is_from_proc_macro;
|
||||||
use rustc_ast::{MetaItemKind, NestedMetaItem};
|
use rustc_ast::{MetaItemKind, NestedMetaItem};
|
||||||
use rustc_lint::{LateContext, LintContext};
|
use rustc_lint::{LateContext, LintContext};
|
||||||
|
@ -21,12 +21,14 @@ pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMet
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
span_lint_and_help(
|
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
|
||||||
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
ALLOW_ATTRIBUTES_WITHOUT_REASON,
|
ALLOW_ATTRIBUTES_WITHOUT_REASON,
|
||||||
attr.span,
|
attr.span,
|
||||||
format!("`{}` attribute without specifying a reason", name.as_str()),
|
format!("`{}` attribute without specifying a reason", name.as_str()),
|
||||||
None,
|
|diag| {
|
||||||
"try adding a reason at the end with `, reason = \"..\"`",
|
diag.help("try adding a reason at the end with `, reason = \"..\"`");
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::source::snippet;
|
use clippy_utils::source::snippet_with_applicability;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::{Applicability, SuggestionStyle};
|
||||||
use rustc_hir::{Expr, ExprKind};
|
use rustc_hir::{Expr, ExprKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
|
@ -39,14 +39,24 @@ impl LateLintPass<'_> for CreateDir {
|
||||||
&& let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id()
|
&& let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id()
|
||||||
&& cx.tcx.is_diagnostic_item(sym::fs_create_dir, def_id)
|
&& cx.tcx.is_diagnostic_item(sym::fs_create_dir, def_id)
|
||||||
{
|
{
|
||||||
span_lint_and_sugg(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
CREATE_DIR,
|
CREATE_DIR,
|
||||||
expr.span,
|
expr.span,
|
||||||
"calling `std::fs::create_dir` where there may be a better way",
|
"calling `std::fs::create_dir` where there may be a better way",
|
||||||
"consider calling `std::fs::create_dir_all` instead",
|
|diag| {
|
||||||
format!("create_dir_all({})", snippet(cx, arg.span, "..")),
|
let mut app = Applicability::MaybeIncorrect;
|
||||||
Applicability::MaybeIncorrect,
|
diag.span_suggestion_with_style(
|
||||||
|
expr.span,
|
||||||
|
"consider calling `std::fs::create_dir_all` instead",
|
||||||
|
format!(
|
||||||
|
"create_dir_all({})",
|
||||||
|
snippet_with_applicability(cx, arg.span, "..", &mut app)
|
||||||
|
),
|
||||||
|
app,
|
||||||
|
SuggestionStyle::ShowAlways,
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use clippy_config::Conf;
|
use clippy_config::Conf;
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::is_in_test;
|
use clippy_utils::is_in_test;
|
||||||
use clippy_utils::macros::{macro_backtrace, MacroCall};
|
use clippy_utils::macros::{macro_backtrace, MacroCall};
|
||||||
use clippy_utils::source::snippet_with_applicability;
|
use clippy_utils::source::snippet_with_applicability;
|
||||||
|
@ -65,61 +65,67 @@ impl LateLintPass<'_> for DbgMacro {
|
||||||
// allows `dbg!` in test code if allow-dbg-in-test is set to true in clippy.toml
|
// allows `dbg!` in test code if allow-dbg-in-test is set to true in clippy.toml
|
||||||
!(self.allow_dbg_in_tests && is_in_test(cx.tcx, expr.hir_id))
|
!(self.allow_dbg_in_tests && is_in_test(cx.tcx, expr.hir_id))
|
||||||
{
|
{
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
|
||||||
|
|
||||||
let (sugg_span, suggestion) = match expr.peel_drop_temps().kind {
|
|
||||||
// dbg!()
|
|
||||||
ExprKind::Block(..) => {
|
|
||||||
// If the `dbg!` macro is a "free" statement and not contained within other expressions,
|
|
||||||
// remove the whole statement.
|
|
||||||
if let Node::Stmt(_) = cx.tcx.parent_hir_node(expr.hir_id)
|
|
||||||
&& let Some(semi_span) = cx.sess().source_map().mac_call_stmt_semi_span(macro_call.span)
|
|
||||||
{
|
|
||||||
(macro_call.span.to(semi_span), String::new())
|
|
||||||
} else {
|
|
||||||
(macro_call.span, String::from("()"))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// dbg!(1)
|
|
||||||
ExprKind::Match(val, ..) => (
|
|
||||||
macro_call.span,
|
|
||||||
snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability).to_string(),
|
|
||||||
),
|
|
||||||
// dbg!(2, 3)
|
|
||||||
ExprKind::Tup(
|
|
||||||
[
|
|
||||||
Expr {
|
|
||||||
kind: ExprKind::Match(first, ..),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..,
|
|
||||||
Expr {
|
|
||||||
kind: ExprKind::Match(last, ..),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
],
|
|
||||||
) => {
|
|
||||||
let snippet = snippet_with_applicability(
|
|
||||||
cx,
|
|
||||||
first.span.source_callsite().to(last.span.source_callsite()),
|
|
||||||
"..",
|
|
||||||
&mut applicability,
|
|
||||||
);
|
|
||||||
(macro_call.span, format!("({snippet})"))
|
|
||||||
},
|
|
||||||
_ => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.prev_ctxt = cur_syntax_ctxt;
|
self.prev_ctxt = cur_syntax_ctxt;
|
||||||
|
|
||||||
span_lint_and_sugg(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
DBG_MACRO,
|
DBG_MACRO,
|
||||||
sugg_span,
|
macro_call.span,
|
||||||
"the `dbg!` macro is intended as a debugging tool",
|
"the `dbg!` macro is intended as a debugging tool",
|
||||||
"remove the invocation before committing it to a version control system",
|
|diag| {
|
||||||
suggestion,
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
applicability,
|
|
||||||
|
let (sugg_span, suggestion) = match expr.peel_drop_temps().kind {
|
||||||
|
// dbg!()
|
||||||
|
ExprKind::Block(..) => {
|
||||||
|
// If the `dbg!` macro is a "free" statement and not contained within other expressions,
|
||||||
|
// remove the whole statement.
|
||||||
|
if let Node::Stmt(_) = cx.tcx.parent_hir_node(expr.hir_id)
|
||||||
|
&& let Some(semi_span) = cx.sess().source_map().mac_call_stmt_semi_span(macro_call.span)
|
||||||
|
{
|
||||||
|
(macro_call.span.to(semi_span), String::new())
|
||||||
|
} else {
|
||||||
|
(macro_call.span, String::from("()"))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// dbg!(1)
|
||||||
|
ExprKind::Match(val, ..) => (
|
||||||
|
macro_call.span,
|
||||||
|
snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability)
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
|
// dbg!(2, 3)
|
||||||
|
ExprKind::Tup(
|
||||||
|
[
|
||||||
|
Expr {
|
||||||
|
kind: ExprKind::Match(first, ..),
|
||||||
|
..
|
||||||
|
},
|
||||||
|
..,
|
||||||
|
Expr {
|
||||||
|
kind: ExprKind::Match(last, ..),
|
||||||
|
..
|
||||||
|
},
|
||||||
|
],
|
||||||
|
) => {
|
||||||
|
let snippet = snippet_with_applicability(
|
||||||
|
cx,
|
||||||
|
first.span.source_callsite().to(last.span.source_callsite()),
|
||||||
|
"..",
|
||||||
|
&mut applicability,
|
||||||
|
);
|
||||||
|
(macro_call.span, format!("({snippet})"))
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
diag.span_suggestion(
|
||||||
|
sugg_span,
|
||||||
|
"remove the invocation before committing it to a version control system",
|
||||||
|
suggestion,
|
||||||
|
applicability,
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,20 +92,8 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
|
||||||
let (suffix, is_float) = match lit_ty.kind() {
|
let (suffix, is_float) = match lit_ty.kind() {
|
||||||
ty::Int(IntTy::I32) => ("i32", false),
|
ty::Int(IntTy::I32) => ("i32", false),
|
||||||
ty::Float(FloatTy::F64) => ("f64", true),
|
ty::Float(FloatTy::F64) => ("f64", true),
|
||||||
// Default numeric fallback never results in other types.
|
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let src = if let Some(src) = snippet_opt(self.cx, lit.span) {
|
|
||||||
src
|
|
||||||
} else {
|
|
||||||
match lit.node {
|
|
||||||
LitKind::Int(src, _) => format!("{src}"),
|
|
||||||
LitKind::Float(src, _) => format!("{src}"),
|
|
||||||
_ => return,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let sugg = numeric_literal::format(&src, Some(suffix), is_float);
|
|
||||||
span_lint_hir_and_then(
|
span_lint_hir_and_then(
|
||||||
self.cx,
|
self.cx,
|
||||||
DEFAULT_NUMERIC_FALLBACK,
|
DEFAULT_NUMERIC_FALLBACK,
|
||||||
|
@ -113,6 +101,17 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
|
||||||
lit.span,
|
lit.span,
|
||||||
"default numeric fallback might occur",
|
"default numeric fallback might occur",
|
||||||
|diag| {
|
|diag| {
|
||||||
|
let src = if let Some(src) = snippet_opt(self.cx, lit.span) {
|
||||||
|
src
|
||||||
|
} else {
|
||||||
|
match lit.node {
|
||||||
|
LitKind::Int(src, _) => format!("{src}"),
|
||||||
|
LitKind::Float(src, _) => format!("{src}"),
|
||||||
|
_ => unreachable!("Default numeric fallback never results in other types"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let sugg = numeric_literal::format(&src, Some(suffix), is_float);
|
||||||
diag.span_suggestion(lit.span, "consider adding suffix", sugg, Applicability::MaybeIncorrect);
|
diag.span_suggestion(lit.span, "consider adding suffix", sugg, Applicability::MaybeIncorrect);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_help;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use rustc_hir::{HirId, Item, ItemKind};
|
use rustc_hir::{HirId, Item, ItemKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
|
@ -56,16 +56,18 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
|
||||||
&& is_union_with_two_non_zst_fields(cx, item)
|
&& is_union_with_two_non_zst_fields(cx, item)
|
||||||
&& !has_c_repr_attr(cx, item.hir_id())
|
&& !has_c_repr_attr(cx, item.hir_id())
|
||||||
{
|
{
|
||||||
span_lint_and_help(
|
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
|
||||||
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
DEFAULT_UNION_REPRESENTATION,
|
DEFAULT_UNION_REPRESENTATION,
|
||||||
item.span,
|
item.span,
|
||||||
"this union has the default representation",
|
"this union has the default representation",
|
||||||
None,
|
|diag| {
|
||||||
format!(
|
diag.help(format!(
|
||||||
"consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout",
|
"consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout",
|
||||||
cx.tcx.def_path_str(item.owner_id)
|
cx.tcx.def_path_str(item.owner_id)
|
||||||
),
|
));
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::Symbol;
|
use rustc_span::Symbol;
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
|
@ -141,52 +140,6 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut help = None;
|
|
||||||
|
|
||||||
'build_help: {
|
|
||||||
// all lints disallowed, don't give help here
|
|
||||||
if [&[lint], other_lints.as_slice()]
|
|
||||||
.concat()
|
|
||||||
.iter()
|
|
||||||
.all(|lint| !lint.allowed(cx, expr))
|
|
||||||
{
|
|
||||||
break 'build_help;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ne_bytes and all other lints allowed
|
|
||||||
if lint.as_name(prefix) == ne && other_lints.iter().all(|lint| lint.allowed(cx, expr)) {
|
|
||||||
help = Some(Cow::Borrowed("specify the desired endianness explicitly"));
|
|
||||||
break 'build_help;
|
|
||||||
}
|
|
||||||
|
|
||||||
// le_bytes where ne_bytes allowed but be_bytes is not, or le_bytes where ne_bytes allowed but
|
|
||||||
// le_bytes is not
|
|
||||||
if (lint.as_name(prefix) == le || lint.as_name(prefix) == be) && LintKind::Host.allowed(cx, expr) {
|
|
||||||
help = Some(Cow::Borrowed("use the native endianness instead"));
|
|
||||||
break 'build_help;
|
|
||||||
}
|
|
||||||
|
|
||||||
let allowed_lints = other_lints.iter().filter(|lint| lint.allowed(cx, expr));
|
|
||||||
let len = allowed_lints.clone().count();
|
|
||||||
|
|
||||||
let mut help_str = "use ".to_owned();
|
|
||||||
|
|
||||||
for (i, lint) in allowed_lints.enumerate() {
|
|
||||||
let only_one = len == 1;
|
|
||||||
if !only_one {
|
|
||||||
help_str.push_str("either of ");
|
|
||||||
}
|
|
||||||
|
|
||||||
help_str.push_str(&format!("`{ty}::{}` ", lint.as_name(prefix)));
|
|
||||||
|
|
||||||
if i != len && !only_one {
|
|
||||||
help_str.push_str("or ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
help = Some(Cow::Owned(help_str + "instead"));
|
|
||||||
}
|
|
||||||
|
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
lint.as_lint(),
|
lint.as_lint(),
|
||||||
|
@ -198,9 +151,47 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix
|
||||||
if prefix == Prefix::To { " method" } else { "" },
|
if prefix == Prefix::To { " method" } else { "" },
|
||||||
),
|
),
|
||||||
move |diag| {
|
move |diag| {
|
||||||
if let Some(help) = help {
|
// all lints disallowed, don't give help here
|
||||||
diag.help(help);
|
if [&[lint], other_lints.as_slice()]
|
||||||
|
.concat()
|
||||||
|
.iter()
|
||||||
|
.all(|lint| !lint.allowed(cx, expr))
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ne_bytes and all other lints allowed
|
||||||
|
if lint.as_name(prefix) == ne && other_lints.iter().all(|lint| lint.allowed(cx, expr)) {
|
||||||
|
diag.help("specify the desired endianness explicitly");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// le_bytes where ne_bytes allowed but be_bytes is not, or le_bytes where ne_bytes allowed but
|
||||||
|
// le_bytes is not
|
||||||
|
if (lint.as_name(prefix) == le || lint.as_name(prefix) == be) && LintKind::Host.allowed(cx, expr) {
|
||||||
|
diag.help("use the native endianness instead");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let allowed_lints = other_lints.iter().filter(|lint| lint.allowed(cx, expr));
|
||||||
|
let len = allowed_lints.clone().count();
|
||||||
|
|
||||||
|
let mut help_str = "use ".to_owned();
|
||||||
|
|
||||||
|
for (i, lint) in allowed_lints.enumerate() {
|
||||||
|
let only_one = len == 1;
|
||||||
|
if !only_one {
|
||||||
|
help_str.push_str("either of ");
|
||||||
|
}
|
||||||
|
|
||||||
|
help_str.push_str(&format!("`{ty}::{}` ", lint.as_name(prefix)));
|
||||||
|
|
||||||
|
if i != len && !only_one {
|
||||||
|
help_str.push_str("or ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
help_str.push_str("instead");
|
||||||
|
diag.help(help_str);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
//! floating-point literal expressions.
|
//! floating-point literal expressions.
|
||||||
|
|
||||||
use clippy_config::Conf;
|
use clippy_config::Conf;
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::numeric_literal::{NumericLiteral, Radix};
|
use clippy_utils::numeric_literal::{NumericLiteral, Radix};
|
||||||
use clippy_utils::source::snippet_opt;
|
use clippy_utils::source::snippet_opt;
|
||||||
use rustc_ast::ast::{Expr, ExprKind, LitKind};
|
use rustc_ast::ast::{Expr, ExprKind, LitKind};
|
||||||
use rustc_ast::token;
|
use rustc_ast::token;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
|
use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
@ -159,63 +159,39 @@ enum WarningType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WarningType {
|
impl WarningType {
|
||||||
fn display(&self, suggested_format: String, cx: &EarlyContext<'_>, span: Span) {
|
fn lint_and_text(&self) -> (&'static Lint, &'static str, &'static str) {
|
||||||
match self {
|
match self {
|
||||||
Self::MistypedLiteralSuffix => span_lint_and_sugg(
|
Self::MistypedLiteralSuffix => (
|
||||||
cx,
|
|
||||||
MISTYPED_LITERAL_SUFFIXES,
|
MISTYPED_LITERAL_SUFFIXES,
|
||||||
span,
|
|
||||||
"mistyped literal suffix",
|
"mistyped literal suffix",
|
||||||
"did you mean to write",
|
"did you mean to write",
|
||||||
suggested_format,
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
),
|
),
|
||||||
Self::UnreadableLiteral => span_lint_and_sugg(
|
Self::UnreadableLiteral => (UNREADABLE_LITERAL, "long literal lacking separators", "consider"),
|
||||||
cx,
|
Self::LargeDigitGroups => (LARGE_DIGIT_GROUPS, "digit groups should be smaller", "consider"),
|
||||||
UNREADABLE_LITERAL,
|
Self::InconsistentDigitGrouping => (
|
||||||
span,
|
|
||||||
"long literal lacking separators",
|
|
||||||
"consider",
|
|
||||||
suggested_format,
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
),
|
|
||||||
Self::LargeDigitGroups => span_lint_and_sugg(
|
|
||||||
cx,
|
|
||||||
LARGE_DIGIT_GROUPS,
|
|
||||||
span,
|
|
||||||
"digit groups should be smaller",
|
|
||||||
"consider",
|
|
||||||
suggested_format,
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
),
|
|
||||||
Self::InconsistentDigitGrouping => span_lint_and_sugg(
|
|
||||||
cx,
|
|
||||||
INCONSISTENT_DIGIT_GROUPING,
|
INCONSISTENT_DIGIT_GROUPING,
|
||||||
span,
|
|
||||||
"digits grouped inconsistently by underscores",
|
"digits grouped inconsistently by underscores",
|
||||||
"consider",
|
"consider",
|
||||||
suggested_format,
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
),
|
),
|
||||||
Self::DecimalRepresentation => span_lint_and_sugg(
|
Self::DecimalRepresentation => (
|
||||||
cx,
|
|
||||||
DECIMAL_LITERAL_REPRESENTATION,
|
DECIMAL_LITERAL_REPRESENTATION,
|
||||||
span,
|
|
||||||
"integer literal has a better hexadecimal representation",
|
"integer literal has a better hexadecimal representation",
|
||||||
"consider",
|
"consider",
|
||||||
suggested_format,
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
),
|
),
|
||||||
Self::UnusualByteGroupings => span_lint_and_sugg(
|
Self::UnusualByteGroupings => (
|
||||||
cx,
|
|
||||||
UNUSUAL_BYTE_GROUPINGS,
|
UNUSUAL_BYTE_GROUPINGS,
|
||||||
span,
|
|
||||||
"digits of hex, binary or octal literal not in groups of equal size",
|
"digits of hex, binary or octal literal not in groups of equal size",
|
||||||
"consider",
|
"consider",
|
||||||
suggested_format,
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
),
|
),
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display(&self, num_lit: NumericLiteral<'_>, cx: &EarlyContext<'_>, span: Span) {
|
||||||
|
let (lint, message, try_msg) = self.lint_and_text();
|
||||||
|
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
|
||||||
|
span_lint_and_then(cx, lint, span, message, |diag| {
|
||||||
|
diag.span_suggestion(span, try_msg, num_lit.format(), Applicability::MaybeIncorrect);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +269,7 @@ impl LiteralDigitGrouping {
|
||||||
WarningType::DecimalRepresentation | WarningType::MistypedLiteralSuffix => true,
|
WarningType::DecimalRepresentation | WarningType::MistypedLiteralSuffix => true,
|
||||||
};
|
};
|
||||||
if should_warn {
|
if should_warn {
|
||||||
warning_type.display(num_lit.format(), cx, span);
|
warning_type.display(num_lit, cx, span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,11 +322,14 @@ impl LiteralDigitGrouping {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*part = main_part;
|
*part = main_part;
|
||||||
let mut sugg = num_lit.format();
|
let (lint, message, try_msg) = WarningType::MistypedLiteralSuffix.lint_and_text();
|
||||||
sugg.push('_');
|
span_lint_and_then(cx, lint, span, message, |diag| {
|
||||||
sugg.push(missing_char);
|
let mut sugg = num_lit.format();
|
||||||
sugg.push_str(last_group);
|
sugg.push('_');
|
||||||
WarningType::MistypedLiteralSuffix.display(sugg, cx, span);
|
sugg.push(missing_char);
|
||||||
|
sugg.push_str(last_group);
|
||||||
|
diag.span_suggestion(span, try_msg, sugg, Applicability::MaybeIncorrect);
|
||||||
|
});
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
@ -471,7 +450,7 @@ impl DecimalLiteralRepresentation {
|
||||||
let hex = format!("{val:#X}");
|
let hex = format!("{val:#X}");
|
||||||
let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false);
|
let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false);
|
||||||
let _: Result<(), ()> = Self::do_lint(num_lit.integer).map_err(|warning_type| {
|
let _: Result<(), ()> = Self::do_lint(num_lit.integer).map_err(|warning_type| {
|
||||||
warning_type.display(num_lit.format(), cx, span);
|
warning_type.display(num_lit, cx, span);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::source::snippet_with_context;
|
use clippy_utils::source::snippet_with_context;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -29,19 +29,22 @@ pub(super) fn check(
|
||||||
sym::RcWeak | sym::ArcWeak => "Weak",
|
sym::RcWeak | sym::ArcWeak => "Weak",
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
span_lint_and_then(
|
||||||
// Sometimes unnecessary ::<_> after Rc/Arc/Weak
|
|
||||||
let mut app = Applicability::Unspecified;
|
|
||||||
let snippet = snippet_with_context(cx, receiver.span, expr.span.ctxt(), "..", &mut app).0;
|
|
||||||
|
|
||||||
span_lint_and_sugg(
|
|
||||||
cx,
|
cx,
|
||||||
CLONE_ON_REF_PTR,
|
CLONE_ON_REF_PTR,
|
||||||
expr.span,
|
expr.span,
|
||||||
"using `.clone()` on a ref-counted pointer",
|
"using `.clone()` on a ref-counted pointer",
|
||||||
"try",
|
|diag| {
|
||||||
format!("{caller_type}::<{}>::clone(&{snippet})", subst.type_at(0)),
|
// Sometimes unnecessary ::<_> after Rc/Arc/Weak
|
||||||
app,
|
let mut app = Applicability::Unspecified;
|
||||||
|
let snippet = snippet_with_context(cx, receiver.span, expr.span.ctxt(), "..", &mut app).0;
|
||||||
|
diag.span_suggestion(
|
||||||
|
expr.span,
|
||||||
|
"try",
|
||||||
|
format!("{caller_type}::<{}>::clone(&{snippet})", subst.type_at(0)),
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::source::snippet_with_context;
|
use clippy_utils::source::snippet_with_context;
|
||||||
use clippy_utils::ty::is_type_lang_item;
|
use clippy_utils::ty::is_type_lang_item;
|
||||||
use clippy_utils::{get_parent_expr, peel_middle_ty_refs};
|
use clippy_utils::{get_parent_expr, peel_middle_ty_refs};
|
||||||
|
@ -86,9 +86,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
|
||||||
let (indexed_ty, indexed_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(indexed));
|
let (indexed_ty, indexed_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(indexed));
|
||||||
let parent_expr = get_parent_expr(cx, expr);
|
let parent_expr = get_parent_expr(cx, expr);
|
||||||
let needs_parens_for_prefix = parent_expr.map_or(false, |parent| parent.precedence().order() > PREC_PREFIX);
|
let needs_parens_for_prefix = parent_expr.map_or(false, |parent| parent.precedence().order() > PREC_PREFIX);
|
||||||
let mut app = Applicability::MachineApplicable;
|
|
||||||
|
|
||||||
let ((lint, msg), help, sugg) = if expr_ty == indexed_ty {
|
if expr_ty == indexed_ty {
|
||||||
if expr_ref_count > indexed_ref_count {
|
if expr_ref_count > indexed_ref_count {
|
||||||
// Indexing takes self by reference and can't return a reference to that
|
// Indexing takes self by reference and can't return a reference to that
|
||||||
// reference as it's a local variable. The only way this could happen is if
|
// reference as it's a local variable. The only way this could happen is if
|
||||||
|
@ -99,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
|
||||||
}
|
}
|
||||||
let deref_count = indexed_ref_count - expr_ref_count;
|
let deref_count = indexed_ref_count - expr_ref_count;
|
||||||
|
|
||||||
let (lint, reborrow_str, help_str) = if mutability == Mutability::Mut {
|
let ((lint, msg), reborrow_str, help_msg) = if mutability == Mutability::Mut {
|
||||||
// The slice was used to reborrow the mutable reference.
|
// The slice was used to reborrow the mutable reference.
|
||||||
(DEREF_BY_SLICING_LINT, "&mut *", "reborrow the original value instead")
|
(DEREF_BY_SLICING_LINT, "&mut *", "reborrow the original value instead")
|
||||||
} else if matches!(
|
} else if matches!(
|
||||||
|
@ -125,38 +124,36 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
|
||||||
(REDUNDANT_SLICING_LINT, "", "use the original value instead")
|
(REDUNDANT_SLICING_LINT, "", "use the original value instead")
|
||||||
};
|
};
|
||||||
|
|
||||||
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;
|
span_lint_and_then(cx, lint, expr.span, msg, |diag| {
|
||||||
let sugg = if (deref_count != 0 || !reborrow_str.is_empty()) && needs_parens_for_prefix {
|
let mut app = Applicability::MachineApplicable;
|
||||||
format!("({reborrow_str}{}{snip})", "*".repeat(deref_count))
|
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;
|
||||||
} else {
|
let sugg = if (deref_count != 0 || !reborrow_str.is_empty()) && needs_parens_for_prefix {
|
||||||
format!("{reborrow_str}{}{snip}", "*".repeat(deref_count))
|
format!("({reborrow_str}{}{snip})", "*".repeat(deref_count))
|
||||||
};
|
} else {
|
||||||
|
format!("{reborrow_str}{}{snip}", "*".repeat(deref_count))
|
||||||
(lint, help_str, sugg)
|
};
|
||||||
|
diag.span_suggestion(expr.span, help_msg, sugg, app);
|
||||||
|
});
|
||||||
} else if let Some(target_id) = cx.tcx.lang_items().deref_target() {
|
} else if let Some(target_id) = cx.tcx.lang_items().deref_target() {
|
||||||
if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions(
|
if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions(
|
||||||
cx.param_env,
|
cx.param_env,
|
||||||
Ty::new_projection_from_args(cx.tcx, target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])),
|
Ty::new_projection_from_args(cx.tcx, target_id, cx.tcx.mk_args(&[GenericArg::from(indexed_ty)])),
|
||||||
) {
|
) {
|
||||||
if deref_ty == expr_ty {
|
if deref_ty == expr_ty {
|
||||||
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;
|
let (lint, msg) = DEREF_BY_SLICING_LINT;
|
||||||
let sugg = if needs_parens_for_prefix {
|
span_lint_and_then(cx, lint, expr.span, msg, |diag| {
|
||||||
format!("(&{}{}*{snip})", mutability.prefix_str(), "*".repeat(indexed_ref_count))
|
let mut app = Applicability::MachineApplicable;
|
||||||
} else {
|
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;
|
||||||
format!("&{}{}*{snip}", mutability.prefix_str(), "*".repeat(indexed_ref_count))
|
let sugg = if needs_parens_for_prefix {
|
||||||
};
|
format!("(&{}{}*{snip})", mutability.prefix_str(), "*".repeat(indexed_ref_count))
|
||||||
(DEREF_BY_SLICING_LINT, "dereference the original value instead", sugg)
|
} else {
|
||||||
} else {
|
format!("&{}{}*{snip}", mutability.prefix_str(), "*".repeat(indexed_ref_count))
|
||||||
return;
|
};
|
||||||
|
diag.span_suggestion(expr.span, "dereference the original value instead", sugg, app);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
span_lint_and_sugg(cx, lint, expr.span, msg, help, sugg, app);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use clippy_config::msrvs::Msrv;
|
use clippy_config::msrvs::Msrv;
|
||||||
use clippy_config::Conf;
|
use clippy_config::Conf;
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::is_from_proc_macro;
|
use clippy_utils::is_from_proc_macro;
|
||||||
use rustc_attr::{StabilityLevel, StableSince};
|
use rustc_attr::{StabilityLevel, StableSince};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
|
@ -136,14 +136,20 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
if first_segment.ident.span != self.prev_span {
|
if first_segment.ident.span != self.prev_span {
|
||||||
span_lint_and_sugg(
|
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
|
||||||
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
lint,
|
lint,
|
||||||
first_segment.ident.span,
|
first_segment.ident.span,
|
||||||
format!("used import from `{used_mod}` instead of `{replace_with}`"),
|
format!("used import from `{used_mod}` instead of `{replace_with}`"),
|
||||||
format!("consider importing the item from `{replace_with}`"),
|
|diag| {
|
||||||
replace_with.to_string(),
|
diag.span_suggestion(
|
||||||
Applicability::MachineApplicable,
|
first_segment.ident.span,
|
||||||
|
format!("consider importing the item from `{replace_with}`"),
|
||||||
|
replace_with.to_string(),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
self.prev_span = first_segment.ident.span;
|
self.prev_span = first_segment.ident.span;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,25 @@ error: calling `std::fs::create_dir` where there may be a better way
|
||||||
--> tests/ui/create_dir.rs:10:5
|
--> tests/ui/create_dir.rs:10:5
|
||||||
|
|
|
|
||||||
LL | std::fs::create_dir("foo");
|
LL | std::fs::create_dir("foo");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("foo")`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::create-dir` implied by `-D warnings`
|
= note: `-D clippy::create-dir` implied by `-D warnings`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::create_dir)]`
|
= help: to override `-D warnings` add `#[allow(clippy::create_dir)]`
|
||||||
|
help: consider calling `std::fs::create_dir_all` instead
|
||||||
|
|
|
||||||
|
LL | create_dir_all("foo");
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: calling `std::fs::create_dir` where there may be a better way
|
error: calling `std::fs::create_dir` where there may be a better way
|
||||||
--> tests/ui/create_dir.rs:11:5
|
--> tests/ui/create_dir.rs:11:5
|
||||||
|
|
|
|
||||||
LL | std::fs::create_dir("bar").unwrap();
|
LL | std::fs::create_dir("bar").unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("bar")`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
help: consider calling `std::fs::create_dir_all` instead
|
||||||
|
|
|
||||||
|
LL | create_dir_all("bar").unwrap();
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ error: the `dbg!` macro is intended as a debugging tool
|
||||||
--> tests/ui/dbg_macro/dbg_macro.rs:48:5
|
--> tests/ui/dbg_macro/dbg_macro.rs:48:5
|
||||||
|
|
|
|
||||||
LL | dbg!();
|
LL | dbg!();
|
||||||
| ^^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
help: remove the invocation before committing it to a version control system
|
help: remove the invocation before committing it to a version control system
|
||||||
|
|
|
|
||||||
|
@ -136,7 +136,7 @@ error: the `dbg!` macro is intended as a debugging tool
|
||||||
--> tests/ui/dbg_macro/dbg_macro.rs:43:13
|
--> tests/ui/dbg_macro/dbg_macro.rs:43:13
|
||||||
|
|
|
|
||||||
LL | dbg!();
|
LL | dbg!();
|
||||||
| ^^^^^^^
|
| ^^^^^^
|
||||||
...
|
...
|
||||||
LL | expand_to_dbg!();
|
LL | expand_to_dbg!();
|
||||||
| ---------------- in this macro invocation
|
| ---------------- in this macro invocation
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: the `dbg!` macro is intended as a debugging tool
|
||||||
--> tests/ui/dbg_macro/auxiliary/submodule.rs:2:5
|
--> tests/ui/dbg_macro/auxiliary/submodule.rs:2:5
|
||||||
|
|
|
|
||||||
LL | dbg!();
|
LL | dbg!();
|
||||||
| ^^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::dbg-macro` implied by `-D warnings`
|
= note: `-D clippy::dbg-macro` implied by `-D warnings`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]`
|
= help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]`
|
||||||
|
|
Loading…
Add table
Reference in a new issue