Skip to content

Commit 1bbbd5d

Browse files
Rollup merge of #33931 - srinivasreddy:lint_folder, r=GuillaumeGomez
run rustfmt on librustc_lint folder
2 parents df9dd98 + 68641d8 commit 1bbbd5d

File tree

5 files changed

+543
-400
lines changed

5 files changed

+543
-400
lines changed

src/librustc_lint/bad_style.rs

+97-69
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
use rustc::hir::def::Def;
1212
use rustc::ty;
13-
use lint::{LateContext, LintContext, LintArray};
14-
use lint::{LintPass, LateLintPass};
13+
use lint::{LateContext, LintArray, LintContext};
14+
use lint::{LateLintPass, LintPass};
1515

1616
use syntax::ast;
1717
use syntax::attr::{self, AttrMetaMethods};
@@ -24,19 +24,21 @@ use rustc::hir::intravisit::FnKind;
2424
pub enum MethodLateContext {
2525
TraitDefaultImpl,
2626
TraitImpl,
27-
PlainImpl
27+
PlainImpl,
2828
}
2929

3030
pub fn method_context(cx: &LateContext, id: ast::NodeId, span: Span) -> MethodLateContext {
3131
let def_id = cx.tcx.map.local_def_id(id);
3232
match cx.tcx.impl_or_trait_items.borrow().get(&def_id) {
3333
None => span_bug!(span, "missing method descriptor?!"),
34-
Some(item) => match item.container() {
35-
ty::TraitContainer(..) => MethodLateContext::TraitDefaultImpl,
36-
ty::ImplContainer(cid) => {
37-
match cx.tcx.impl_trait_ref(cid) {
38-
Some(_) => MethodLateContext::TraitImpl,
39-
None => MethodLateContext::PlainImpl
34+
Some(item) => {
35+
match item.container() {
36+
ty::TraitContainer(..) => MethodLateContext::TraitDefaultImpl,
37+
ty::ImplContainer(cid) => {
38+
match cx.tcx.impl_trait_ref(cid) {
39+
Some(_) => MethodLateContext::TraitImpl,
40+
None => MethodLateContext::PlainImpl,
41+
}
4042
}
4143
}
4244
}
@@ -63,29 +65,37 @@ impl NonCamelCaseTypes {
6365

6466
// start with a non-lowercase letter rather than non-uppercase
6567
// ones (some scripts don't have a concept of upper/lowercase)
66-
!name.is_empty() &&
67-
!name.chars().next().unwrap().is_lowercase() &&
68-
!name.contains('_')
68+
!name.is_empty() && !name.chars().next().unwrap().is_lowercase() && !name.contains('_')
6969
}
7070

7171
fn to_camel_case(s: &str) -> String {
72-
s.split('_').flat_map(|word| word.chars().enumerate().map(|(i, c)|
73-
if i == 0 {
74-
c.to_uppercase().collect::<String>()
75-
} else {
76-
c.to_lowercase().collect()
77-
}
78-
)).collect::<Vec<_>>().concat()
72+
s.split('_')
73+
.flat_map(|word| {
74+
word.chars().enumerate().map(|(i, c)| {
75+
if i == 0 {
76+
c.to_uppercase().collect::<String>()
77+
} else {
78+
c.to_lowercase().collect()
79+
}
80+
})
81+
})
82+
.collect::<Vec<_>>()
83+
.concat()
7984
}
8085

8186
let s = name.as_str();
8287

8388
if !is_camel_case(name) {
8489
let c = to_camel_case(&s);
8590
let m = if c.is_empty() {
86-
format!("{} `{}` should have a camel case name such as `CamelCase`", sort, s)
91+
format!("{} `{}` should have a camel case name such as `CamelCase`",
92+
sort,
93+
s)
8794
} else {
88-
format!("{} `{}` should have a camel case name such as `{}`", sort, s, c)
95+
format!("{} `{}` should have a camel case name such as `{}`",
96+
sort,
97+
s,
98+
c)
8999
};
90100
cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m[..]);
91101
}
@@ -100,23 +110,23 @@ impl LintPass for NonCamelCaseTypes {
100110

101111
impl LateLintPass for NonCamelCaseTypes {
102112
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
103-
let extern_repr_count = it.attrs.iter().filter(|attr| {
104-
attr::find_repr_attrs(cx.tcx.sess.diagnostic(), attr).iter()
105-
.any(|r| r == &attr::ReprExtern)
106-
}).count();
113+
let extern_repr_count = it.attrs
114+
.iter()
115+
.filter(|attr| {
116+
attr::find_repr_attrs(cx.tcx.sess.diagnostic(), attr)
117+
.iter()
118+
.any(|r| r == &attr::ReprExtern)
119+
})
120+
.count();
107121
let has_extern_repr = extern_repr_count > 0;
108122

109123
if has_extern_repr {
110124
return;
111125
}
112126

113127
match it.node {
114-
hir::ItemTy(..) | hir::ItemStruct(..) => {
115-
self.check_case(cx, "type", it.name, it.span)
116-
}
117-
hir::ItemTrait(..) => {
118-
self.check_case(cx, "trait", it.name, it.span)
119-
}
128+
hir::ItemTy(..) | hir::ItemStruct(..) => self.check_case(cx, "type", it.name, it.span),
129+
hir::ItemTrait(..) => self.check_case(cx, "trait", it.name, it.span),
120130
hir::ItemEnum(ref enum_definition, _) => {
121131
if has_extern_repr {
122132
return;
@@ -126,7 +136,7 @@ impl LateLintPass for NonCamelCaseTypes {
126136
self.check_case(cx, "variant", variant.node.name, variant.span);
127137
}
128138
}
129-
_ => ()
139+
_ => (),
130140
}
131141
}
132142

@@ -165,9 +175,7 @@ impl NonSnakeCase {
165175
continue;
166176
}
167177
for ch in s.chars() {
168-
if !buf.is_empty() && buf != "'"
169-
&& ch.is_uppercase()
170-
&& !last_upper {
178+
if !buf.is_empty() && buf != "'" && ch.is_uppercase() && !last_upper {
171179
words.push(buf);
172180
buf = String::new();
173181
}
@@ -205,10 +213,11 @@ impl NonSnakeCase {
205213
let sc = NonSnakeCase::to_snake_case(name);
206214
let msg = if sc != name {
207215
format!("{} `{}` should have a snake case name such as `{}`",
208-
sort, name, sc)
216+
sort,
217+
name,
218+
sc)
209219
} else {
210-
format!("{} `{}` should have a snake case name",
211-
sort, name)
220+
format!("{} `{}` should have a snake case name", sort, name)
212221
};
213222
match span {
214223
Some(span) => cx.span_lint(NON_SNAKE_CASE, span, &msg),
@@ -226,31 +235,39 @@ impl LintPass for NonSnakeCase {
226235

227236
impl LateLintPass for NonSnakeCase {
228237
fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) {
229-
let attr_crate_name = cr.attrs.iter().find(|at| at.check_name("crate_name"))
230-
.and_then(|at| at.value_str().map(|s| (at, s)));
238+
let attr_crate_name = cr.attrs
239+
.iter()
240+
.find(|at| at.check_name("crate_name"))
241+
.and_then(|at| at.value_str().map(|s| (at, s)));
231242
if let Some(ref name) = cx.tcx.sess.opts.crate_name {
232243
self.check_snake_case(cx, "crate", name, None);
233244
} else if let Some((attr, ref name)) = attr_crate_name {
234245
self.check_snake_case(cx, "crate", name, Some(attr.span));
235246
}
236247
}
237248

238-
fn check_fn(&mut self, cx: &LateContext,
239-
fk: FnKind, _: &hir::FnDecl,
240-
_: &hir::Block, span: Span, id: ast::NodeId) {
249+
fn check_fn(&mut self,
250+
cx: &LateContext,
251+
fk: FnKind,
252+
_: &hir::FnDecl,
253+
_: &hir::Block,
254+
span: Span,
255+
id: ast::NodeId) {
241256
match fk {
242-
FnKind::Method(name, _, _, _) => match method_context(cx, id, span) {
243-
MethodLateContext::PlainImpl => {
244-
self.check_snake_case(cx, "method", &name.as_str(), Some(span))
245-
},
246-
MethodLateContext::TraitDefaultImpl => {
247-
self.check_snake_case(cx, "trait method", &name.as_str(), Some(span))
248-
},
249-
_ => (),
250-
},
257+
FnKind::Method(name, _, _, _) => {
258+
match method_context(cx, id, span) {
259+
MethodLateContext::PlainImpl => {
260+
self.check_snake_case(cx, "method", &name.as_str(), Some(span))
261+
}
262+
MethodLateContext::TraitDefaultImpl => {
263+
self.check_snake_case(cx, "trait method", &name.as_str(), Some(span))
264+
}
265+
_ => (),
266+
}
267+
}
251268
FnKind::ItemFn(name, _, _, _, _, _, _) => {
252269
self.check_snake_case(cx, "function", &name.as_str(), Some(span))
253-
},
270+
}
254271
FnKind::Closure(_) => (),
255272
}
256273
}
@@ -263,13 +280,17 @@ impl LateLintPass for NonSnakeCase {
263280

264281
fn check_trait_item(&mut self, cx: &LateContext, trait_item: &hir::TraitItem) {
265282
if let hir::MethodTraitItem(_, None) = trait_item.node {
266-
self.check_snake_case(cx, "trait method", &trait_item.name.as_str(),
283+
self.check_snake_case(cx,
284+
"trait method",
285+
&trait_item.name.as_str(),
267286
Some(trait_item.span));
268287
}
269288
}
270289

271290
fn check_lifetime_def(&mut self, cx: &LateContext, t: &hir::LifetimeDef) {
272-
self.check_snake_case(cx, "lifetime", &t.lifetime.name.as_str(),
291+
self.check_snake_case(cx,
292+
"lifetime",
293+
&t.lifetime.name.as_str(),
273294
Some(t.lifetime.span));
274295
}
275296

@@ -282,8 +303,12 @@ impl LateLintPass for NonSnakeCase {
282303
}
283304
}
284305

285-
fn check_struct_def(&mut self, cx: &LateContext, s: &hir::VariantData,
286-
_: ast::Name, _: &hir::Generics, _: ast::NodeId) {
306+
fn check_struct_def(&mut self,
307+
cx: &LateContext,
308+
s: &hir::VariantData,
309+
_: ast::Name,
310+
_: &hir::Generics,
311+
_: ast::NodeId) {
287312
for sf in s.fields() {
288313
self.check_snake_case(cx, "structure field", &sf.name.as_str(), Some(sf.span));
289314
}
@@ -306,13 +331,16 @@ impl NonUpperCaseGlobals {
306331
if s.chars().any(|c| c.is_lowercase()) {
307332
let uc = NonSnakeCase::to_snake_case(&s).to_uppercase();
308333
if uc != &s[..] {
309-
cx.span_lint(NON_UPPER_CASE_GLOBALS, span,
310-
&format!("{} `{}` should have an upper case name such as `{}`",
311-
sort, s, uc));
334+
cx.span_lint(NON_UPPER_CASE_GLOBALS,
335+
span,
336+
&format!("{} `{}` should have an upper case name such as `{}`",
337+
sort,
338+
s,
339+
uc));
312340
} else {
313-
cx.span_lint(NON_UPPER_CASE_GLOBALS, span,
314-
&format!("{} `{}` should have an upper case name",
315-
sort, s));
341+
cx.span_lint(NON_UPPER_CASE_GLOBALS,
342+
span,
343+
&format!("{} `{}` should have an upper case name", sort, s));
316344
}
317345
}
318346
}
@@ -341,8 +369,7 @@ impl LateLintPass for NonUpperCaseGlobals {
341369
fn check_trait_item(&mut self, cx: &LateContext, ti: &hir::TraitItem) {
342370
match ti.node {
343371
hir::ConstTraitItem(..) => {
344-
NonUpperCaseGlobals::check_upper_case(cx, "associated constant",
345-
ti.name, ti.span);
372+
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ti.name, ti.span);
346373
}
347374
_ => {}
348375
}
@@ -351,8 +378,7 @@ impl LateLintPass for NonUpperCaseGlobals {
351378
fn check_impl_item(&mut self, cx: &LateContext, ii: &hir::ImplItem) {
352379
match ii.node {
353380
hir::ImplItemKind::Const(..) => {
354-
NonUpperCaseGlobals::check_upper_case(cx, "associated constant",
355-
ii.name, ii.span);
381+
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ii.name, ii.span);
356382
}
357383
_ => {}
358384
}
@@ -362,8 +388,10 @@ impl LateLintPass for NonUpperCaseGlobals {
362388
// Lint for constants that look like binding identifiers (#7526)
363389
match (&p.node, cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def())) {
364390
(&PatKind::Ident(_, ref path1, _), Some(Def::Const(..))) => {
365-
NonUpperCaseGlobals::check_upper_case(cx, "constant in pattern",
366-
path1.node, p.span);
391+
NonUpperCaseGlobals::check_upper_case(cx,
392+
"constant in pattern",
393+
path1.node,
394+
p.span);
367395
}
368396
_ => {}
369397
}

0 commit comments

Comments
 (0)