Skip to content

Commit 3a162b0

Browse files
committed
revert clippy formating
1 parent b93ed5f commit 3a162b0

File tree

12 files changed

+257
-278
lines changed

12 files changed

+257
-278
lines changed

src/tools/clippy/clippy_lints/src/doc.rs

+51-50
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
22
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
3-
use clippy_utils::{
4-
is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty,
5-
};
3+
use clippy_utils::{is_entrypoint_fn, is_expn_of, match_panic_def_id, method_chain_args, return_ty};
64
use if_chain::if_chain;
75
use itertools::Itertools;
86
use rustc_ast::ast::{Async, AttrKind, Attribute, FnKind, FnRetTy, ItemKind};
@@ -197,7 +195,10 @@ pub struct DocMarkdown {
197195

198196
impl DocMarkdown {
199197
pub fn new(valid_idents: FxHashSet<String>) -> Self {
200-
Self { valid_idents, in_trait_impl: false }
198+
Self {
199+
valid_idents,
200+
in_trait_impl: false,
201+
}
201202
}
202203
}
203204

@@ -216,9 +217,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
216217
let headers = check_attrs(cx, &self.valid_idents, attrs);
217218
match item.kind {
218219
hir::ItemKind::Fn(ref sig, _, body_id) => {
219-
if !(is_entrypoint_fn(cx, item.def_id.to_def_id())
220-
|| in_external_macro(cx.tcx.sess, item.span))
221-
{
220+
if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
222221
let body = cx.tcx.hir().body(body_id);
223222
let mut fpu = FindPanicUnwrap {
224223
cx,
@@ -236,11 +235,11 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
236235
fpu.panic_span,
237236
);
238237
}
239-
}
238+
},
240239
hir::ItemKind::Impl(ref impl_) => {
241240
self.in_trait_impl = impl_.of_trait.is_some();
242-
}
243-
_ => {}
241+
},
242+
_ => {},
244243
}
245244
}
246245

@@ -300,7 +299,12 @@ fn lint_for_missing_headers<'tcx>(
300299
return; // Private functions do not require doc comments
301300
}
302301
if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
303-
span_lint(cx, MISSING_SAFETY_DOC, span, "unsafe function's docs miss `# Safety` section");
302+
span_lint(
303+
cx,
304+
MISSING_SAFETY_DOC,
305+
span,
306+
"unsafe function's docs miss `# Safety` section",
307+
);
304308
}
305309
if !headers.panics && panic_span.is_some() {
306310
span_lint_and_note(
@@ -353,11 +357,7 @@ fn lint_for_missing_headers<'tcx>(
353357
/// the spans but this function is inspired from the later.
354358
#[allow(clippy::cast_possible_truncation)]
355359
#[must_use]
356-
pub fn strip_doc_comment_decoration(
357-
doc: &str,
358-
comment_kind: CommentKind,
359-
span: Span,
360-
) -> (String, Vec<(usize, Span)>) {
360+
pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: Span) -> (String, Vec<(usize, Span)>) {
361361
// one-line comments lose their prefix
362362
if comment_kind == CommentKind::Line {
363363
let mut doc = doc.to_owned();
@@ -405,24 +405,23 @@ struct DocHeaders {
405405
panics: bool,
406406
}
407407

408-
fn check_attrs<'a>(
409-
cx: &LateContext<'_>,
410-
valid_idents: &FxHashSet<String>,
411-
attrs: &'a [Attribute],
412-
) -> DocHeaders {
408+
fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &'a [Attribute]) -> DocHeaders {
413409
let mut doc = String::new();
414410
let mut spans = vec![];
415411

416412
for attr in attrs {
417413
if let AttrKind::DocComment(comment_kind, comment) = attr.kind {
418-
let (comment, current_spans) =
419-
strip_doc_comment_decoration(&comment.as_str(), comment_kind, attr.span);
414+
let (comment, current_spans) = strip_doc_comment_decoration(&comment.as_str(), comment_kind, attr.span);
420415
spans.extend_from_slice(&current_spans);
421416
doc.push_str(&comment);
422417
} else if attr.has_name(sym::doc) {
423418
// ignore mix of sugared and non-sugared doc
424419
// don't trigger the safety or errors check
425-
return DocHeaders { safety: true, errors: true, panics: true };
420+
return DocHeaders {
421+
safety: true,
422+
errors: true,
423+
panics: true,
424+
};
426425
}
427426
}
428427

@@ -434,7 +433,11 @@ fn check_attrs<'a>(
434433
}
435434

436435
if doc.is_empty() {
437-
return DocHeaders { safety: false, errors: false, panics: false };
436+
return DocHeaders {
437+
safety: false,
438+
errors: false,
439+
panics: false,
440+
};
438441
}
439442

440443
let parser = pulldown_cmark::Parser::new(&doc).into_offset_iter();
@@ -450,7 +453,7 @@ fn check_attrs<'a>(
450453
let mut previous = previous.to_string();
451454
previous.push_str(&current);
452455
Ok((Text(previous.into()), previous_range))
453-
}
456+
},
454457
(previous, current) => Err(((previous, previous_range), (current, current_range))),
455458
}
456459
});
@@ -472,7 +475,11 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
472475
};
473476
use pulldown_cmark::Tag::{CodeBlock, Heading, Link};
474477

