Skip to content

Commit bc5bf23

Browse files
committed
Run RustFmt
1 parent eaf8fa7 commit bc5bf23

File tree

4 files changed

+102
-77
lines changed

4 files changed

+102
-77
lines changed

src/librustc_lint/builtin.rs

+64-42
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
2424
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2525
use rustc::hir::map::Map;
26+
use rustc::lint::LintDiagnosticBuilder;
2627
use rustc::traits::misc::can_type_implement_copy;
2728
use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt};
2829
use rustc_ast_pretty::pprust::{self, expr_to_string};
2930
use rustc_data_structures::fx::FxHashSet;
3031
use rustc_errors::{Applicability, DiagnosticBuilder};
31-
use rustc::lint::LintDiagnosticBuilder;
3232
use rustc_feature::Stability;
3333
use rustc_feature::{deprecated_attributes, AttributeGate, AttributeTemplate, AttributeType};
3434
use rustc_hir as hir;
@@ -107,7 +107,9 @@ impl BoxPointers {
107107
fn check_heap_type(&self, cx: &LateContext<'_, '_>, span: Span, ty: Ty<'_>) {
108108
for leaf_ty in ty.walk() {
109109
if leaf_ty.is_box() {
110-
cx.struct_span_lint(BOX_POINTERS, span, |lint| lint.build(&format!("type uses owned (Box type) pointers: {}", ty)).emit());
110+
cx.struct_span_lint(BOX_POINTERS, span, |lint| {
111+
lint.build(&format!("type uses owned (Box type) pointers: {}", ty)).emit()
112+
});
111113
}
112114
}
113115
}
@@ -214,7 +216,12 @@ declare_lint! {
214216
declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]);
215217

