Skip to content

Commit ba6bc81

Browse files
committed
Auto merge of rust-lang#13278 - Alexendoo:misc-cleanup, r=y21
Misc cleanup changelog: none
2 parents 45720b7 + 6993752 commit ba6bc81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+89
-245
lines changed

clippy_lints/src/attrs/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! checks for attributes
2-
31
mod allow_attributes;
42
mod allow_attributes_without_reason;
53
mod blanket_clippy_restriction_lints;

clippy_lints/src/cargo/common_metadata.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! lint on missing cargo common metadata
2-
31
use cargo_metadata::Metadata;
42
use clippy_utils::diagnostics::span_lint;
53
use rustc_lint::LateContext;

clippy_lints/src/cargo/multiple_crate_versions.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! lint on multiple versions of a crate being used
2-
31
use cargo_metadata::{DependencyKind, Metadata, Node, Package, PackageId};
42
use clippy_utils::diagnostics::span_lint;
53
use itertools::Itertools;

clippy_lints/src/casts/cast_possible_truncation.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::expr_or_init;
44
use clippy_utils::source::snippet;
55
use clippy_utils::sugg::Sugg;
66
use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize};
7-
use rustc_errors::{Applicability, Diag, SuggestionStyle};
7+
use rustc_errors::{Applicability, Diag};
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::{BinOpKind, Expr, ExprKind};
1010
use rustc_lint::LateContext;
@@ -190,12 +190,10 @@ fn offer_suggestion(
190190
format!("{cast_to_snip}::try_from({})", Sugg::hir(cx, cast_expr, ".."))
191191
};
192192

193-
diag.span_suggestion_with_style(
193+
diag.span_suggestion_verbose(
194194
expr.span,
195195
"... or use `try_from` and handle the error accordingly",
196196
suggestion,
197197
Applicability::Unspecified,
198-
// always show the suggestion in a separate line
199-
SuggestionStyle::ShowAlways,
200198
);
201199
}

clippy_lints/src/casts/fn_to_numeric_cast_any.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet_with_applicability;
3-
use rustc_errors::{Applicability, SuggestionStyle};
3+
use rustc_errors::Applicability;
44
use rustc_hir::Expr;
55
use rustc_lint::LateContext;
66
use rustc_middle::ty::{self, Ty};
@@ -24,12 +24,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
2424
expr.span,
2525
format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
2626
|diag| {
27-
diag.span_suggestion_with_style(
27+
diag.span_suggestion_verbose(
2828
expr.span,
2929
"did you mean to invoke the function?",
3030
format!("{from_snippet}() as {cast_to}"),
3131
applicability,
32-
SuggestionStyle::ShowAlways,
3332
);
3433
},
3534
);

clippy_lints/src/checked_conversions.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! lint on manually implemented checked conversions that could be transformed into `try_from`
2-
31
use clippy_config::msrvs::{self, Msrv};
42
use clippy_config::Conf;
53
use clippy_utils::diagnostics::span_lint_and_sugg;

clippy_lints/src/cognitive_complexity.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! calculate cognitive complexity and warn about overly complex functions
2-
31
use clippy_config::Conf;
42
use clippy_utils::diagnostics::span_lint_and_help;
53
use clippy_utils::source::{IntoSpan, SpanRangeExt};

clippy_lints/src/collapsible_if.rs

-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
//! Checks for if expressions that contain only an if expression.
2-
//!
3-
//! For example, the lint would catch:
4-
//!
5-
//! ```rust,ignore
6-
//! if x {
7-
//! if y {
8-
//! println!("Hello world");
9-
//! }
10-
//! }
11-
//! ```
12-
//!
13-
//! This lint is **warn** by default
14-
151
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
162
use clippy_utils::source::{snippet, snippet_block, snippet_block_with_applicability};
173
use clippy_utils::sugg::Sugg;

