Skip to content

Commit ba6bc81

Browse files
committed
Auto merge of #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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 14 deletions
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

Lines changed: 17 additions & 20 deletions
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

Lines changed: 2 additions & 3 deletions
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
);

0 commit comments

Comments
 (0)