216218
impl UnsafeCode {
217-
fn report_unsafe(&self, cx: &EarlyContext<'_>, span: Span, decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)) {
219+
fn report_unsafe(
220+
&self,
221+
cx: &EarlyContext<'_>,
222+
span: Span,
223+
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
224+
) {
218225
// This comes from a macro that has `#[allow_internal_unsafe]`.
219226
if span.allows_unsafe() {
220227
return;
@@ -227,33 +234,40 @@ impl UnsafeCode {
227234
impl EarlyLintPass for UnsafeCode {
228235
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
229236
if attr.check_name(sym::allow_internal_unsafe) {
230-
self.report_unsafe(
231-
cx,
232-
attr.span,
233-
|lint| lint.build("`allow_internal_unsafe` allows defining \
237+
self.report_unsafe(cx, attr.span, |lint| {
238+
lint.build(
239+
"`allow_internal_unsafe` allows defining \
234240
macros using unsafe without triggering \
235-
the `unsafe_code` lint at their call site").emit(),
236-
);
241+
the `unsafe_code` lint at their call site",
242+
)
243+
.emit()
244+
});
237245
}
238246
}
239247

240248
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
241249
if let ast::ExprKind::Block(ref blk, _) = e.kind {
242250
// Don't warn about generated blocks; that'll just pollute the output.
243251
if blk.rules == ast::BlockCheckMode::Unsafe(ast::UserProvided) {
244-
self.report_unsafe(cx, blk.span, |lint| lint.build("usage of an `unsafe` block").emit());
252+
self.report_unsafe(cx, blk.span, |lint| {
253+
lint.build("usage of an `unsafe` block").emit()
254+
});
245255
}
246256
}
247257
}
248258

249259
fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) {
250260
match it.kind {
251261
ast::ItemKind::Trait(_, ast::Unsafety::Unsafe, ..) => {
252-
self.report_unsafe(cx, it.span, |lint| lint.build("declaration of an `unsafe` trait").emit())
262+
self.report_unsafe(cx, it.span, |lint| {
263+
lint.build("declaration of an `unsafe` trait").emit()
264+
})
253265
}
254266

255267
ast::ItemKind::Impl { unsafety: ast::Unsafety::Unsafe, .. } => {
256-
self.report_unsafe(cx, it.span, |lint| lint.build("implementation of an `unsafe` trait").emit())
268+
self.report_unsafe(cx, it.span, |lint| {
269+
lint.build("implementation of an `unsafe` trait").emit()
270+
})
257271
}
258272

259273
_ => return,
@@ -269,13 +283,16 @@ impl EarlyLintPass for UnsafeCode {
269283
_: ast::NodeId,
270284
) {
271285
match fk {
272-
FnKind::ItemFn(_, ast::FnHeader { unsafety: ast::Unsafety::Unsafe, .. }, ..) => {
273-
self.report_unsafe(cx, span, |lint| lint.build("declaration of an `unsafe` function").emit())
274-
}
286+
FnKind::ItemFn(_, ast::FnHeader { unsafety: ast::Unsafety::Unsafe, .. }, ..) => self
287+
.report_unsafe(cx, span, |lint| {
288+
lint.build("declaration of an `unsafe` function").emit()
289+
}),
275290

276291
FnKind::Method(_, sig, ..) => {
277292
if sig.header.unsafety == ast::Unsafety::Unsafe {
278-
self.report_unsafe(cx, span, |lint| lint.build("implementation of an `unsafe` method").emit())
293+
self.report_unsafe(cx, span, |lint| {
294+
lint.build("implementation of an `unsafe` method").emit()
295+
})
279296
}
280297
}
281298

@@ -286,7 +303,9 @@ impl EarlyLintPass for UnsafeCode {
286303
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &ast::AssocItem) {
287304
if let ast::AssocItemKind::Fn(ref sig, None) = item.kind {
288305
if sig.header.unsafety == ast::Unsafety::Unsafe {
289-
self.report_unsafe(cx, item.span, |lint| lint.build("declaration of an `unsafe` method").emit())
306+
self.report_unsafe(cx, item.span, |lint| {
307+
lint.build("declaration of an `unsafe` method").emit()
308+
})
290309
}
291310
}
292311
}
@@ -372,11 +391,9 @@ impl MissingDoc {
372391

373392
let has_doc = attrs.iter().any(|a| has_doc(a));
374393
if !has_doc {
375-
cx.struct_span_lint(
376-
MISSING_DOCS,
377-
cx.tcx.sess.source_map().def_span(sp),
378-
|lint| lint.build(&format!("missing documentation for {}", desc)).emit(),
379-
);
394+
cx.struct_span_lint(MISSING_DOCS, cx.tcx.sess.source_map().def_span(sp), |lint| {
395+
lint.build(&format!("missing documentation for {}", desc)).emit()
396+
});
380397
}
381398
}
382399
}
@@ -555,12 +572,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
555572
return;
556573
}
557574
if can_type_implement_copy(cx.tcx, param_env, ty).is_ok() {
558-
cx.struct_span_lint(
559-
MISSING_COPY_IMPLEMENTATIONS,
560-
item.span,
561-
|lint| lint.build("type could implement `Copy`; consider adding `impl \
562-
Copy`").emit(),
563-
)
575+
cx.struct_span_lint(MISSING_COPY_IMPLEMENTATIONS, item.span, |lint| {
576+
lint.build(
577+
"type could implement `Copy`; consider adding `impl \
578+
Copy`",
579+
)
580+
.emit()
581+
})
564582
}
565583
}
566584
}
@@ -609,12 +627,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
609627
}
610628

611629
if !self.impling_types.as_ref().unwrap().contains(&item.hir_id) {
612-
cx.struct_span_lint(
613-
MISSING_DEBUG_IMPLEMENTATIONS,
614-
item.span,
615-
|lint| lint.build("type does not implement `fmt::Debug`; consider adding `#[derive(Debug)]` \
616-
or a manual implementation").emit(),
617-
)
630+
cx.struct_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, |lint| {
631+
lint.build(
632+
"type does not implement `fmt::Debug`; consider adding `#[derive(Debug)]` \
633+
or a manual implementation",
634+
)
635+
.emit()
636+
})
618637
}
619638
}
620639
}
@@ -912,7 +931,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
912931
match get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (&ty1.kind, &ty2.kind)) {
913932
Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) => {
914933
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
915-
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| lint.build(msg).emit());
934+
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| {
935+
lint.build(msg).emit()
936+
});
916937
}
917938
}
918939
_ => (),
@@ -962,7 +983,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
962983
if attr.check_name(sym::feature) {
963984
if let Some(items) = attr.meta_item_list() {
964985
for item in items {
965-
ctx.struct_span_lint(UNSTABLE_FEATURES, item.span(), |lint| lint.build("unstable feature").emit());
986+
ctx.struct_span_lint(UNSTABLE_FEATURES, item.span(), |lint| {
987+
lint.build("unstable feature").emit()
988+
});
966989
}
967990
}
968991
}
@@ -1244,15 +1267,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12441267
ConstEvaluatable(..) => continue,
12451268
};
12461269
if predicate.is_global() {
1247-
cx.struct_span_lint(
1248-
TRIVIAL_BOUNDS,
1249-
span,
1250-
|lint| lint.build(&format!(
1270+
cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| {
1271+
lint.build(&format!(
12511272
"{} bound {} does not depend on any type \
12521273
or lifetime parameters",
12531274
predicate_kind_name, predicate
1254-
)).emit(),
1255-
);
1275+
))
1276+
.emit()
1277+
});
12561278
}
12571279
}
12581280
}

src/librustc_lint/early.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ struct EarlyContextAndPass<'a, T: EarlyLintPass> {
3737
impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
3838
fn check_id(&mut self, id: ast::NodeId) {
3939
for early_lint in self.context.buffered.take(id) {
40-
let rustc_session::lint::BufferedEarlyLint { span, msg, node_id: _, lint_id: _, diagnostic } = early_lint;
40+
let rustc_session::lint::BufferedEarlyLint {
41+
span,
42+
msg,
43+
node_id: _,
44+
lint_id: _,
45+
diagnostic,
46+
} = early_lint;
4147
self.context.lookup_with_diagnostics(
4248
early_lint.lint_id.lint,
4349
Some(span),

src/librustc_lint/types.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,9 @@ fn lint_int_literal<'a, 'tcx>(
266266
}
267267
}
268268

269-
cx.struct_span_lint(
270-
OVERFLOWING_LITERALS,
271-
e.span,
272-
|lint| lint.build(&format!("literal out of range for `{}`", t.name_str())).emit(),
273-
);
269+
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
270+
lint.build(&format!("literal out of range for `{}`", t.name_str())).emit()
271+
});
274272
}
275273
}
276274