clippy_lints/src/collection_is_never_read.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
2+
use clippy_utils::ty::{get_type_diagnostic_name, is_type_lang_item};
33
use clippy_utils::visitors::{for_each_expr, Visitable};
44
use clippy_utils::{get_enclosing_block, path_to_local_id};
55
use core::ops::ControlFlow;
66
use rustc_hir::{Body, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::declare_lint_pass;
99
use rustc_span::symbol::sym;
10-
use rustc_span::Symbol;
1110

1211
declare_clippy_lint! {
1312
/// ### What it does
@@ -44,24 +43,11 @@ declare_clippy_lint! {
4443
}
4544
declare_lint_pass!(CollectionIsNeverRead => [COLLECTION_IS_NEVER_READ]);
4645

47-
// Add `String` here when it is added to diagnostic items
48-
static COLLECTIONS: [Symbol; 9] = [
49-
sym::BTreeMap,
50-
sym::BTreeSet,
51-
sym::BinaryHeap,
52-
sym::HashMap,
53-
sym::HashSet,
54-
sym::LinkedList,
55-
sym::Option,
56-
sym::Vec,
57-
sym::VecDeque,
58-
];
59-
6046
impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
6147
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
6248
// Look for local variables whose type is a container. Search surrounding block for read access.
6349
if let PatKind::Binding(_, local_id, _, _) = local.pat.kind
64-
&& match_acceptable_type(cx, local, &COLLECTIONS)
50+
&& match_acceptable_type(cx, local)
6551
&& let Some(enclosing_block) = get_enclosing_block(cx, local.hir_id)
6652
&& has_no_read_access(cx, local_id, enclosing_block)
6753
{
@@ -70,11 +56,22 @@ impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
7056
}
7157
}
7258

73-
fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>, collections: &[Symbol]) -> bool {
59+
fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>) -> bool {
7460
let ty = cx.typeck_results().pat_ty(local.pat);
75-
collections.iter().any(|&sym| is_type_diagnostic_item(cx, ty, sym))
76-
// String type is a lang item but not a diagnostic item for now so we need a separate check
77-
|| is_type_lang_item(cx, ty, LangItem::String)
61+
matches!(
62+
get_type_diagnostic_name(cx, ty),
63+
Some(
64+
sym::BTreeMap
65+
| sym::BTreeSet
66+
| sym::BinaryHeap
67+
| sym::HashMap
68+
| sym::HashSet
69+
| sym::LinkedList
70+
| sym::Option
71+
| sym::Vec
72+
| sym::VecDeque
73+
)
74+
) || is_type_lang_item(cx, ty, LangItem::String)
7875
}
7976