475-
let mut headers = DocHeaders { safety: false, errors: false, panics: false };
478+
let mut headers = DocHeaders {
479+
safety: false,
480+
errors: false,
481+
panics: false,
482+
};
476483
let mut in_code = false;
477484
let mut in_link = None;
478485
let mut in_heading = false;
@@ -496,11 +503,11 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
496503
}
497504
}
498505
}
499-
}
506+
},
500507
End(CodeBlock(_)) => {
501508
in_code = false;
502509
is_rust = false;
503-
}
510+
},
504511
Start(Link(_, url, _)) => in_link = Some(url),
505512
End(Link(..)) => in_link = None,
506513
Start(Heading(_)) => in_heading = true,
@@ -534,7 +541,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
534541

535542
check_text(cx, valid_idents, &text, span);
536543
}
537-
}
544+
},
538545
}
539546
}
540547
headers
@@ -547,21 +554,19 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
547554
let filename = FileName::anon_source_code(code);
548555

549556
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
550-
let emitter =
551-
EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
557+
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
552558
let handler = Handler::with_emitter(false, None, box emitter);
553559
let sess = ParseSess::with_span_handler(handler, sm);
554560

555-
let mut parser =
556-
match maybe_new_parser_from_source_str(&sess, filename, code.into()) {
557-
Ok(p) => p,
558-
Err(errs) => {
559-
for mut err in errs {
560-
err.cancel();
561-
}
562-
return false;
561+
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code.into()) {
562+
Ok(p) => p,
563+
Err(errs) => {
564+
for mut err in errs {
565+
err.cancel();
563566
}
564-
};
567+
return false;
568+
},
569+
};
565570

566571
let mut relevant_main_found = false;
567572
loop {
@@ -573,9 +578,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
573578
| ItemKind::ExternCrate(..)
574579
| ItemKind::ForeignMod(..) => return false,
575580
// We found a main function ...
576-
ItemKind::Fn(box FnKind(_, sig, _, Some(block)))
577-
if item.ident.name == sym::main =>
578-
{
581+
ItemKind::Fn(box FnKind(_, sig, _, Some(block))) if item.ident.name == sym::main => {
579582
let is_async = matches!(sig.header.asyncness, Async::Yes { .. });
580583
let returns_nothing = match &sig.decl.output {
581584
FnRetTy::Default(..) => true,
@@ -590,16 +593,16 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
590593
// This main function should not be linted, we're done
591594
return false;
592595
}
593-
}
596+
},
594597
// Another function was found; this case is ignored too
595598
ItemKind::Fn(..) => return false,
596-
_ => {}
599+
_ => {},
597600
},
598601
Ok(None) => break,
599602
Err(mut e) => {
600603
e.cancel();
601604
return false;
602-
}
605+
},
603606
}
604607
}
605608

@@ -719,9 +722,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
719722
}
720723

721724
// check for `assert_eq` or `assert_ne`
722-
if is_expn_of(expr.span, "assert_eq").is_some()
723-
|| is_expn_of(expr.span, "assert_ne").is_some()
724-
{
725+
if is_expn_of(expr.span, "assert_eq").is_some() || is_expn_of(expr.span, "assert_ne").is_some() {
725726
self.panic_span = Some(expr.span);
726727
}
727728

src/tools/clippy/clippy_lints/src/fallible_impl_from.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
6565
}
6666
}
6767