@@ -321,11 +319,9 @@ fn lint_uint_literal<'a, 'tcx>(
321319
report_bin_hex_error(cx, e, attr::IntType::UnsignedInt(t), repr_str, lit_val, false);
322320
return;
323321
}
324-
cx.struct_span_lint(
325-
OVERFLOWING_LITERALS,
326-
e.span,
327-
|lint| lint.build(&format!("literal out of range for `{}`", t.name_str())).emit(),
328-
);
322+
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
323+
lint.build(&format!("literal out of range for `{}`", t.name_str())).emit()
324+
});
329325
}
330326
}
331327

@@ -355,11 +351,9 @@ fn lint_literal<'a, 'tcx>(
355351
_ => bug!(),
356352
};
357353
if is_infinite == Ok(true) {
358-
cx.struct_span_lint(
359-
OVERFLOWING_LITERALS,
360-
e.span,
361-
|lint| lint.build(&format!("literal out of range for `{}`", t.name_str())).emit(),
362-
);
354+
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
355+
lint.build(&format!("literal out of range for `{}`", t.name_str())).emit()
356+
});
363357
}
364358
}
365359
_ => {}
@@ -377,11 +371,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
377371
}
378372
hir::ExprKind::Binary(binop, ref l, ref r) => {
379373
if is_comparison(binop) && !check_limits(cx, binop, &l, &r) {
380-
cx.struct_span_lint(
381-
UNUSED_COMPARISONS,
382-
e.span,
383-
|lint| lint.build("comparison is useless due to type limits").emit(),
384-
);
374+
cx.struct_span_lint(UNUSED_COMPARISONS, e.span, |lint| {
375+
lint.build("comparison is useless due to type limits").emit()
376+
});
385377
}
386378
}
387379
hir::ExprKind::Lit(ref lit) => lint_literal(cx, self, e, lit),
@@ -1058,11 +1050,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
10581050
cx.struct_span_lint(
10591051
VARIANT_SIZE_DIFFERENCES,
10601052
enum_definition.variants[largest_index].span,
1061-
|lint| lint.build(&format!(
1062-
"enum variant is more than three times \
1053+
|lint| {
1054+
lint.build(&format!(
1055+
"enum variant is more than three times \
10631056
larger ({} bytes) than the next largest",
1064-
largest
1065-
)).emit(),
1057+
largest
1058+
))
1059+
.emit()
1060+
},
10661061
);
10671062
}
10681063
}

src/librustc_lint/unused.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
104104
};
105105

106106
if let Some(must_use_op) = must_use_op {
107-
cx.struct_span_lint(
108-
UNUSED_MUST_USE,
109-
expr.span,
110-
|lint| lint.build(&format!("unused {} that must be used", must_use_op)).emit(),
111-
);
107+
cx.struct_span_lint(UNUSED_MUST_USE, expr.span, |lint| {
108+
lint.build(&format!("unused {} that must be used", must_use_op)).emit()
109+
});
112110
op_warned = true;
113111
}
114112

@@ -247,7 +245,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements {
247245
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt<'_>) {
248246
if let hir::StmtKind::Semi(ref expr) = s.kind {
249247
if let hir::ExprKind::Path(_) = expr.kind {
250-
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| lint.build("path statement with no effect").emit());
248+
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| {
249+
lint.build("path statement with no effect").emit()
250+
});
251251
}
252252
}
253253
}
@@ -288,7 +288,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
288288

289289
if !attr::is_used(attr) {
290290
debug!("emitting warning for: {:?}", attr);
291-
cx.struct_span_lint(UNUSED_ATTRIBUTES, attr.span, |lint| lint.build("unused attribute").emit());
291+
cx.struct_span_lint(UNUSED_ATTRIBUTES, attr.span, |lint| {
292+
lint.build("unused attribute").emit()
293+
});
292294
// Is it a builtin attribute that must be used at the crate level?
293295
if attr_info.map_or(false, |(_, ty, ..)| ty == &AttributeType::CrateLevel) {
294296
cx.struct_span_lint(UNUSED_ATTRIBUTES, attr.span, |lint| {
@@ -629,9 +631,9 @@ impl UnusedImportBraces {
629631
ast::UseTreeKind::Nested(_) => return,
630632
};
631633

632-
cx.struct_span_lint(UNUSED_IMPORT_BRACES, item.span, |lint|
633-
lint.build(&format!("braces around {} is unnecessary", node_name)).emit()
634-
);
634+
cx.struct_span_lint(UNUSED_IMPORT_BRACES, item.span, |lint| {
635+
lint.build(&format!("braces around {} is unnecessary", node_name)).emit()
636+
});
635637
}
636638
}
637639
}

0 commit comments

Comments
 (0)