Skip to content

Commit 6474de9

Browse files
committed
make non_camel_case_types an early lint
1 parent ddab10a commit 6474de9

File tree

241 files changed

+885
-875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+885
-875
lines changed

src/librustc_lint/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
123123
UnusedDocComment,
124124
BadRepr,
125125
EllipsisInclusiveRangePatterns,
126+
NonCamelCaseTypes,
126127
);
127128

128129
add_early_builtin_with_new!(sess,
@@ -138,7 +139,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
138139
UnusedAttributes: UnusedAttributes,
139140
PathStatements: PathStatements,
140141
UnusedResults: UnusedResults,
141-
NonCamelCaseTypes: NonCamelCaseTypes,
142142
NonSnakeCase: NonSnakeCase,
143143
NonUpperCaseGlobals: NonUpperCaseGlobals,
144144
NonShorthandFieldPatterns: NonShorthandFieldPatterns,

src/librustc_lint/nonstandard_style.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use rustc::hir::def::Def;
1313
use rustc::hir::intravisit::FnKind;
1414
use rustc::ty;
1515
use rustc_target::spec::abi::Abi;
16-
use lint::{LateContext, LintContext, LintArray};
17-
use lint::{LintPass, LateLintPass};
16+
use lint::{EarlyContext, LateContext, LintContext, LintArray};
17+
use lint::{EarlyLintPass, LintPass, LateLintPass};
1818
use syntax::ast;
1919
use syntax::attr;
2020
use syntax_pos::Span;
@@ -50,7 +50,7 @@ declare_lint! {
5050
pub struct NonCamelCaseTypes;
5151

5252
impl NonCamelCaseTypes {
53-
fn check_case(&self, cx: &LateContext, sort: &str, name: ast::Name, span: Span) {
53+
fn check_case(&self, cx: &EarlyContext, sort: &str, name: ast::Name, span: Span) {
5454
fn char_has_case(c: char) -> bool {
5555
c.is_lowercase() || c.is_uppercase()
5656
}
@@ -114,12 +114,12 @@ impl LintPass for NonCamelCaseTypes {
114114
}
115115
}
116116

117-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
118-
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
117+
impl EarlyLintPass for NonCamelCaseTypes {
118+
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
119119
let has_repr_c = it.attrs
120120
.iter()
121121
.any(|attr| {
122-
attr::find_repr_attrs(&cx.tcx.sess.parse_sess, attr)
122+
attr::find_repr_attrs(&cx.sess.parse_sess, attr)
123123
.iter()
124124
.any(|r| r == &attr::ReprC)
125125
});
@@ -129,27 +129,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
129129
}
130130

131131
match it.node {
132-
hir::ItemKind::Ty(..) |
133-
hir::ItemKind::Enum(..) |
134-
hir::ItemKind::Struct(..) |
135-
hir::ItemKind::Union(..) => self.check_case(cx, "type", it.name, it.span),
136-
hir::ItemKind::Trait(..) => self.check_case(cx, "trait", it.name, it.span),
132+
ast::ItemKind::Ty(..) |
133+
ast::ItemKind::Enum(..) |
134+
ast::ItemKind::Struct(..) |
135+
ast::ItemKind::Union(..) => self.check_case(cx, "type", it.ident.name, it.span),
136+
ast::ItemKind::Trait(..) => self.check_case(cx, "trait", it.ident.name, it.span),
137137
_ => (),
138138
}
139139
}
140140

141-
fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) {
142-
self.check_case(cx, "variant", v.node.name, v.span);
141+
fn check_variant(&mut self, cx: &EarlyContext, v: &ast::Variant, _: &ast::Generics) {
142+
self.check_case(cx, "variant", v.node.ident.name, v.span);
143143
}
144144

145-
fn check_generic_param(&mut self, cx: &LateContext, param: &hir::GenericParam) {
146-
match param.kind {
147-
GenericParamKind::Lifetime { .. } => {}
148-
GenericParamKind::Type { synthetic, .. } => {
149-
if synthetic.is_none() {
150-
self.check_case(cx, "type parameter", param.name.ident().name, param.span);
151-
}
152-
}
145+
fn check_generic_param(&mut self, cx: &EarlyContext, param: &ast::GenericParam) {
146+
if let ast::GenericParamKind::Type { .. } = param.kind {
147+
self.check_case(cx, "type parameter", param.ident.name, param.ident.span);
153148
}
154149
}
155150
}

src/test/ui/access-mode-in-closures.nll.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0507]: cannot move out of borrowed content
2-
--> $DIR/access-mode-in-closures.rs:19:15
2+
--> $DIR/access-mode-in-closures.rs:18:15
33
|
4-
LL | match *s { sty(v) => v } //~ ERROR cannot move out
5-
| ^^ - data moved here
4+
LL | match *s { S(v) => v } //~ ERROR cannot move out
5+
| ^^ - data moved here
66
| |
77
| cannot move out of borrowed content
88
| help: consider removing the `*`: `s`
99
|
1010
note: move occurs because `v` has type `std::vec::Vec<isize>`, which does not implement the `Copy` trait
11-
--> $DIR/access-mode-in-closures.rs:19:24
11+
--> $DIR/access-mode-in-closures.rs:18:22
1212
|
13-
LL | match *s { sty(v) => v } //~ ERROR cannot move out
14-
| ^
13+
LL | match *s { S(v) => v } //~ ERROR cannot move out
14+
| ^
1515

1616
error: aborting due to previous error
1717

src/test/ui/access-mode-in-closures.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
struct S(Vec<isize>);
1112

12-
struct sty(Vec<isize> );
13-
14-
fn unpack<F>(_unpack: F) where F: FnOnce(&sty) -> Vec<isize> {}
13+
fn unpack<F>(_unpack: F) where F: FnOnce(&S) -> Vec<isize> {}
1514

1615
fn main() {
1716
let _foo = unpack(|s| {
1817
// Test that `s` is moved here.
19-
match *s { sty(v) => v } //~ ERROR cannot move out
18+
match *s { S(v) => v } //~ ERROR cannot move out
2019
});
2120
}

src/test/ui/access-mode-in-closures.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0507]: cannot move out of borrowed content
2-
--> $DIR/access-mode-in-closures.rs:19:15
2+
--> $DIR/access-mode-in-closures.rs:18:15
33
|
4-
LL | match *s { sty(v) => v } //~ ERROR cannot move out
5-
| ^^ - hint: to prevent move, use `ref v` or `ref mut v`
4+
LL | match *s { S(v) => v } //~ ERROR cannot move out
5+
| ^^ - hint: to prevent move, use `ref v` or `ref mut v`
66
| |
77
| cannot move out of borrowed content
88

src/test/ui/assign-to-method.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
struct cat {
11+
struct Cat {
1212
meows : usize,
1313

1414
how_hungry : isize,
1515
}
1616

17-
impl cat {
17+
impl Cat {
1818
pub fn speak(&self) { self.meows += 1; }
1919
}
2020

21-
fn cat(in_x : usize, in_y : isize) -> cat {
22-
cat {
21+
fn cat(in_x : usize, in_y : isize) -> Cat {
22+
Cat {
2323
meows: in_x,
2424
how_hungry: in_y
2525
}
2626
}
2727

2828
fn main() {
29-
let nyan : cat = cat(52, 99);
29+
let nyan : Cat = cat(52, 99);
3030
nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method
3131
}

src/test/ui/assign-to-method.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0615]: attempted to take value of method `speak` on type `cat`
1+
error[E0615]: attempted to take value of method `speak` on type `Cat`
22
--> $DIR/assign-to-method.rs:30:8
33
|
44
LL | nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method

src/test/ui/autoderef-full-lval.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010

1111
#![feature(box_syntax)]
1212

13-
struct clam {
13+
struct Clam {
1414
x: Box<isize>,
1515
y: Box<isize>,
1616
}
1717

18-
struct fish {
18+
struct Fish {
1919
a: Box<isize>,
2020
}
2121

2222
fn main() {
23-
let a: clam = clam{x: box 1, y: box 2};
24-
let b: clam = clam{x: box 10, y: box 20};
23+
let a: Clam = Clam{x: box 1, y: box 2};
24+
let b: Clam = Clam{x: box 10, y: box 20};
2525
let z: isize = a.x + b.y;
2626
//~^ ERROR binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
2727
println!("{}", z);
2828
assert_eq!(z, 21);
29-
let forty: fish = fish{a: box 40};
30-
let two: fish = fish{a: box 2};
29+
let forty: Fish = Fish{a: box 40};
30+
let two: Fish = Fish{a: box 2};
3131
let answer: isize = forty.a + two.a;
3232
//~^ ERROR binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
3333
println!("{}", answer);

src/test/ui/bad/bad-method-typaram-kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ fn foo<T:'static>() {
1212
1.bar::<T>(); //~ ERROR `T` cannot be sent between threads safely
1313
}
1414

15-
trait bar {
15+
trait Bar {
1616
fn bar<T:Send>(&self);
1717
}
1818

19-
impl bar for usize {
19+
impl Bar for usize {
2020
fn bar<T:Send>(&self) {
2121
}
2222
}

src/test/ui/bind-by-move/bind-by-move-neither-can-live-while-the-other-survives-3.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ impl Drop for X {
1616
}
1717
}
1818

19-
enum double_option<T,U> { some2(T,U), none2 }
19+
enum DoubleOption<T,U> { Some2(T,U), None2 }
2020

2121
fn main() {
22-
let x = double_option::some2(X { x: () }, X { x: () });
22+
let x = DoubleOption::Some2(X { x: () }, X { x: () });
2323
match x {
24-
double_option::some2(ref _y, _z) => { },
24+
DoubleOption::Some2(ref _y, _z) => { },
2525
//~^ ERROR cannot bind by-move and by-ref in the same pattern
26-
double_option::none2 => panic!()
26+
DoubleOption::None2 => panic!()
2727
}
2828
}

0 commit comments

Comments
 (0)