8077
fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirId, block: T) -> bool {

clippy_lints/src/create_dir.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet_with_applicability;
3-
use rustc_errors::{Applicability, SuggestionStyle};
3+
use rustc_errors::Applicability;
44
use rustc_hir::{Expr, ExprKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
@@ -46,15 +46,14 @@ impl LateLintPass<'_> for CreateDir {
4646
"calling `std::fs::create_dir` where there may be a better way",
4747
|diag| {
4848
let mut app = Applicability::MaybeIncorrect;
49-
diag.span_suggestion_with_style(
49+
diag.span_suggestion_verbose(
5050
expr.span,
5151
"consider calling `std::fs::create_dir_all` instead",
5252
format!(
5353
"create_dir_all({})",
5454
snippet_with_applicability(cx, arg.span, "..", &mut app)
5555
),
5656
app,
57-
SuggestionStyle::ShowAlways,
5857
);
5958
},
6059
);

clippy_lints/src/doc/lazy_continuation.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use itertools::Itertools;
3-
use rustc_errors::{Applicability, SuggestionStyle};
3+
use rustc_errors::Applicability;
44
use rustc_lint::LateContext;
55
use rustc_span::{BytePos, Span};
66
use std::ops::Range;
@@ -59,12 +59,11 @@ pub(super) fn check(
5959
&& (doc_comment == "///" || doc_comment == "//!")
6060
{
6161
// suggest filling in a blank line
62-
diag.span_suggestion_with_style(
62+
diag.span_suggestion_verbose(
6363
line_break_span.shrink_to_lo(),
6464
"if this should be its own paragraph, add a blank doc comment line",
6565
format!("\n{doc_comment}"),
6666
Applicability::MaybeIncorrect,
67-
SuggestionStyle::ShowAlways,
6867
);
6968
if ccount > 0 || blockquote_level > 0 {
7069
diag.help("if this not intended to be a quote at all, escape it with `\\>`");
@@ -79,12 +78,11 @@ pub(super) fn check(
7978
if ccount == 0 && blockquote_level == 0 {
8079
// simpler suggestion style for indentation
8180
let indent = list_indentation - lcount;
82-
diag.span_suggestion_with_style(
81+
diag.span_suggestion_verbose(
8382
span.shrink_to_hi(),
8483
"indent this line",
8584
std::iter::repeat(" ").take(indent).join(""),
8685
Applicability::MaybeIncorrect,
87-
SuggestionStyle::ShowAlways,
8886
);
8987
diag.help("if this is supposed to be its own paragraph, add a blank line");
9088
return;
@@ -107,12 +105,11 @@ pub(super) fn check(
107105
suggested.push_str(text);
108106
}
109107
}
110-
diag.span_suggestion_with_style(
108+
diag.span_suggestion_verbose(
111109
span,
112110
"add markers to start of line",
113111
suggested,
114112
Applicability::MachineApplicable,
115-
SuggestionStyle::ShowAlways,
116113
);
117114
diag.help("if this not intended to be a quote at all, escape it with `\\>`");
118115
});

clippy_lints/src/doc/markdown.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::source::snippet_with_applicability;
33
use rustc_data_structures::fx::FxHashSet;
4-
use rustc_errors::{Applicability, SuggestionStyle};
4+
use rustc_errors::Applicability;
55
use rustc_lint::LateContext;
66
use rustc_span::{BytePos, Pos, Span};
77
use url::Url;
@@ -137,24 +137,15 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span, code_level: isize, b
137137
}
138138

139139
if has_underscore(word) || word.contains("::") || is_camel_case(word) || word.ends_with("()") {
140-
let mut applicability = Applicability::MachineApplicable;
141-
142140
span_lint_and_then(
143141
cx,
144142
DOC_MARKDOWN,
145143
span,
146144
"item in documentation is missing backticks",
147145
|diag| {
146+
let mut applicability = Applicability::MachineApplicable;
148147
let snippet = snippet_with_applicability(cx, span, "..", &mut applicability);
149-
diag.span_suggestion_with_style(
150-
span,
151-
"try",
152-
format!("`{snippet}`"),
153-
applicability,
154-
// always show the suggestion in a separate line, since the
155-
// inline presentation adds another pair of backticks
156-
SuggestionStyle::ShowAlways,
157-
);
148+
diag.span_suggestion_verbose(span, "try", format!("`{snippet}`"), applicability);
158149
},
159150
);
160151
}

clippy_lints/src/else_if_without_else.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! Lint on if expressions with an else if, but without a final else branch.
2-
31
use clippy_utils::diagnostics::span_lint_and_then;
42
use rustc_ast::ast::{Expr, ExprKind};
53
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};

clippy_lints/src/empty_enum.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! lint when there is an enum with no variants
2-
31
use clippy_utils::diagnostics::span_lint_and_help;
42
use rustc_hir::{Item, ItemKind};
53
use rustc_lint::{LateContext, LateLintPass};

clippy_lints/src/enum_clike.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//! lint on C-like enums that are `repr(isize/usize)` and have values that
2-
//! don't fit into an `i32`
3-
41
use clippy_utils::consts::{mir_to_const, Constant};
52
use clippy_utils::diagnostics::span_lint;
63
use rustc_hir::{Item, ItemKind};

clippy_lints/src/eta_reduction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::higher::VecArgs;
33
use clippy_utils::source::snippet_opt;
4-
use clippy_utils::ty::type_diagnostic_name;
4+
use clippy_utils::ty::get_type_diagnostic_name;
55
use clippy_utils::usage::{local_used_after_expr, local_used_in};
66
use clippy_utils::{get_path_from_caller_to_method_type, is_adjusted, path_to_local, path_to_local_id};
77
use rustc_errors::Applicability;
@@ -139,7 +139,7 @@ fn check_clousure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tc
139139
{
140140
let callee_ty_raw = typeck.expr_ty(callee);
141141
let callee_ty = callee_ty_raw.peel_refs();
142-
if matches!(type_diagnostic_name(cx, callee_ty), Some(sym::Arc | sym::Rc))
142+
if matches!(get_type_diagnostic_name(cx, callee_ty), Some(sym::Arc | sym::Rc))
143143
|| !check_inputs(typeck, body.params, None, args)
144144
{
145145
return;

clippy_lints/src/float_literal.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::numeric_literal;
33
use rustc_ast::ast::{self, LitFloatType, LitKind};
4-
use rustc_errors::{Applicability, SuggestionStyle};
4+
use rustc_errors::Applicability;
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::ty::{self, FloatTy};
@@ -117,12 +117,11 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
117117
if type_suffix.is_none() {
118118
float_str.push_str(".0");
119119
}
120-
diag.span_suggestion_with_style(
120+
diag.span_suggestion_verbose(
121121
expr.span,
122122
"consider changing the type or replacing it with",
123123
numeric_literal::format(&float_str, type_suffix, true),
124124
Applicability::MachineApplicable,
125-
SuggestionStyle::ShowAlways,
126125
);
127126
},
128127
);
@@ -134,12 +133,11 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
134133
expr.span,
135134
"float has excessive precision",
136135
|diag| {
137-
diag.span_suggestion_with_style(
136+
diag.span_suggestion_verbose(
138137
expr.span,
139138
"consider changing the type or truncating it to",
140139
numeric_literal::format(&float_str, type_suffix, true),
141140
Applicability::MachineApplicable,
142-
SuggestionStyle::ShowAlways,
143141
);
144142
},
145143
);

clippy_lints/src/functions/impl_trait_in_params.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::is_in_test;
33

4+
use rustc_errors::Applicability;
45
use rustc_hir as hir;
56
use rustc_hir::intravisit::FnKind;
67
use rustc_hir::{Body, GenericParam, Generics, HirId, ImplItem, ImplItemKind, TraitItem, TraitItemKind};
@@ -18,20 +19,18 @@ fn report(cx: &LateContext<'_>, param: &GenericParam<'_>, generics: &Generics<'_
1819
|diag| {
1920
if let Some(gen_span) = generics.span_for_param_suggestion() {
2021
// If there's already a generic param with the same bound, do not lint **this** suggestion.
21-
diag.span_suggestion_with_style(
22+
diag.span_suggestion_verbose(
2223
gen_span,
2324
"add a type parameter",
2425
format!(", {{ /* Generic name */ }}: {}", &param.name.ident().as_str()[5..]),
25-
rustc_errors::Applicability::HasPlaceholders,
26-
rustc_errors::SuggestionStyle::ShowAlways,
26+
Applicability::HasPlaceholders,
2727
);
2828
} else {
29-
diag.span_suggestion_with_style(
29+
diag.span_suggestion_verbose(
3030
generics.span,
3131
"add a type parameter",
3232
format!("<{{ /* Generic name */ }}: {}>", &param.name.ident().as_str()[5..]),
33-
rustc_errors::Applicability::HasPlaceholders,
34-
rustc_errors::SuggestionStyle::ShowAlways,
33+
Applicability::HasPlaceholders,
3534
);
3635
}
3736
},

0 commit comments

Comments
 (0)