Replace span_suggestion_with_style with _verbose

This commit is contained in:
Alex Macleod 2024-08-17 18:09:28 +00:00
parent 68b222ebd9
commit 4f661302c6
10 changed files with 27 additions and 55 deletions

View file

@ -4,7 +4,7 @@ use clippy_utils::expr_or_init;
use clippy_utils::source::snippet; use clippy_utils::source::snippet;
use clippy_utils::sugg::Sugg; use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize}; use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize};
use rustc_errors::{Applicability, Diag, SuggestionStyle}; use rustc_errors::{Applicability, Diag};
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
@ -190,12 +190,10 @@ fn offer_suggestion(
format!("{cast_to_snip}::try_from({})", Sugg::hir(cx, cast_expr, "..")) format!("{cast_to_snip}::try_from({})", Sugg::hir(cx, cast_expr, ".."))
}; };
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
expr.span, expr.span,
"... or use `try_from` and handle the error accordingly", "... or use `try_from` and handle the error accordingly",
suggestion, suggestion,
Applicability::Unspecified, Applicability::Unspecified,
// always show the suggestion in a separate line
SuggestionStyle::ShowAlways,
); );
} }

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet_with_applicability; use clippy_utils::source::snippet_with_applicability;
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::Applicability;
use rustc_hir::Expr; use rustc_hir::Expr;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
@ -24,12 +24,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
expr.span, expr.span,
format!("casting function pointer `{from_snippet}` to `{cast_to}`"), format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
|diag| { |diag| {
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
expr.span, expr.span,
"did you mean to invoke the function?", "did you mean to invoke the function?",
format!("{from_snippet}() as {cast_to}"), format!("{from_snippet}() as {cast_to}"),
applicability, applicability,
SuggestionStyle::ShowAlways,
); );
}, },
); );

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet_with_applicability; use clippy_utils::source::snippet_with_applicability;
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::Applicability;
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;
@ -46,7 +46,7 @@ impl LateLintPass<'_> for CreateDir {
"calling `std::fs::create_dir` where there may be a better way", "calling `std::fs::create_dir` where there may be a better way",
|diag| { |diag| {
let mut app = Applicability::MaybeIncorrect; let mut app = Applicability::MaybeIncorrect;
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
expr.span, expr.span,
"consider calling `std::fs::create_dir_all` instead", "consider calling `std::fs::create_dir_all` instead",
format!( format!(
@ -54,7 +54,6 @@ impl LateLintPass<'_> for CreateDir {
snippet_with_applicability(cx, arg.span, "..", &mut app) snippet_with_applicability(cx, arg.span, "..", &mut app)
), ),
app, app,
SuggestionStyle::ShowAlways,
); );
}, },
); );

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use itertools::Itertools; use itertools::Itertools;
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::Applicability;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
use std::ops::Range; use std::ops::Range;
@ -59,12 +59,11 @@ pub(super) fn check(
&& (doc_comment == "///" || doc_comment == "//!") && (doc_comment == "///" || doc_comment == "//!")
{ {
// suggest filling in a blank line // suggest filling in a blank line
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
line_break_span.shrink_to_lo(), line_break_span.shrink_to_lo(),
"if this should be its own paragraph, add a blank doc comment line", "if this should be its own paragraph, add a blank doc comment line",
format!("\n{doc_comment}"), format!("\n{doc_comment}"),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
SuggestionStyle::ShowAlways,
); );
if ccount > 0 || blockquote_level > 0 { if ccount > 0 || blockquote_level > 0 {
diag.help("if this not intended to be a quote at all, escape it with `\\>`"); diag.help("if this not intended to be a quote at all, escape it with `\\>`");
@ -79,12 +78,11 @@ pub(super) fn check(
if ccount == 0 && blockquote_level == 0 { if ccount == 0 && blockquote_level == 0 {
// simpler suggestion style for indentation // simpler suggestion style for indentation
let indent = list_indentation - lcount; let indent = list_indentation - lcount;
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
span.shrink_to_hi(), span.shrink_to_hi(),
"indent this line", "indent this line",
std::iter::repeat(" ").take(indent).join(""), std::iter::repeat(" ").take(indent).join(""),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
SuggestionStyle::ShowAlways,
); );
diag.help("if this is supposed to be its own paragraph, add a blank line"); diag.help("if this is supposed to be its own paragraph, add a blank line");
return; return;
@ -107,12 +105,11 @@ pub(super) fn check(
suggested.push_str(text); suggested.push_str(text);
} }
} }
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
span, span,
"add markers to start of line", "add markers to start of line",
suggested, suggested,
Applicability::MachineApplicable, Applicability::MachineApplicable,
SuggestionStyle::ShowAlways,
); );
diag.help("if this not intended to be a quote at all, escape it with `\\>`"); diag.help("if this not intended to be a quote at all, escape it with `\\>`");
}); });

