Skip to content

Commit 14b9665

Browse files
committed
Auto merge of rust-lang#57088 - euclio:non-camel-case-early-lint, r=estebank
make non_camel_case_types an early lint This allows us to catch these kinds of style violations much earlier, as evidenced by the large number of tests that had to be updated for this change.
2 parents 27a25df + 6474de9 commit 14b9665

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
125125
UnusedDocComment,
126126
BadRepr,
127127
EllipsisInclusiveRangePatterns,
128+
NonCamelCaseTypes,
128129
);
129130

130131
add_early_builtin_with_new!(sess,
@@ -140,7 +141,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
140141
UnusedAttributes: UnusedAttributes,
141142
PathStatements: PathStatements,
142143
UnusedResults: UnusedResults,
143-
NonCamelCaseTypes: NonCamelCaseTypes,
144144
NonSnakeCase: NonSnakeCase,
145145
NonUpperCaseGlobals: NonUpperCaseGlobals,
146146
NonShorthandFieldPatterns: NonShorthandFieldPatterns,

src/librustc_lint/nonstandard_style.rs

+16-21
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

+6-6
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

+3-4
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

+3-3
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

+5-5
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

+1-1
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

+6-6
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

+2-2
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

+4-4
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
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0009]: cannot bind by-move and by-ref in the same pattern
2-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-3.rs:24:38
2+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-3.rs:24:37
33
|
4-
LL | double_option::some2(ref _y, _z) => { },
5-
| ------ ^^ by-move pattern here
6-
| |
7-
| both by-ref and by-move used
4+
LL | DoubleOption::Some2(ref _y, _z) => { },
5+
| ------ ^^ by-move pattern here
6+
| |
7+
| both by-ref and by-move used
88

99
error: aborting due to previous error
1010

src/test/ui/blind/blind-item-block-middle.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![allow(non_camel_case_types)]
12+
1113
mod foo { pub struct bar; }
1214

1315
fn main() {

src/test/ui/blind/blind-item-block-middle.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/blind-item-block-middle.rs:14:9
2+
--> $DIR/blind-item-block-middle.rs:16:9
33
|
44
LL | let bar = 5;
55
| ^^^ expected integral variable, found struct `foo::bar`

src/test/ui/block-result/block-must-not-have-result-res.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
struct r;
11+
struct R;
1212

13-
impl Drop for r {
13+
impl Drop for R {
1414
fn drop(&mut self) {
1515
true //~ ERROR mismatched types
1616
}

src/test/ui/bogus-tag.rs

+4-5
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-
12-
enum color { rgb(isize, isize, isize), rgba(isize, isize, isize, isize), }
11+
enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
1312

1413
fn main() {
15-
let red: color = color::rgb(255, 0, 0);
14+
let red: Color = Color::Rgb(255, 0, 0);
1615
match red {
17-
color::rgb(r, g, b) => { println!("rgb"); }
18-
color::hsl(h, s, l) => { println!("hsl"); }
16+
Color::Rgb(r, g, b) => { println!("rgb"); }
17+
Color::Hsl(h, s, l) => { println!("hsl"); }
1918
//~^ ERROR no variant
2019
}
2120
}

src/test/ui/bogus-tag.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0599]: no variant named `hsl` found for type `color` in the current scope
2-
--> $DIR/bogus-tag.rs:18:7
1+
error[E0599]: no variant named `Hsl` found for type `Color` in the current scope
2+
--> $DIR/bogus-tag.rs:17:7
33
|
4-
LL | enum color { rgb(isize, isize, isize), rgba(isize, isize, isize, isize), }
5-
| ---------- variant `hsl` not found here
4+
LL | enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
5+
| ---------- variant `Hsl` not found here
66
...
7-
LL | color::hsl(h, s, l) => { println!("hsl"); }
8-
| ^^^^^^^^^^^^^^^^^^^ variant not found in `color`
7+
LL | Color::Hsl(h, s, l) => { println!("hsl"); }
8+
| ^^^^^^^^^^^^^^^^^^^ variant not found in `Color`
99

1010
error: aborting due to previous error
1111

src/test/ui/borrowck/borrowck-assign-comp.ast.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error[E0506]: cannot assign to `p` because it is borrowed
1515
|
1616
LL | let q = &p.y;
1717
| ---- borrow of `p` occurs here
18-
LL | p = point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
18+
LL | p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
1919
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
2020
...
2121
LL | *q; // stretch loan

src/test/ui/borrowck/borrowck-assign-comp.ast.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0506]: cannot assign to `p` because it is borrowed
1212
|
1313
LL | let q = &p.y;
1414
| --- borrow of `p` occurs here
15-
LL | p = point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
15+
LL | p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
1616
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
1717

1818
error[E0506]: cannot assign to `p.y` because it is borrowed

src/test/ui/borrowck/borrowck-assign-comp.mir.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error[E0506]: cannot assign to `p` because it is borrowed
1515
|
1616
LL | let q = &p.y;
1717
| ---- borrow of `p` occurs here
18-
LL | p = point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
18+
LL | p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
1919
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
2020
...
2121
LL | *q; // stretch loan

src/test/ui/borrowck/borrowck-assign-comp.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// revisions: ast mir
1212
//[mir]compile-flags: -Z borrowck=mir
1313

14-
struct point { x: isize, y: isize }
14+
struct Point { x: isize, y: isize }
1515

1616
fn a() {
17-
let mut p = point {x: 3, y: 4};
17+
let mut p = Point {x: 3, y: 4};
1818
let q = &p;
1919

2020
// This assignment is illegal because the field x is not
@@ -29,9 +29,9 @@ fn c() {
2929
// this is sort of the opposite. We take a loan to the interior of `p`
3030
// and then try to overwrite `p` as a whole.
3131

32-
let mut p = point {x: 3, y: 4};
32+
let mut p = Point {x: 3, y: 4};
3333
let q = &p.y;
34-
p = point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
34+
p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
3535
//[mir]~^ ERROR cannot assign to `p` because it is borrowed
3636
p.x; // silence warning
3737
*q; // stretch loan
@@ -41,7 +41,7 @@ fn d() {
4141
// just for completeness's sake, the easy case, where we take the
4242
// address of a subcomponent and then modify that subcomponent:
4343

44-
let mut p = point {x: 3, y: 4};
44+
let mut p = Point {x: 3, y: 4};
4545
let q = &p.y;
4646
p.y = 5; //[ast]~ ERROR cannot assign to `p.y`
4747
//[mir]~^ ERROR cannot assign to `p.y` because it is borrowed

src/test/ui/borrowck/borrowck-borrowed-uniq-rvalue-2.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/borrowck-borrowed-uniq-rvalue-2.rs:32:20
2+
--> $DIR/borrowck-borrowed-uniq-rvalue-2.rs:30:20
33
|
4-
LL | let x = defer(&vec!["Goodbye", "world!"]);
4+
LL | let x = defer(&vec!["Goodbye", "world!"]); //~ ERROR borrowed value does not live long enough
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
66
| |
77
| creates a temporary which is freed while still in use

0 commit comments

Comments
 (0)