68-
fn lint_impl_body<'tcx>(
69-
cx: &LateContext<'tcx>,
70-
impl_span: Span,
71-
impl_items: &[hir::ImplItemRef<'_>],
72-
) {
68+
fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) {
7369
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
7470
use rustc_hir::{Expr, ExprKind, ImplItemKind, QPath};
7571

src/tools/clippy/clippy_lints/src/functions/must_use.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
2727
if let Some(attr) = attr {
2828
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
2929
return;
30-
} else if is_public
31-
&& !is_proc_macro(cx.sess(), attrs)
32-
&& !attrs.iter().any(|a| a.has_name(sym::no_mangle))
33-
{
30+
} else if is_public && !is_proc_macro(cx.sess(), attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) {
3431
check_must_use_candidate(
3532
cx,
3633
sig.decl,
@@ -52,10 +49,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
5249
let attr = must_use_attr(attrs);
5350
if let Some(attr) = attr {
5451
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
55-
} else if is_public
56-
&& !is_proc_macro(cx.sess(), attrs)
57-
&& trait_ref_of_method(cx, item.hir_id()).is_none()
58-
{
52+
} else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.hir_id()).is_none() {
5953
check_must_use_candidate(
6054
cx,
6155
sig.decl,
@@ -192,25 +186,20 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
192186

193187
static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]];
194188

195-
fn is_mutable_ty<'tcx>(
196-
cx: &LateContext<'tcx>,
197-
ty: Ty<'tcx>,
198-
span: Span,
199-
tys: &mut DefIdSet,
200-
) -> bool {
189+
fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut DefIdSet) -> bool {
201190
match *ty.kind() {
202191
// primitive types are never mutable
203192
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
204193
ty::Adt(adt, substs) => {
205194
tys.insert(adt.did) && !ty.is_freeze(cx.tcx.at(span), cx.param_env)
206195
|| KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path))
207196
&& substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
208-
}
197+
},
209198
ty::Tuple(substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
210199
ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys),
211200
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => {
212201
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys)
213-
}
202+
},
214203
// calling something constitutes a side effect, so return true on all callables
215204
// also never calls need not be used, so return true for them, too
216205
_ => true,
@@ -249,13 +238,11 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
249238
}
250239
tys.clear();
251240
}
252-
}
253-
Assign(target, ..)
254-
| AssignOp(_, target, _)
255-
| AddrOf(_, hir::Mutability::Mut, target) => {
241+
},
242+
Assign(target, ..) | AssignOp(_, target, _) | AddrOf(_, hir::Mutability::Mut, target) => {
256243
self.mutates_static |= is_mutated_static(target)
257-
}
258-
_ => {}
244+
},
245+
_ => {},
259246
}
260247
}
261248

@@ -276,7 +263,10 @@ fn is_mutated_static(e: &hir::Expr<'_>) -> bool {
276263
}
277264

278265
fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bool {
279-
let mut v = StaticMutVisitor { cx, mutates_static: false };
266+
let mut v = StaticMutVisitor {
267+
cx,
268+
mutates_static: false,
269+
};
280270
intravisit::walk_expr(&mut v, &body.value);
281271
v.mutates_static
282272
}

src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ use rustc_infer::infer::TyCtxtInferExt;
77
use rustc_lint::LateContext;
88
use rustc_middle::{mir::FakeReadCause, ty};
99
use rustc_span::source_map::Span;
10-
use rustc_typeck::expr_use_visitor::{
11-
ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId,
12-
};
10+
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
1311

1412
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) {
15-
if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(arg) {
13+
if let Some(higher::Range {
14+
start: Some(start),
15+
end: Some(end),
16+
..
17+
}) = higher::range(arg)
18+
{
1619
let mut_ids = vec![check_for_mutability(cx, start), check_for_mutability(cx, end)];
1720
if mut_ids[0].is_some() || mut_ids[1].is_some() {
1821
let (span_low, span_high) = check_for_mutation(cx, body, &mut_ids);
@@ -105,13 +108,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
105108
}
106109
}
107110

108-
fn fake_read(
109-
&mut self,
110-
_: rustc_typeck::expr_use_visitor::Place<'tcx>,
111-
_: FakeReadCause,
112-
_: HirId,
113-
) {
114-
}
111+
fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {}
115112
}
116113

117114
impl MutatePairDelegate<'_, '_> {

0 commit comments

Comments
 (0)