Skip to content

Commit

Permalink
make non_camel_case_types an early lint
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Dec 24, 2018
1 parent ddab10a commit 6474de9
Show file tree
Hide file tree
Showing 241 changed files with 885 additions and 875 deletions.
2 changes: 1 addition & 1 deletion src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UnusedDocComment,
BadRepr,
EllipsisInclusiveRangePatterns,
NonCamelCaseTypes,
);

add_early_builtin_with_new!(sess,
Expand All @@ -138,7 +139,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UnusedAttributes: UnusedAttributes,
PathStatements: PathStatements,
UnusedResults: UnusedResults,
NonCamelCaseTypes: NonCamelCaseTypes,
NonSnakeCase: NonSnakeCase,
NonUpperCaseGlobals: NonUpperCaseGlobals,
NonShorthandFieldPatterns: NonShorthandFieldPatterns,
Expand Down
37 changes: 16 additions & 21 deletions src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use rustc::hir::def::Def;
use rustc::hir::intravisit::FnKind;
use rustc::ty;
use rustc_target::spec::abi::Abi;
use lint::{LateContext, LintContext, LintArray};
use lint::{LintPass, LateLintPass};
use lint::{EarlyContext, LateContext, LintContext, LintArray};
use lint::{EarlyLintPass, LintPass, LateLintPass};
use syntax::ast;
use syntax::attr;
use syntax_pos::Span;
Expand Down Expand Up @@ -50,7 +50,7 @@ declare_lint! {
pub struct NonCamelCaseTypes;

impl NonCamelCaseTypes {
fn check_case(&self, cx: &LateContext, sort: &str, name: ast::Name, span: Span) {
fn check_case(&self, cx: &EarlyContext, sort: &str, name: ast::Name, span: Span) {
fn char_has_case(c: char) -> bool {
c.is_lowercase() || c.is_uppercase()
}
Expand Down Expand Up @@ -114,12 +114,12 @@ impl LintPass for NonCamelCaseTypes {
}
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
impl EarlyLintPass for NonCamelCaseTypes {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
let has_repr_c = it.attrs
.iter()
.any(|attr| {
attr::find_repr_attrs(&cx.tcx.sess.parse_sess, attr)
attr::find_repr_attrs(&cx.sess.parse_sess, attr)
.iter()
.any(|r| r == &attr::ReprC)
});
Expand All @@ -129,27 +129,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
}

match it.node {
hir::ItemKind::Ty(..) |
hir::ItemKind::Enum(..) |
hir::ItemKind::Struct(..) |
hir::ItemKind::Union(..) => self.check_case(cx, "type", it.name, it.span),
hir::ItemKind::Trait(..) => self.check_case(cx, "trait", it.name, it.span),
ast::ItemKind::Ty(..) |
ast::ItemKind::Enum(..) |
ast::ItemKind::Struct(..) |
ast::ItemKind::Union(..) => self.check_case(cx, "type", it.ident.name, it.span),
ast::ItemKind::Trait(..) => self.check_case(cx, "trait", it.ident.name, it.span),
_ => (),
}
}

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

fn check_generic_param(&mut self, cx: &LateContext, param: &hir::GenericParam) {
match param.kind {
GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { synthetic, .. } => {
if synthetic.is_none() {
self.check_case(cx, "type parameter", param.name.ident().name, param.span);
}
}
fn check_generic_param(&mut self, cx: &EarlyContext, param: &ast::GenericParam) {
if let ast::GenericParamKind::Type { .. } = param.kind {
self.check_case(cx, "type parameter", param.ident.name, param.ident.span);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/access-mode-in-closures.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0507]: cannot move out of borrowed content
--> $DIR/access-mode-in-closures.rs:19:15
--> $DIR/access-mode-in-closures.rs:18:15
|
LL | match *s { sty(v) => v } //~ ERROR cannot move out
| ^^ - data moved here
LL | match *s { S(v) => v } //~ ERROR cannot move out
| ^^ - data moved here
| |
| cannot move out of borrowed content
| help: consider removing the `*`: `s`
|
note: move occurs because `v` has type `std::vec::Vec<isize>`, which does not implement the `Copy` trait
--> $DIR/access-mode-in-closures.rs:19:24
--> $DIR/access-mode-in-closures.rs:18:22
|
LL | match *s { sty(v) => v } //~ ERROR cannot move out
| ^
LL | match *s { S(v) => v } //~ ERROR cannot move out
| ^

error: aborting due to previous error

Expand Down
7 changes: 3 additions & 4 deletions src/test/ui/access-mode-in-closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct S(Vec<isize>);

struct sty(Vec<isize> );

fn unpack<F>(_unpack: F) where F: FnOnce(&sty) -> Vec<isize> {}
fn unpack<F>(_unpack: F) where F: FnOnce(&S) -> Vec<isize> {}

fn main() {
let _foo = unpack(|s| {
// Test that `s` is moved here.
match *s { sty(v) => v } //~ ERROR cannot move out
match *s { S(v) => v } //~ ERROR cannot move out
});
}
6 changes: 3 additions & 3 deletions src/test/ui/access-mode-in-closures.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0507]: cannot move out of borrowed content
--> $DIR/access-mode-in-closures.rs:19:15
--> $DIR/access-mode-in-closures.rs:18:15
|
LL | match *s { sty(v) => v } //~ ERROR cannot move out
| ^^ - hint: to prevent move, use `ref v` or `ref mut v`
LL | match *s { S(v) => v } //~ ERROR cannot move out
| ^^ - hint: to prevent move, use `ref v` or `ref mut v`
| |
| cannot move out of borrowed content

Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/assign-to-method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct cat {
struct Cat {
meows : usize,

how_hungry : isize,
}

impl cat {
impl Cat {
pub fn speak(&self) { self.meows += 1; }
}

fn cat(in_x : usize, in_y : isize) -> cat {
cat {
fn cat(in_x : usize, in_y : isize) -> Cat {
Cat {
meows: in_x,
how_hungry: in_y
}
}

fn main() {
let nyan : cat = cat(52, 99);
let nyan : Cat = cat(52, 99);
nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method
}
2 changes: 1 addition & 1 deletion src/test/ui/assign-to-method.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0615]: attempted to take value of method `speak` on type `cat`
error[E0615]: attempted to take value of method `speak` on type `Cat`
--> $DIR/assign-to-method.rs:30:8
|
LL | nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/autoderef-full-lval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@

#![feature(box_syntax)]

struct clam {
struct Clam {
x: Box<isize>,
y: Box<isize>,
}

struct fish {
struct Fish {
a: Box<isize>,
}

fn main() {
let a: clam = clam{x: box 1, y: box 2};
let b: clam = clam{x: box 10, y: box 20};
let a: Clam = Clam{x: box 1, y: box 2};
let b: Clam = Clam{x: box 10, y: box 20};
let z: isize = a.x + b.y;
//~^ ERROR binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
println!("{}", z);
assert_eq!(z, 21);
let forty: fish = fish{a: box 40};
let two: fish = fish{a: box 2};
let forty: Fish = Fish{a: box 40};
let two: Fish = Fish{a: box 2};
let answer: isize = forty.a + two.a;
//~^ ERROR binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
println!("{}", answer);
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/bad/bad-method-typaram-kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ fn foo<T:'static>() {
1.bar::<T>(); //~ ERROR `T` cannot be sent between threads safely
}

trait bar {
trait Bar {
fn bar<T:Send>(&self);
}

impl bar for usize {
impl Bar for usize {
fn bar<T:Send>(&self) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ impl Drop for X {
}
}

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

fn main() {
let x = double_option::some2(X { x: () }, X { x: () });
let x = DoubleOption::Some2(X { x: () }, X { x: () });
match x {
double_option::some2(ref _y, _z) => { },
DoubleOption::Some2(ref _y, _z) => { },
//~^ ERROR cannot bind by-move and by-ref in the same pattern
double_option::none2 => panic!()
DoubleOption::None2 => panic!()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0009]: cannot bind by-move and by-ref in the same pattern
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-3.rs:24:38
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-3.rs:24:37
|
LL | double_option::some2(ref _y, _z) => { },
| ------ ^^ by-move pattern here
| |
| both by-ref and by-move used
LL | DoubleOption::Some2(ref _y, _z) => { },
| ------ ^^ by-move pattern here
| |
| both by-ref and by-move used

error: aborting due to previous error

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/blind/blind-item-block-middle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(non_camel_case_types)]

mod foo { pub struct bar; }

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/blind/blind-item-block-middle.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/blind-item-block-middle.rs:14:9
--> $DIR/blind-item-block-middle.rs:16:9
|
LL | let bar = 5;
| ^^^ expected integral variable, found struct `foo::bar`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/block-result/block-must-not-have-result-res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct r;
struct R;

impl Drop for r {
impl Drop for R {
fn drop(&mut self) {
true //~ ERROR mismatched types
}
Expand Down
9 changes: 4 additions & 5 deletions src/test/ui/bogus-tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.


enum color { rgb(isize, isize, isize), rgba(isize, isize, isize, isize), }
enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }

fn main() {
let red: color = color::rgb(255, 0, 0);
let red: Color = Color::Rgb(255, 0, 0);
match red {
color::rgb(r, g, b) => { println!("rgb"); }
color::hsl(h, s, l) => { println!("hsl"); }
Color::Rgb(r, g, b) => { println!("rgb"); }
Color::Hsl(h, s, l) => { println!("hsl"); }
//~^ ERROR no variant
}
}
12 changes: 6 additions & 6 deletions src/test/ui/bogus-tag.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0599]: no variant named `hsl` found for type `color` in the current scope
--> $DIR/bogus-tag.rs:18:7
error[E0599]: no variant named `Hsl` found for type `Color` in the current scope
--> $DIR/bogus-tag.rs:17:7
|
LL | enum color { rgb(isize, isize, isize), rgba(isize, isize, isize, isize), }
| ---------- variant `hsl` not found here
LL | enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
| ---------- variant `Hsl` not found here
...
LL | color::hsl(h, s, l) => { println!("hsl"); }
| ^^^^^^^^^^^^^^^^^^^ variant not found in `color`
LL | Color::Hsl(h, s, l) => { println!("hsl"); }
| ^^^^^^^^^^^^^^^^^^^ variant not found in `Color`

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-assign-comp.ast.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ error[E0506]: cannot assign to `p` because it is borrowed
|
LL | let q = &p.y;
| ---- borrow of `p` occurs here
LL | p = point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
LL | p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
...
LL | *q; // stretch loan
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-assign-comp.ast.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0506]: cannot assign to `p` because it is borrowed
|
LL | let q = &p.y;
| --- borrow of `p` occurs here
LL | p = point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
LL | p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here

error[E0506]: cannot assign to `p.y` because it is borrowed
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-assign-comp.mir.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ error[E0506]: cannot assign to `p` because it is borrowed
|
LL | let q = &p.y;
| ---- borrow of `p` occurs here
LL | p = point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
LL | p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
...
LL | *q; // stretch loan
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/borrowck/borrowck-assign-comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir

struct point { x: isize, y: isize }
struct Point { x: isize, y: isize }

fn a() {
let mut p = point {x: 3, y: 4};
let mut p = Point {x: 3, y: 4};
let q = &p;

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

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

let mut p = point {x: 3, y: 4};
let mut p = Point {x: 3, y: 4};
let q = &p.y;
p.y = 5; //[ast]~ ERROR cannot assign to `p.y`
//[mir]~^ ERROR cannot assign to `p.y` because it is borrowed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/borrowck-borrowed-uniq-rvalue-2.rs:32:20
--> $DIR/borrowck-borrowed-uniq-rvalue-2.rs:30:20
|
LL | let x = defer(&vec!["Goodbye", "world!"]);
LL | let x = defer(&vec!["Goodbye", "world!"]); //~ ERROR borrowed value does not live long enough
| ^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary which is freed while still in use
Expand Down
Loading

0 comments on commit 6474de9

Please sign in to comment.