Skip to content

Commit 395c782

Browse files
committed
clean-up
1 parent 2a9eb78 commit 395c782

File tree

6 files changed

+37
-40
lines changed

6 files changed

+37
-40
lines changed

clippy_lints/src/doc/too_long_first_doc_paragraph.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,9 @@ pub(super) fn check(
8282
&& let Some(second_span) = spans.get(1)
8383
&& let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi())
8484
&& let Some(snippet) = snippet_opt(cx, new_span)
85+
&& let Some(first) = snippet_opt(cx, *first_span)
86+
&& let Some(comment_form) = first.get(..3)
8587
{
86-
let Some(first) = snippet_opt(cx, *first_span) else {
87-
return;
88-
};
89-
let Some(comment_form) = first.get(..3) else {
90-
return;
91-
};
92-
9388
diag.span_suggestion(
9489
new_span,
9590
"add an empty line",

clippy_lints/src/eta_reduction.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,17 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
233233
},
234234
_ => (),
235235
}
236-
} else if let n_refs =
237-
callee_ty_adjustments
238-
.iter()
239-
.rev()
240-
.fold(0, |acc, adjustment| match adjustment.kind {
236+
} else {
237+
let n_refs = callee_ty_adjustments.iter().rev().fold(0, |acc, adjustment| {
238+
match adjustment.kind {
241239
Adjust::Deref(Some(_)) => acc + 1,
242240
Adjust::Deref(_) if acc > 0 => acc + 1,
243241
_ => acc,
244-
})
245-
&& n_refs > 0
246-
{
247-
snippet = format!("{}{snippet}", "*".repeat(n_refs));
242+
}
243+
});
244+
if n_refs > 0 {
245+
snippet = format!("{}{snippet}", "*".repeat(n_refs));
246+
}
248247
}
249248

250249
let replace_with = match callee_ty_adjusted.kind() {

clippy_lints/src/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
294294
&& lhs.span.eq_ctxt(op.span)
295295
&& let space_span = lhs.span.between(op.span)
296296
&& let Some(space_snippet) = snippet_opt(cx, space_span)
297-
&& let lint_span = lhs.span.with_lo(lhs.span.hi())
298297
&& space_snippet.contains('\n')
299298
&& indentation(cx, op.span) <= indentation(cx, lhs.span)
300299
{
300+
let lint_span = lhs.span.shrink_to_hi();
301301
span_lint_and_note(
302302
cx,
303303
POSSIBLE_MISSING_COMMA,

clippy_lints/src/manual_option_as_slice.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_config::Conf;
2-
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
2+
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::msrvs::Msrv;
44
use clippy_utils::{is_none_pattern, msrvs, peel_hir_expr_refs, sym};
55
use rustc_errors::Applicability;
@@ -134,19 +134,22 @@ fn check_as_ref(cx: &LateContext<'_>, expr: &Expr<'_>, span: Span, msrv: Msrv) {
134134
},
135135
)
136136
{
137-
if let Some(snippet) = clippy_utils::source::snippet_opt(cx, callee.span) {
138-
span_lint_and_sugg(
139-
cx,
140-
MANUAL_OPTION_AS_SLICE,
141-
span,
142-
"use `Option::as_slice`",
143-
"use",
144-
format!("{snippet}.as_slice()"),
145-
Applicability::MachineApplicable,
146-
);
147-
} else {
148-
span_lint(cx, MANUAL_OPTION_AS_SLICE, span, "use `Option_as_slice`");
149-
}
137+
span_lint_and_then(
138+
cx,
139+
MANUAL_OPTION_AS_SLICE,
140+
span,
141+
"manual implementation of `Option::as_slice`",
142+
|diag| {
143+
if let Some(snippet) = clippy_utils::source::snippet_opt(cx, callee.span) {
144+
diag.span_suggestion(
145+
span,
146+
"use",
147+
format!("{snippet}.as_slice()"),
148+
Applicability::MachineApplicable,
149+
);
150+
}
151+
},
152+
)
150153
}
151154
}
152155

clippy_lints/src/raw_strings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ impl EarlyLintPass for RawStrings {
7272
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
7373
if let ExprKind::FormatArgs(format_args) = &expr.kind
7474
&& !format_args.span.in_external_macro(cx.sess().source_map())
75-
&& format_args.span.check_source_text(cx, |src| src.starts_with('r'))
7675
&& let Some(str) = snippet_opt(cx.sess(), format_args.span)
77-
&& let count_hash = str.bytes().skip(1).take_while(|b| *b == b'#').count()
76+
&& let Some(str) = str.strip_prefix('r')
77+
&& let count_hash = str.bytes().take_while(|b| *b == b'#').count()
7878
&& let Some(str) = str.get(count_hash + 2..str.len() - count_hash - 1)
7979
{
8080
self.check_raw_string(

tests/ui/manual_option_as_slice.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: use `Option::as_slice`
1+
error: manual implementation of `Option::as_slice`
22
--> tests/ui/manual_option_as_slice.rs:5:9
33
|
44
LL | _ = match x.as_ref() {
@@ -12,7 +12,7 @@ LL | | };
1212
= note: `-D clippy::manual-option-as-slice` implied by `-D warnings`
1313
= help: to override `-D warnings` add `#[allow(clippy::manual_option_as_slice)]`
1414

15-
error: use `Option::as_slice`
15+
error: manual implementation of `Option::as_slice`
1616
--> tests/ui/manual_option_as_slice.rs:11:9
1717
|
1818
LL | _ = if let Some(f) = x.as_ref() {
@@ -25,31 +25,31 @@ LL | | &[]
2525
LL | | };
2626
| |_____^ help: use: `x.as_slice()`
2727

28-
error: use `Option::as_slice`
28+
error: manual implementation of `Option::as_slice`
2929
--> tests/ui/manual_option_as_slice.rs:19:9
3030
|
3131
LL | _ = x.as_ref().map_or(&[][..], std::slice::from_ref);
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()`
3333

34-
error: use `Option::as_slice`
34+
error: manual implementation of `Option::as_slice`
3535
--> tests/ui/manual_option_as_slice.rs:22:9
3636
|
3737
LL | _ = x.as_ref().map_or_else(Default::default, std::slice::from_ref);
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()`
3939

40-
error: use `Option::as_slice`
40+
error: manual implementation of `Option::as_slice`
4141
--> tests/ui/manual_option_as_slice.rs:25:9
4242
|
4343
LL | _ = x.as_ref().map(std::slice::from_ref).unwrap_or_default();
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()`
4545

46-
error: use `Option::as_slice`
46+
error: manual implementation of `Option::as_slice`
4747
--> tests/ui/manual_option_as_slice.rs:28:9
4848
|
4949
LL | _ = x.as_ref().map_or_else(|| &[42][..0], std::slice::from_ref);
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `x.as_slice()`
5151

52-
error: use `Option::as_slice`
52+
error: manual implementation of `Option::as_slice`
5353
--> tests/ui/manual_option_as_slice.rs:33:13
5454
|
5555
LL | _ = x.as_ref().map_or_else(<&[_]>::default, from_ref);

0 commit comments

Comments
 (0)