Skip to content

Commit 95eeaab

Browse files
committed
clean-up
- update file name to match lint name - use `Symbol`s instead of `&str`s - get rid of needless lifetimes
1 parent c6f2557 commit 95eeaab

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

clippy_lints_internal/src/collapsible_calls.rs renamed to clippy_lints_internal/src/collapsible_span_lint_calls.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet;
3-
use clippy_utils::{SpanlessEq, is_lint_allowed, peel_blocks_with_stmt};
3+
use clippy_utils::{SpanlessEq, is_lint_allowed, peel_blocks_with_stmt, sym};
44
use rustc_errors::Applicability;
55
use rustc_hir::{Closure, Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
@@ -91,28 +91,28 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
9191
let and_then_snippets =
9292
get_and_then_snippets(cx, call_cx.span, call_lint.span, call_sp.span, call_msg.span);
9393
let mut sle = SpanlessEq::new(cx).deny_side_effects();
94-
match ps.ident.as_str() {
95-
"span_suggestion" if sle.eq_expr(call_sp, &span_call_args[0]) => {
94+
match ps.ident.name {
95+
sym::span_suggestion if sle.eq_expr(call_sp, &span_call_args[0]) => {
9696
suggest_suggestion(
9797
cx,
9898
expr,
9999
&and_then_snippets,
100100
&span_suggestion_snippets(cx, span_call_args),
101101
);
102102
},
103-
"span_help" if sle.eq_expr(call_sp, &span_call_args[0]) => {
103+
sym::span_help if sle.eq_expr(call_sp, &span_call_args[0]) => {
104104
let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
105105
suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), true);
106106
},
107-
"span_note" if sle.eq_expr(call_sp, &span_call_args[0]) => {
107+
sym::span_note if sle.eq_expr(call_sp, &span_call_args[0]) => {
108108
let note_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
109109
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), true);
110110
},
111-
"help" => {
111+
sym::help => {
112112
let help_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
113113
suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), false);
114114
},
115-
"note" => {
115+
sym::note => {
116116
let note_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
117117
suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), false);
118118
},
@@ -122,11 +122,11 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
122122
}
123123
}
124124

125-
struct AndThenSnippets<'a> {
126-
cx: Cow<'a, str>,
127-
lint: Cow<'a, str>,
128-
span: Cow<'a, str>,
129-
msg: Cow<'a, str>,
125+
struct AndThenSnippets {
126+
cx: Cow<'static, str>,
127+
lint: Cow<'static, str>,
128+
span: Cow<'static, str>,
129+
msg: Cow<'static, str>,
130130
}
131131

132132
fn get_and_then_snippets(
@@ -135,7 +135,7 @@ fn get_and_then_snippets(
135135
lint_span: Span,
136136
span_span: Span,
137137
msg_span: Span,
138-
) -> AndThenSnippets<'static> {
138+
) -> AndThenSnippets {
139139
let cx_snippet = snippet(cx, cx_span, "cx");
140140
let lint_snippet = snippet(cx, lint_span, "..");
141141
let span_snippet = snippet(cx, span_span, "span");
@@ -149,16 +149,13 @@ fn get_and_then_snippets(
149149
}
150150
}
151151

152-
struct SpanSuggestionSnippets<'a> {
153-
help: Cow<'a, str>,
154-
sugg: Cow<'a, str>,
155-
applicability: Cow<'a, str>,
152+
struct SpanSuggestionSnippets {
153+
help: Cow<'static, str>,
154+
sugg: Cow<'static, str>,
155+
applicability: Cow<'static, str>,
156156
}
157157

158-
fn span_suggestion_snippets<'a, 'hir>(
159-
cx: &LateContext<'_>,
160-
span_call_args: &'hir [Expr<'hir>],
161-
) -> SpanSuggestionSnippets<'a> {
158+
fn span_suggestion_snippets<'hir>(cx: &LateContext<'_>, span_call_args: &'hir [Expr<'hir>]) -> SpanSuggestionSnippets {
162159
let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
163160
let sugg_snippet = snippet(cx, span_call_args[2].span, "..");
164161
let applicability_snippet = snippet(cx, span_call_args[3].span, "Applicability::MachineApplicable");
@@ -173,8 +170,8 @@ fn span_suggestion_snippets<'a, 'hir>(
173170
fn suggest_suggestion(
174171
cx: &LateContext<'_>,
175172
expr: &Expr<'_>,
176-
and_then_snippets: &AndThenSnippets<'_>,
177-
span_suggestion_snippets: &SpanSuggestionSnippets<'_>,
173+
and_then_snippets: &AndThenSnippets,
174+
span_suggestion_snippets: &SpanSuggestionSnippets,
178175
) {
179176
span_lint_and_sugg(
180177
cx,
@@ -199,7 +196,7 @@ fn suggest_suggestion(
199196
fn suggest_help(
200197
cx: &LateContext<'_>,
201198
expr: &Expr<'_>,
202-
and_then_snippets: &AndThenSnippets<'_>,
199+
and_then_snippets: &AndThenSnippets,
203200
help: &str,
204201
with_span: bool,
205202
) {
@@ -226,7 +223,7 @@ fn suggest_help(
226223
fn suggest_note(
227224
cx: &LateContext<'_>,
228225
expr: &Expr<'_>,
229-
and_then_snippets: &AndThenSnippets<'_>,
226+
and_then_snippets: &AndThenSnippets,
230227
note: &str,
231228
with_span: bool,
232229
) {

clippy_lints_internal/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern crate rustc_session;
3131
extern crate rustc_span;
3232

3333
mod almost_standard_lint_formulation;
34-
mod collapsible_calls;
34+
mod collapsible_span_lint_calls;
3535
mod derive_deserialize_allowing_unknown;
3636
mod internal_paths;
3737
mod lint_without_lint_pass;

clippy_utils/src/sym.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ generate! {
173173
get_unchecked,
174174
get_unchecked_mut,
175175
has_significant_drop,
176+
help,
176177
hidden_glob_reexports,
177178
hygiene,
178179
insert,
@@ -310,7 +311,10 @@ generate! {
310311
sort,
311312
sort_by,
312313
sort_unstable_by,
314+
span_help,
313315
span_lint_and_then,
316+
span_note,
317+
span_suggestion,
314318
split,
315319
split_at,
316320
split_at_checked,

0 commit comments

Comments
 (0)