View file

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::snippet_with_applicability; use clippy_utils::source::snippet_with_applicability;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::Applicability;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::{BytePos, Pos, Span}; use rustc_span::{BytePos, Pos, Span};
use url::Url; use url::Url;
@ -137,24 +137,15 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, b
} }
if has_underscore(word) || word.contains("::") || is_camel_case(word) || word.ends_with("()") { if has_underscore(word) || word.contains("::") || is_camel_case(word) || word.ends_with("()") {
let mut applicability = Applicability::MachineApplicable;
span_lint_and_then( span_lint_and_then(
cx, cx,
DOC_MARKDOWN, DOC_MARKDOWN,
span, span,
"item in documentation is missing backticks", "item in documentation is missing backticks",
|diag| { |diag| {
let mut applicability = Applicability::MachineApplicable;
let snippet = snippet_with_applicability(cx, span, "..", &mut applicability); let snippet = snippet_with_applicability(cx, span, "..", &mut applicability);
diag.span_suggestion_with_style( diag.span_suggestion_verbose(span, "try", format!("`{snippet}`"), applicability);
span,
"try",
format!("`{snippet}`"),
applicability,
// always show the suggestion in a separate line, since the
// inline presentation adds another pair of backticks
SuggestionStyle::ShowAlways,
);
}, },
); );
} }

View file

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::numeric_literal; use clippy_utils::numeric_literal;
use rustc_ast::ast::{self, LitFloatType, LitKind}; use rustc_ast::ast::{self, LitFloatType, LitKind};
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{self, FloatTy}; use rustc_middle::ty::{self, FloatTy};
@ -117,12 +117,11 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
if type_suffix.is_none() { if type_suffix.is_none() {
float_str.push_str(".0"); float_str.push_str(".0");
} }
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
expr.span, expr.span,
"consider changing the type or replacing it with", "consider changing the type or replacing it with",
numeric_literal::format(&float_str, type_suffix, true), numeric_literal::format(&float_str, type_suffix, true),
Applicability::MachineApplicable, Applicability::MachineApplicable,
SuggestionStyle::ShowAlways,
); );
}, },
); );
@ -134,12 +133,11 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
expr.span, expr.span,
"float has excessive precision", "float has excessive precision",
|diag| { |diag| {
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
expr.span, expr.span,
"consider changing the type or truncating it to", "consider changing the type or truncating it to",
numeric_literal::format(&float_str, type_suffix, true), numeric_literal::format(&float_str, type_suffix, true),
Applicability::MachineApplicable, Applicability::MachineApplicable,
SuggestionStyle::ShowAlways,
); );
}, },
); );

View file

@ -1,6 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_in_test; use clippy_utils::is_in_test;
use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, GenericParam, Generics, HirId, ImplItem, ImplItemKind, TraitItem, TraitItemKind}; use rustc_hir::{Body, GenericParam, Generics, HirId, ImplItem, ImplItemKind, TraitItem, TraitItemKind};
@ -18,20 +19,18 @@ fn report(cx: &LateContext<'_>, param: &GenericParam<'_>, generics: &Generics<'_
|diag| { |diag| {
if let Some(gen_span) = generics.span_for_param_suggestion() { if let Some(gen_span) = generics.span_for_param_suggestion() {
// If there's already a generic param with the same bound, do not lint **this** suggestion. // If there's already a generic param with the same bound, do not lint **this** suggestion.
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
gen_span, gen_span,
"add a type parameter", "add a type parameter",
format!(", {{ /* Generic name */ }}: {}", &param.name.ident().as_str()[5..]), format!(", {{ /* Generic name */ }}: {}", &param.name.ident().as_str()[5..]),
rustc_errors::Applicability::HasPlaceholders, Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways,
); );
} else { } else {
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
generics.span, generics.span,
"add a type parameter", "add a type parameter",
format!("<{{ /* Generic name */ }}: {}>", &param.name.ident().as_str()[5..]), format!("<{{ /* Generic name */ }}: {}>", &param.name.ident().as_str()[5..]),
rustc_errors::Applicability::HasPlaceholders, Applicability::HasPlaceholders,
rustc_errors::SuggestionStyle::ShowAlways,
); );
} }
}, },

View file

@ -3,7 +3,7 @@ use clippy_utils::source::{snippet_with_applicability, snippet_with_context, wal
use clippy_utils::visitors::for_each_expr_without_closures; use clippy_utils::visitors::for_each_expr_without_closures;
use clippy_utils::{get_async_fn_body, is_async_fn, is_from_proc_macro}; use clippy_utils::{get_async_fn_body, is_async_fn, is_from_proc_macro};
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, FnRetTy, HirId}; use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, FnRetTy, HirId};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
@ -54,13 +54,7 @@ fn lint_return(cx: &LateContext<'_>, emission_place: HirId, span: Span) {
|diag| { |diag| {
let mut app = Applicability::MachineApplicable; let mut app = Applicability::MachineApplicable;
let snip = snippet_with_applicability(cx, span, "..", &mut app); let snip = snippet_with_applicability(cx, span, "..", &mut app);
diag.span_suggestion_with_style( diag.span_suggestion_verbose(span, "add `return` as shown", format!("return {snip}"), app);
span,
"add `return` as shown",
format!("return {snip}"),
app,
SuggestionStyle::ShowAlways,
);
}, },
); );
} }
@ -75,12 +69,11 @@ fn lint_break(cx: &LateContext<'_>, emission_place: HirId, break_span: Span, exp
|diag| { |diag| {
let mut app = Applicability::MachineApplicable; let mut app = Applicability::MachineApplicable;
let snip = snippet_with_context(cx, expr_span, break_span.ctxt(), "..", &mut app).0; let snip = snippet_with_context(cx, expr_span, break_span.ctxt(), "..", &mut app).0;
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
break_span, break_span,
"change `break` to `return` as shown", "change `break` to `return` as shown",
format!("return {snip}"), format!("return {snip}"),
app, app,
SuggestionStyle::ShowAlways,
); );
}, },
); );

View file

@ -3,7 +3,7 @@ use clippy_config::Conf;
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then}; use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
use clippy_utils::{get_parent_expr, is_from_proc_macro}; use clippy_utils::{get_parent_expr, is_from_proc_macro};
use hir::def_id::DefId; use hir::def_id::DefId;
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::{ExprKind, Item, ItemKind, QPath, UseKind}; use rustc_hir::{ExprKind, Item, ItemKind, QPath, UseKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
@ -143,12 +143,11 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
&& !is_from_proc_macro(cx, expr) && !is_from_proc_macro(cx, expr)
{ {
span_lint_hir_and_then(cx, LEGACY_NUMERIC_CONSTANTS, expr.hir_id, span, msg, |diag| { span_lint_hir_and_then(cx, LEGACY_NUMERIC_CONSTANTS, expr.hir_id, span, msg, |diag| {
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
span, span,
"use the associated constant instead", "use the associated constant instead",
sugg, sugg,
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
SuggestionStyle::ShowAlways,
); );
}); });
} }

View file

@ -74,7 +74,7 @@ pub(super) fn check<'tcx>(
"&" "&"
}; };
diag.span_suggestion_with_style( diag.span_suggestion_verbose(
span, span,
"using `[]` is clearer and more concise", "using `[]` is clearer and more concise",
format!( format!(
@ -82,7 +82,6 @@ pub(super) fn check<'tcx>(
snippet_with_applicability(cx, recv.span, "..", &mut applicability) snippet_with_applicability(cx, recv.span, "..", &mut applicability)
), ),
applicability, applicability,
rustc_errors::SuggestionStyle::ShowAlways,
); );
}, },
); );