From de7abd88244a9fe7033cb71e22af0601d1b811b9 Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 19 Jul 2014 00:45:17 +1200 Subject: [PATCH 1/2] Unify non-snake-case lints and non-uppercase statics lints This unifies the `non_snake_case_functions` and `uppercase_variables` lints into one lint, `non_snake_case`. It also now checks for non-snake-case modules. This also extends the non-camel-case types lint to check type parameters, and merges the `non_uppercase_pattern_statics` lint into the `non_uppercase_statics` lint. Because the `uppercase_variables` lint is now part of the `non_snake_case` lint, all non-snake-case variables that start with lowercase characters (such as `fooBar`) will now trigger the `non_snake_case` lint. New code should be updated to use the new `non_snake_case` lint instead of the previous `non_snake_case_functions` and `uppercase_variables` lints. All use of the `non_uppercase_pattern_statics` should be replaced with the `non_uppercase_statics` lint. Any code that previously contained non-snake-case module or variable names should be updated to use snake case names or disable the `non_snake_case` lint. Any code with non-camel-case type parameters should be changed to use camel case or disable the `non_camel_case_types` lint. [breaking-change] --- src/doc/guide-ffi.md | 2 +- src/etc/unicode.py | 2 +- src/libcollections/hash/mod.rs | 1 + src/libcore/char.rs | 2 +- src/libcore/fmt/mod.rs | 2 +- src/libcore/str.rs | 54 +++--- src/liblibc/lib.rs | 4 +- src/libnative/io/mod.rs | 2 +- src/libnative/io/process.rs | 2 +- src/libnum/bigint.rs | 1 + src/librbml/lib.rs | 2 +- src/libregex/test/bench.rs | 2 +- src/librustc/diagnostics.rs | 2 + src/librustc/lint/builtin.rs | 176 +++++++++--------- src/librustc/lint/context.rs | 4 +- src/librustc/middle/trans/build.rs | 2 +- src/librustc/middle/trans/cabi_arm.rs | 2 +- src/librustc/middle/trans/cabi_mips.rs | 2 +- src/librustc/middle/trans/cabi_x86_64.rs | 2 +- src/librustc/middle/trans/common.rs | 2 +- src/librustc/middle/trans/debuginfo.rs | 4 +- src/librustc/middle/trans/intrinsic.rs | 2 +- src/librustc/middle/trans/type_.rs | 2 +- src/librustc/middle/ty.rs | 1 + src/librustc/util/nodemap.rs | 2 + src/librustc_llvm/lib.rs | 4 +- src/librustdoc/flock.rs | 2 +- src/librustrt/libunwind.rs | 2 +- src/librustrt/mutex.rs | 2 +- src/librustrt/thread.rs | 2 +- src/librustrt/thread_local_storage.rs | 2 +- src/libserialize/json.rs | 2 +- src/libserialize/serialize.rs | 4 +- src/libstd/dynamic_lib.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/rand/os.rs | 2 +- src/libstd/rt/backtrace.rs | 6 +- src/libsyntax/abi.rs | 2 +- src/libsyntax/ast.rs | 2 +- src/libterm/win.rs | 2 +- src/libunicode/tables.rs | 2 +- src/libunicode/u_char.rs | 8 +- src/test/bench/shootout-spectralnorm.rs | 2 +- src/test/bench/sudoku.rs | 2 +- .../compile-fail/lint-non-camel-case-types.rs | 2 + .../lint-non-snake-case-functions.rs | 2 +- .../lint-non-snake-case-lifetimes.rs | 18 ++ .../lint-non-snake-case-modules.rs | 20 ++ .../compile-fail/lint-uppercase-variables.rs | 10 +- .../compile-fail/match-static-const-lc.rs | 4 +- .../run-pass/match-static-const-rename.rs | 3 +- 51 files changed, 214 insertions(+), 176 deletions(-) create mode 100644 src/test/compile-fail/lint-non-snake-case-lifetimes.rs create mode 100644 src/test/compile-fail/lint-non-snake-case-modules.rs diff --git a/src/doc/guide-ffi.md b/src/doc/guide-ffi.md index 0ded9db3ad08b..294cae3a1f76b 100644 --- a/src/doc/guide-ffi.md +++ b/src/doc/guide-ffi.md @@ -477,7 +477,7 @@ extern crate libc; #[cfg(target_os = "win32", target_arch = "x86")] #[link(name = "kernel32")] -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] extern "stdcall" { fn SetEnvironmentVariableA(n: *const u8, v: *const u8) -> libc::c_int; } diff --git a/src/etc/unicode.py b/src/etc/unicode.py index 7663cd1e3466a..a74bb74897135 100755 --- a/src/etc/unicode.py +++ b/src/etc/unicode.py @@ -34,7 +34,7 @@ // NOTE: The following code was generated by "src/etc/unicode.py", do not edit directly -#![allow(missing_doc, non_uppercase_statics, non_snake_case_functions)] +#![allow(missing_doc, non_uppercase_statics, non_snake_case)] ''' # Mapping taken from Table 12 from: diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index 8d20208515cbc..a264acf5d03a3 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -159,6 +159,7 @@ macro_rules! impl_hash_tuple( impl),*> Hash for ($($name,)*) { #[allow(uppercase_variables)] #[inline] + #[allow(non_snake_case)] fn hash(&self, state: &mut S) { match *self { ($(ref $name,)*) => { diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 4e9a72c6af544..95267a8f9e5fa 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -12,7 +12,7 @@ //! //! For more details, see ::unicode::char (a.k.a. std::char) -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] #![doc(primitive = "char")] use mem::transmute; diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index f7ff92f5ce39b..32663e5eb0fe2 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -668,7 +668,7 @@ macro_rules! tuple ( () => (); ( $($name:ident,)+ ) => ( impl<$($name:Show),*> Show for ($($name,)*) { - #[allow(uppercase_variables, dead_assignment)] + #[allow(non_snake_case, dead_assignment)] fn fmt(&self, f: &mut Formatter) -> Result { try!(write!(f, "(")); let ($(ref $name,)*) = *self; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 5cbeda94d0f86..b067e6299ee2e 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -394,9 +394,9 @@ impl NaiveSearcher { fn next(&mut self, haystack: &[u8], needle: &[u8]) -> Option<(uint, uint)> { while self.position + needle.len() <= haystack.len() { if haystack.slice(self.position, self.position + needle.len()) == needle { - let matchPos = self.position; + let match_pos = self.position; self.position += needle.len(); // add 1 for all matches - return Some((matchPos, matchPos + needle.len())); + return Some((match_pos, match_pos + needle.len())); } else { self.position += 1; } @@ -410,7 +410,7 @@ impl NaiveSearcher { #[deriving(Clone)] struct TwoWaySearcher { // constants - critPos: uint, + crit_pos: uint, period: uint, byteset: u64, @@ -423,32 +423,31 @@ struct TwoWaySearcher { // Crochemore, M., Perrin, D., 1991, Two-way string-matching, Journal of the ACM 38(3):651-675. impl TwoWaySearcher { fn new(needle: &[u8]) -> TwoWaySearcher { - let (critPos1, period1) = TwoWaySearcher::maximal_suffix(needle, false); - let (critPos2, period2) = TwoWaySearcher::maximal_suffix(needle, true); + let (crit_pos1, period1) = TwoWaySearcher::maximal_suffix(needle, false); + let (crit_pos2, period2) = TwoWaySearcher::maximal_suffix(needle, true); - let critPos; + let crit_pos; let period; - if critPos1 > critPos2 { - critPos = critPos1; + if crit_pos1 > crit_pos2 { + crit_pos = crit_pos1; period = period1; } else { - critPos = critPos2; + crit_pos = crit_pos2; period = period2; } let byteset = needle.iter() .fold(0, |a, &b| (1 << ((b & 0x3f) as uint)) | a); - - // The logic here (calculating critPos and period, the final if statement to see which + // The logic here (calculating crit_pos and period, the final if statement to see which // period to use for the TwoWaySearcher) is essentially an implementation of the // "small-period" function from the paper (p. 670) // - // In the paper they check whether `needle.slice_to(critPos)` is a suffix of - // `needle.slice(critPos, critPos + period)`, which is precisely what this does - if needle.slice_to(critPos) == needle.slice(period, period + critPos) { + // In the paper they check whether `needle.slice_to(crit_pos)` is a suffix of + // `needle.slice(crit_pos, crit_pos + period)`, which is precisely what this does + if needle.slice_to(crit_pos) == needle.slice(period, period + crit_pos) { TwoWaySearcher { - critPos: critPos, + crit_pos: crit_pos, period: period, byteset: byteset, @@ -457,8 +456,8 @@ impl TwoWaySearcher { } } else { TwoWaySearcher { - critPos: critPos, - period: cmp::max(critPos, needle.len() - critPos) + 1, + crit_pos: crit_pos, + period: cmp::max(crit_pos, needle.len() - crit_pos) + 1, byteset: byteset, position: 0, @@ -468,7 +467,7 @@ impl TwoWaySearcher { } #[inline] - fn next(&mut self, haystack: &[u8], needle: &[u8], longPeriod: bool) -> Option<(uint, uint)> { + fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool) -> Option<(uint, uint)> { 'search: loop { // Check that we have room to search in if self.position + needle.len() > haystack.len() { @@ -484,11 +483,12 @@ impl TwoWaySearcher { } // See if the right part of the needle matches - let start = if longPeriod { self.critPos } else { cmp::max(self.critPos, self.memory) }; + let start = if long_period { self.crit_pos } + else { cmp::max(self.crit_pos, self.memory) }; for i in range(start, needle.len()) { if needle[i] != haystack[self.position + i] { - self.position += i - self.critPos + 1; - if !longPeriod { + self.position += i - self.crit_pos + 1; + if !long_period { self.memory = 0; } continue 'search; @@ -496,11 +496,11 @@ impl TwoWaySearcher { } // See if the left part of the needle matches - let start = if longPeriod { 0 } else { self.memory }; - for i in range(start, self.critPos).rev() { + let start = if long_period { 0 } else { self.memory }; + for i in range(start, self.crit_pos).rev() { if needle[i] != haystack[self.position + i] { self.position += self.period; - if !longPeriod { + if !long_period { self.memory = needle.len() - self.period; } continue 'search; @@ -508,12 +508,12 @@ impl TwoWaySearcher { } // We have found a match! - let matchPos = self.position; + let match_pos = self.position; self.position += needle.len(); // add self.period for all matches - if !longPeriod { + if !long_period { self.memory = 0; // set to needle.len() - self.period for all matches } - return Some((matchPos, matchPos + needle.len())); + return Some((match_pos, match_pos + needle.len())); } } diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 949dd08eaa343..b8a7ac019c35c 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -74,10 +74,10 @@ */ #![allow(non_camel_case_types)] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] #![allow(non_uppercase_statics)] #![allow(missing_doc)] -#![allow(uppercase_variables)] +#![allow(non_snake_case)] #[cfg(test)] extern crate std; #[cfg(test)] extern crate test; diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs index 2dc6539b17806..276194feaf0e3 100644 --- a/src/libnative/io/mod.rs +++ b/src/libnative/io/mod.rs @@ -21,7 +21,7 @@ //! play. The only dependencies of these modules are the normal system libraries //! that you would find on the respective platform. -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] use libc::c_int; use libc; diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index b8ec0cd549611..0cc7158bb5d32 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -838,7 +838,7 @@ fn free_handle(_handle: *mut ()) { #[cfg(unix)] fn translate_status(status: c_int) -> rtio::ProcessExit { - #![allow(non_snake_case_functions)] + #![allow(non_snake_case)] #[cfg(target_os = "linux")] #[cfg(target_os = "android")] mod imp { diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index ba45d2b2e73ff..68cfe061121ea 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -78,6 +78,7 @@ pub type DoubleBigDigit = u64; pub static ZERO_BIG_DIGIT: BigDigit = 0; static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT]; +#[allow(non_snake_case)] pub mod BigDigit { use super::BigDigit; use super::DoubleBigDigit; diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index a05c877a6a6e1..aaa1cb85d8566 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -1132,7 +1132,7 @@ mod tests { #[cfg(test)] mod bench { - #![allow(non_snake_case_functions)] + #![allow(non_snake_case)] use test::Bencher; use super::reader; diff --git a/src/libregex/test/bench.rs b/src/libregex/test/bench.rs index 4bd9d1a8666c0..aa85a68b5b509 100644 --- a/src/libregex/test/bench.rs +++ b/src/libregex/test/bench.rs @@ -7,7 +7,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] use std::rand::{Rng, task_rng}; use stdtest::Bencher; diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 77e73c46c402c..0c9260bdc7d99 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(non_snake_case)] + register_diagnostic!(E0001, r##" This error suggests that the expression arm corresponding to the noted pattern will never be reached as for all possible values of the expression being matched, diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 01fea98dfa076..71e966d77867e 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -737,19 +737,15 @@ impl LintPass for UnusedResult { } declare_lint!(NON_CAMEL_CASE_TYPES, Warn, - "types, variants and traits should have camel case names") + "types, variants, traits and type parameters should have camel case names") pub struct NonCamelCaseTypes; -impl LintPass for NonCamelCaseTypes { - fn get_lints(&self) -> LintArray { - lint_array!(NON_CAMEL_CASE_TYPES) - } - - fn check_item(&mut self, cx: &Context, it: &ast::Item) { +impl NonCamelCaseTypes { + fn check_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { fn is_camel_case(ident: ast::Ident) -> bool { let ident = token::get_ident(ident); - assert!(!ident.get().is_empty()); + if ident.get().is_empty() { return true; } let ident = ident.get().trim_chars('_'); // start with a non-lowercase letter rather than non-uppercase @@ -764,20 +760,26 @@ impl LintPass for NonCamelCaseTypes { )).collect() } - fn check_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span) { - let s = token::get_ident(ident); + let s = token::get_ident(ident); - if !is_camel_case(ident) { - let c = to_camel_case(s.get()); - let m = if c.is_empty() { - format!("{} `{}` should have a camel case name such as `CamelCase`", sort, s) - } else { - format!("{} `{}` should have a camel case name such as `{}`", sort, s, c) - }; - cx.span_lint(NON_CAMEL_CASE_TYPES, span, m.as_slice()); - } + if !is_camel_case(ident) { + let c = to_camel_case(s.get()); + let m = if c.is_empty() { + format!("{} `{}` should have a camel case name such as `CamelCase`", sort, s) + } else { + format!("{} `{}` should have a camel case name such as `{}`", sort, s, c) + }; + cx.span_lint(NON_CAMEL_CASE_TYPES, span, m.as_slice()); } + } +} + +impl LintPass for NonCamelCaseTypes { + fn get_lints(&self) -> LintArray { + lint_array!(NON_CAMEL_CASE_TYPES) + } + fn check_item(&mut self, cx: &Context, it: &ast::Item) { let has_extern_repr = it.attrs.iter().map(|attr| { attr::find_repr_attrs(cx.tcx.sess.diagnostic(), attr).iter() .any(|r| r == &attr::ReprExtern) @@ -786,21 +788,27 @@ impl LintPass for NonCamelCaseTypes { match it.node { ast::ItemTy(..) | ast::ItemStruct(..) => { - check_case(cx, "type", it.ident, it.span) + self.check_case(cx, "type", it.ident, it.span) } ast::ItemTrait(..) => { - check_case(cx, "trait", it.ident, it.span) + self.check_case(cx, "trait", it.ident, it.span) } ast::ItemEnum(ref enum_definition, _) => { if has_extern_repr { return } - check_case(cx, "type", it.ident, it.span); + self.check_case(cx, "type", it.ident, it.span); for variant in enum_definition.variants.iter() { - check_case(cx, "variant", variant.node.name, variant.span); + self.check_case(cx, "variant", variant.node.name, variant.span); } } _ => () } } + + fn check_generics(&mut self, cx: &Context, it: &ast::Generics) { + for gen in it.ty_params.iter() { + self.check_case(cx, "type parameter", gen.ident, gen.span); + } + } } #[deriving(PartialEq)] @@ -836,17 +844,18 @@ fn method_context(cx: &Context, m: &ast::Method) -> MethodContext { } } -declare_lint!(NON_SNAKE_CASE_FUNCTIONS, Warn, - "methods and functions should have snake case names") +declare_lint!(NON_SNAKE_CASE, Warn, + "methods, functions, lifetime parameters and modules should have snake case names") -pub struct NonSnakeCaseFunctions; +pub struct NonSnakeCase; -impl NonSnakeCaseFunctions { +impl NonSnakeCase { fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { fn is_snake_case(ident: ast::Ident) -> bool { let ident = token::get_ident(ident); - assert!(!ident.get().is_empty()); - let ident = ident.get().trim_chars('_'); + if ident.get().is_empty() { return true; } + let ident = ident.get().trim_left_chars('\''); + let ident = ident.trim_chars('_'); let mut allow_underscore = true; ident.chars().all(|c| { @@ -865,7 +874,7 @@ impl NonSnakeCaseFunctions { let mut buf = String::new(); if s.is_empty() { continue; } for ch in s.chars() { - if !buf.is_empty() && ch.is_uppercase() { + if !buf.is_empty() && buf.as_slice() != "'" && ch.is_uppercase() { words.push(buf); buf = String::new(); } @@ -879,16 +888,16 @@ impl NonSnakeCaseFunctions { let s = token::get_ident(ident); if !is_snake_case(ident) { - cx.span_lint(NON_SNAKE_CASE_FUNCTIONS, span, + cx.span_lint(NON_SNAKE_CASE, span, format!("{} `{}` should have a snake case name such as `{}`", sort, s, to_snake_case(s.get())).as_slice()); } } } -impl LintPass for NonSnakeCaseFunctions { +impl LintPass for NonSnakeCase { fn get_lints(&self) -> LintArray { - lint_array!(NON_SNAKE_CASE_FUNCTIONS) + lint_array!(NON_SNAKE_CASE) } fn check_fn(&mut self, cx: &Context, @@ -908,9 +917,49 @@ impl LintPass for NonSnakeCaseFunctions { } } + fn check_item(&mut self, cx: &Context, it: &ast::Item) { + match it.node { + ast::ItemMod(_) => { + self.check_snake_case(cx, "module", it.ident, it.span); + } + _ => {} + } + } + fn check_ty_method(&mut self, cx: &Context, t: &ast::TypeMethod) { self.check_snake_case(cx, "trait method", t.ident, t.span); } + + fn check_lifetime_decl(&mut self, cx: &Context, t: &ast::Lifetime) { + self.check_snake_case(cx, "lifetime", t.name.ident(), t.span); + } + + fn check_pat(&mut self, cx: &Context, p: &ast::Pat) { + match &p.node { + &ast::PatIdent(_, ref path1, _) => { + match cx.tcx.def_map.borrow().find(&p.id) { + Some(&def::DefLocal(_, _)) | Some(&def::DefBinding(_, _)) | + Some(&def::DefArg(_, _)) => { + self.check_snake_case(cx, "variable", path1.node, p.span); + } + _ => {} + } + } + _ => {} + } + } + + fn check_struct_def(&mut self, cx: &Context, s: &ast::StructDef, + _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { + for sf in s.fields.iter() { + match sf.node { + ast::StructField_ { kind: ast::NamedField(ident, _), .. } => { + self.check_snake_case(cx, "structure field", ident, sf.span); + } + _ => {} + } + } + } } declare_lint!(NON_UPPERCASE_STATICS, Allow, @@ -942,17 +991,6 @@ impl LintPass for NonUppercaseStatics { _ => {} } } -} - -declare_lint!(NON_UPPERCASE_PATTERN_STATICS, Warn, - "static constants in match patterns should be all caps") - -pub struct NonUppercasePatternStatics; - -impl LintPass for NonUppercasePatternStatics { - fn get_lints(&self) -> LintArray { - lint_array!(NON_UPPERCASE_PATTERN_STATICS) - } fn check_pat(&mut self, cx: &Context, p: &ast::Pat) { // Lint for constants that look like binding identifiers (#7526) @@ -960,7 +998,7 @@ impl LintPass for NonUppercasePatternStatics { (&ast::PatIdent(_, ref path1, _), Some(&def::DefStatic(_, false))) => { let s = token::get_ident(path1.node); if s.get().chars().any(|c| c.is_lowercase()) { - cx.span_lint(NON_UPPERCASE_PATTERN_STATICS, path1.span, + cx.span_lint(NON_UPPERCASE_STATICS, path1.span, format!("static constant in pattern `{}` should have an uppercase \ name such as `{}`", s.get(), s.get().chars().map(|c| c.to_uppercase()) @@ -972,54 +1010,6 @@ impl LintPass for NonUppercasePatternStatics { } } -declare_lint!(UPPERCASE_VARIABLES, Warn, - "variable and structure field names should start with a lowercase character") - -pub struct UppercaseVariables; - -impl LintPass for UppercaseVariables { - fn get_lints(&self) -> LintArray { - lint_array!(UPPERCASE_VARIABLES) - } - - fn check_pat(&mut self, cx: &Context, p: &ast::Pat) { - match &p.node { - &ast::PatIdent(_, ref path1, _) => { - match cx.tcx.def_map.borrow().find(&p.id) { - Some(&def::DefLocal(_, _)) | Some(&def::DefBinding(_, _)) | - Some(&def::DefArg(_, _)) => { - let s = token::get_ident(path1.node); - if s.get().len() > 0 && s.get().char_at(0).is_uppercase() { - cx.span_lint(UPPERCASE_VARIABLES, path1.span, - "variable names should start with \ - a lowercase character"); - } - } - _ => {} - } - } - _ => {} - } - } - - fn check_struct_def(&mut self, cx: &Context, s: &ast::StructDef, - _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { - for sf in s.fields.iter() { - match sf.node { - ast::StructField_ { kind: ast::NamedField(ident, _), .. } => { - let s = token::get_ident(ident); - if s.get().char_at(0).is_uppercase() { - cx.span_lint(UPPERCASE_VARIABLES, sf.span, - "structure field names should start with \ - a lowercase character"); - } - } - _ => {} - } - } - } -} - declare_lint!(UNNECESSARY_PARENS, Warn, "`if`, `match`, `while` and `return` do not need parentheses") diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 8952e565008e8..28e4e1a564ef9 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -146,10 +146,8 @@ impl LintStore { PathStatement, UnusedResult, NonCamelCaseTypes, - NonSnakeCaseFunctions, + NonSnakeCase, NonUppercaseStatics, - NonUppercasePatternStatics, - UppercaseVariables, UnnecessaryParens, UnusedUnsafe, UnsafeBlock, diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index d2ddf3ff69662..76059e8df4f8c 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(dead_code)] // FFI wrappers -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] use llvm; use llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect, AttrBuilder}; diff --git a/src/librustc/middle/trans/cabi_arm.rs b/src/librustc/middle/trans/cabi_arm.rs index 0e2bf2104fd55..ccfc79ac0c500 100644 --- a/src/librustc/middle/trans/cabi_arm.rs +++ b/src/librustc/middle/trans/cabi_arm.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_uppercase_pattern_statics)] +#![allow(non_uppercase_statics)] use llvm; use llvm::{Integer, Pointer, Float, Double, Struct, Array}; diff --git a/src/librustc/middle/trans/cabi_mips.rs b/src/librustc/middle/trans/cabi_mips.rs index ac4c56a1d1f11..77815285428fd 100644 --- a/src/librustc/middle/trans/cabi_mips.rs +++ b/src/librustc/middle/trans/cabi_mips.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_uppercase_pattern_statics)] +#![allow(non_uppercase_statics)] use libc::c_uint; use std::cmp; diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index 2ab4814fa0cc3..0d4cb637ae0cd 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -11,7 +11,7 @@ // The classification code for the x86_64 ABI is taken from the clay language // https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp -#![allow(non_uppercase_pattern_statics)] +#![allow(non_uppercase_statics)] use llvm; use llvm::{Integer, Pointer, Float, Double}; diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 05528d2b3d88e..d92364b257010 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_camel_case_types, non_snake_case_functions)] +#![allow(non_camel_case_types, non_snake_case)] //! Code that is useful in various trans modules. diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 26973910400ee..bd337c4b934af 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -1447,7 +1447,7 @@ fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool !cx.reachable.contains(&node_id) } -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray { return unsafe { llvm::LLVMDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) @@ -3107,7 +3107,7 @@ fn debug_context<'a>(cx: &'a CrateContext) -> &'a CrateDebugContext { } #[inline] -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] fn DIB(cx: &CrateContext) -> DIBuilderRef { cx.dbg_cx.get_ref().builder } diff --git a/src/librustc/middle/trans/intrinsic.rs b/src/librustc/middle/trans/intrinsic.rs index 7d8e4679ae302..3c61708fb7b83 100644 --- a/src/librustc/middle/trans/intrinsic.rs +++ b/src/librustc/middle/trans/intrinsic.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_uppercase_pattern_statics)] +#![allow(non_uppercase_statics)] use llvm; use llvm::{SequentiallyConsistent, Acquire, Release, Xchg, ValueRef}; diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 017d61137e4b0..7b98d65a3105b 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_uppercase_pattern_statics)] +#![allow(non_uppercase_statics)] use llvm; use llvm::{TypeRef, Bool, False, True, TypeKind, ValueRef}; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 6f2dd6e099235..051ddd572416e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2118,6 +2118,7 @@ pub struct TypeContents { macro_rules! def_type_content_sets( (mod $mname:ident { $($name:ident = $bits:expr),+ }) => { + #[allow(non_snake_case)] mod $mname { use middle::ty::TypeContents; $(pub static $name: TypeContents = TypeContents { bits: $bits };)+ diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index 34a2faa581c5e..a38ee84e95dfb 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -10,6 +10,8 @@ //! An efficient hash map for node IDs +#![allow(non_snake_case)] + use std::collections::{HashMap, HashSet}; use std::hash::{Hasher, Hash, Writer}; use syntax::ast; diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 522941cee8c9d..7d2d25097a8f8 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_uppercase_pattern_statics)] +#![allow(non_uppercase_statics)] #![allow(non_camel_case_types)] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] #![allow(dead_code)] #![crate_name = "rustc_llvm"] diff --git a/src/librustdoc/flock.rs b/src/librustdoc/flock.rs index cb8be9c899757..101f1c7460571 100644 --- a/src/librustdoc/flock.rs +++ b/src/librustdoc/flock.rs @@ -162,7 +162,7 @@ mod imp { static LOCKFILE_EXCLUSIVE_LOCK: libc::DWORD = 0x00000002; - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] extern "system" { fn LockFileEx(hFile: libc::HANDLE, dwFlags: libc::DWORD, diff --git a/src/librustrt/libunwind.rs b/src/librustrt/libunwind.rs index a43920d27a763..69df8a7fd66e3 100644 --- a/src/librustrt/libunwind.rs +++ b/src/librustrt/libunwind.rs @@ -11,7 +11,7 @@ //! Unwind library interface #![allow(non_camel_case_types)] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] #![allow(dead_code)] // these are just bindings use libc; diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index 08da9b8aad1b0..3aa798aa92a20 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -629,7 +629,7 @@ mod imp { libc::CloseHandle(block); } - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] extern "system" { fn CreateEventA(lpSecurityAttributes: LPSECURITY_ATTRIBUTES, bManualReset: BOOL, diff --git a/src/librustrt/thread.rs b/src/librustrt/thread.rs index 1f0b0c7c207bf..6d18ec4f9f5ad 100644 --- a/src/librustrt/thread.rs +++ b/src/librustrt/thread.rs @@ -198,7 +198,7 @@ mod imp { SwitchToThread(); } - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] extern "system" { fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, diff --git a/src/librustrt/thread_local_storage.rs b/src/librustrt/thread_local_storage.rs index b9b12686170c0..6078ed990e41d 100644 --- a/src/librustrt/thread_local_storage.rs +++ b/src/librustrt/thread_local_storage.rs @@ -83,7 +83,7 @@ pub unsafe fn destroy(key: Key) { } #[cfg(windows)] -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] extern "system" { fn TlsAlloc() -> DWORD; fn TlsFree(dwTlsIndex: DWORD) -> BOOL; diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index d70b6b4d57bb8..b37b4588af630 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2282,7 +2282,7 @@ macro_rules! tuple_impl { > ToJson for ( $( $tyvar ),* , ) { #[inline] - #[allow(uppercase_variables)] + #[allow(non_snake_case)] fn to_json(&self) -> Json { match *self { ($(ref $tyvar),*,) => List(vec![$($tyvar.to_json()),*]) diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index bbaac7a96e9ee..2cda00ad6c4af 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -481,7 +481,7 @@ macro_rules! tuple ( () => (); ( $($name:ident,)+ ) => ( impl,$($name:Decodable),*> Decodable for ($($name,)*) { - #[allow(uppercase_variables)] + #[allow(non_snake_case)] fn decode(d: &mut D) -> Result<($($name,)*), E> { d.read_tuple(|d, amt| { let mut i = 0; @@ -496,7 +496,7 @@ macro_rules! tuple ( } } impl,$($name:Encodable),*> Encodable for ($($name,)*) { - #[allow(uppercase_variables)] + #[allow(non_snake_case)] fn encode(&self, s: &mut S) -> Result<(), E> { let ($(ref $name,)*) = *self; let mut n = 0; diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 16c00d76c5465..eee3e81f5fc06 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -328,7 +328,7 @@ pub mod dl { FreeLibrary(handle as *mut libc::c_void); () } - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] extern "system" { fn SetLastError(error: libc::size_t); fn LoadLibraryW(name: *const libc::c_void) -> *mut libc::c_void; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index f452f8b23e7ba..ea278d55db956 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -29,7 +29,7 @@ #![experimental] #![allow(missing_doc)] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] use clone::Clone; use collections::{Collection, MutableSeq}; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 07ad08e1b3c03..95be3191bab49 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -161,7 +161,7 @@ mod imp { static CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000; static NTE_BAD_SIGNATURE: DWORD = 0x80090006; - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] extern "system" { fn CryptAcquireContextA(phProv: *mut HCRYPTPROV, pszContainer: LPCSTR, diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 58b3179a297ce..aadc9178e1a00 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -543,7 +543,7 @@ mod imp { /// iOS doesn't use all of them it but adding more /// platform-specific configs pollutes the code too much #[allow(non_camel_case_types)] - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] #[allow(dead_code)] mod uw { use libc; @@ -657,7 +657,7 @@ mod imp { /// copy of that function in my mingw install (maybe it was broken?). Instead, /// this takes the route of using StackWalk64 in order to walk the stack. #[cfg(windows)] -#[allow(dead_code, uppercase_variables)] +#[allow(dead_code, non_snake_case)] mod imp { use c_str::CString; use core_collections::Collection; @@ -674,7 +674,7 @@ mod imp { use str::StrSlice; use dynamic_lib::DynamicLibrary; - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] extern "system" { fn GetCurrentProcess() -> libc::HANDLE; fn GetCurrentThread() -> libc::HANDLE; diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 3280829f95835..6d9b8821bd890 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -157,7 +157,7 @@ impl fmt::Show for Os { } } -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] #[test] fn lookup_Rust() { let abi = lookup("Rust"); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d574a02fded22..8df6b65cd1654 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -29,7 +29,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder}; // FIXME(eddyb) #10676 use Rc in the future. pub type P = Gc; -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] /// Construct a P from a T value. pub fn P(value: T) -> P { box(GC) value diff --git a/src/libterm/win.rs b/src/libterm/win.rs index 64a61cc6b3bdc..cd61f9bb35ed1 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -27,7 +27,7 @@ pub struct WinConsole { background: color::Color, } -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] #[link(name = "kernel32")] extern "system" { fn SetConsoleTextAttribute(handle: libc::HANDLE, attr: libc::WORD) -> libc::BOOL; diff --git a/src/libunicode/tables.rs b/src/libunicode/tables.rs index d6010cd8d7bfb..135b267262cc6 100644 --- a/src/libunicode/tables.rs +++ b/src/libunicode/tables.rs @@ -10,7 +10,7 @@ // NOTE: The following code was generated by "src/etc/unicode.py", do not edit directly -#![allow(missing_doc, non_uppercase_statics, non_snake_case_functions)] +#![allow(missing_doc, non_uppercase_statics, non_snake_case)] fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool { use core::cmp::{Equal, Less, Greater}; diff --git a/src/libunicode/u_char.rs b/src/libunicode/u_char.rs index 0f75cf86c18da..91e7589b8caeb 100644 --- a/src/libunicode/u_char.rs +++ b/src/libunicode/u_char.rs @@ -33,7 +33,7 @@ pub fn is_alphabetic(c: char) -> bool { /// 'XID_Start' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to ID_Start but modified for closure under NFKx. -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) } /// Returns whether the specified `char` satisfies the 'XID_Continue' Unicode property @@ -41,7 +41,7 @@ pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) } /// 'XID_Continue' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) } /// @@ -174,7 +174,7 @@ pub trait UnicodeChar { /// 'XID_Start' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to ID_Start but modified for closure under NFKx. - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] fn is_XID_start(&self) -> bool; /// Returns whether the specified `char` satisfies the 'XID_Continue' @@ -183,7 +183,7 @@ pub trait UnicodeChar { /// 'XID_Continue' is a Unicode Derived Property specified in /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. - #[allow(non_snake_case_functions)] + #[allow(non_snake_case)] fn is_XID_continue(&self) -> bool; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 2cbbfdb23fe02..49c1233484476 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -11,7 +11,7 @@ // no-pretty-expanded FIXME #15189 #![feature(phase)] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] #[phase(plugin)] extern crate green; use std::from_str::FromStr; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 7129d4993b74f..728f6bd043a26 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -10,7 +10,7 @@ // ignore-pretty very bad with line comments -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] use std::io; use std::io::stdio::StdReader; diff --git a/src/test/compile-fail/lint-non-camel-case-types.rs b/src/test/compile-fail/lint-non-camel-case-types.rs index f33c7956a1418..6ce63e2ecdb77 100644 --- a/src/test/compile-fail/lint-non-camel-case-types.rs +++ b/src/test/compile-fail/lint-non-camel-case-types.rs @@ -32,6 +32,8 @@ enum Foo5 { trait foo6 { //~ ERROR trait `foo6` should have a camel case name such as `Foo6` } +fn f(_: ty) {} //~ ERROR type parameter `ty` should have a camel case name such as `Ty` + #[repr(C)] struct foo7 { bar: int, diff --git a/src/test/compile-fail/lint-non-snake-case-functions.rs b/src/test/compile-fail/lint-non-snake-case-functions.rs index 4253286996c5a..ccbe1f006e308 100644 --- a/src/test/compile-fail/lint-non-snake-case-functions.rs +++ b/src/test/compile-fail/lint-non-snake-case-functions.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(non_snake_case_functions)] +#![deny(non_snake_case)] #![allow(dead_code)] struct Foo; diff --git a/src/test/compile-fail/lint-non-snake-case-lifetimes.rs b/src/test/compile-fail/lint-non-snake-case-lifetimes.rs new file mode 100644 index 0000000000000..64669d90d06bf --- /dev/null +++ b/src/test/compile-fail/lint-non-snake-case-lifetimes.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(non_snake_case)] +#![allow(dead_code)] + +fn f<'FooBar>( //~ ERROR lifetime `'FooBar` should have a snake case name such as `'foo_bar` + _: &'FooBar () +) {} + +fn main() { } diff --git a/src/test/compile-fail/lint-non-snake-case-modules.rs b/src/test/compile-fail/lint-non-snake-case-modules.rs new file mode 100644 index 0000000000000..5bc84698ec905 --- /dev/null +++ b/src/test/compile-fail/lint-non-snake-case-modules.rs @@ -0,0 +1,20 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(non_snake_case)] +#![allow(dead_code)] + +mod FooBar { //~ ERROR module `FooBar` should have a snake case name such as `foo_bar` + pub struct S; +} + +fn f(_: FooBar::S) { } + +fn main() { } diff --git a/src/test/compile-fail/lint-uppercase-variables.rs b/src/test/compile-fail/lint-uppercase-variables.rs index 279cf6d94cbf1..902cd63b1e78c 100644 --- a/src/test/compile-fail/lint-uppercase-variables.rs +++ b/src/test/compile-fail/lint-uppercase-variables.rs @@ -11,21 +11,21 @@ // ignore-tidy-linelength #![allow(dead_code)] -#![deny(uppercase_variables)] +#![deny(non_snake_case)] use std::io::File; use std::io::IoError; struct Something { - X: uint //~ ERROR structure field names should start with a lowercase character + X: uint //~ ERROR structure field `X` should have a snake case name such as `x` } -fn test(Xx: uint) { //~ ERROR variable names should start with a lowercase character +fn test(Xx: uint) { //~ ERROR variable `Xx` should have a snake case name such as `xx` println!("{}", Xx); } fn main() { - let Test: uint = 0; //~ ERROR variable names should start with a lowercase character + let Test: uint = 0; //~ ERROR variable `Test` should have a snake case name such as `test` println!("{}", Test); let mut f = File::open(&Path::new("something.txt")); @@ -33,7 +33,7 @@ fn main() { match f.read(buff) { Ok(cnt) => println!("read this many bytes: {}", cnt), Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {}", EndOfFile.to_string()), - //~^ ERROR variable names should start with a lowercase character + //~^ ERROR variable `EndOfFile` should have a snake case name such as `end_of_file` } test(1); diff --git a/src/test/compile-fail/match-static-const-lc.rs b/src/test/compile-fail/match-static-const-lc.rs index b5ffa3546c19d..a5dce6ecc6f3e 100644 --- a/src/test/compile-fail/match-static-const-lc.rs +++ b/src/test/compile-fail/match-static-const-lc.rs @@ -11,8 +11,9 @@ // Issue #7526: lowercase static constants in patterns look like bindings #![allow(dead_code)] -#![deny(non_uppercase_pattern_statics)] +#![deny(non_uppercase_statics)] +#[allow(non_uppercase_statics)] pub static a : int = 97; fn f() { @@ -25,6 +26,7 @@ fn f() { } mod m { + #[allow(non_uppercase_statics)] pub static aha : int = 7; } diff --git a/src/test/run-pass/match-static-const-rename.rs b/src/test/run-pass/match-static-const-rename.rs index 92f57f34c947d..9028e68da1fd9 100644 --- a/src/test/run-pass/match-static-const-rename.rs +++ b/src/test/run-pass/match-static-const-rename.rs @@ -16,7 +16,7 @@ // around this problem locally by renaming the constant in the `use` // form to an uppercase identifier that placates the lint. -#![deny(non_uppercase_pattern_statics)] +#![deny(non_uppercase_statics)] pub static A : int = 97; @@ -34,6 +34,7 @@ fn f() { } mod m { + #[allow(non_uppercase_statics)] pub static aha : int = 7; } From ed2aad8b4356d24403f86dd9543957367d4fce88 Mon Sep 17 00:00:00 2001 From: P1start Date: Mon, 21 Jul 2014 15:27:59 +1200 Subject: [PATCH 2/2] Add lint groups; define built-in lint groups `bad_style` and `unused` This adds support for lint groups to the compiler. Lint groups are a way of grouping a number of lints together under one name. For example, this also defines a default lint for naming conventions, named `bad_style`. Writing `#[allow(bad_style)]` is equivalent to writing `#[allow(non_camel_case_types, non_snake_case, non_uppercase_statics)]`. These lint groups can also be defined as a compiler plugin using the new `Registry::register_lint_group` method. This also adds two built-in lint groups, `bad_style` and `unused`. The contents of these groups can be seen by running `rustc -W help`. --- src/libcollections/hash/mod.rs | 1 - src/libcore/ops.rs | 2 +- src/librustc/driver/driver.rs | 6 +- src/librustc/driver/mod.rs | 68 +++++++++--- src/librustc/lint/builtin.rs | 12 +-- src/librustc/lint/context.rs | 102 ++++++++++++++---- src/librustc/middle/typeck/infer/equate.rs | 2 +- src/librustc/middle/typeck/infer/glb.rs | 2 +- src/librustc/middle/typeck/infer/lub.rs | 2 +- src/librustc/middle/typeck/infer/sub.rs | 2 +- src/librustc/plugin/registry.rs | 13 ++- src/librustrt/local_data.rs | 8 +- src/test/auxiliary/lint_group_plugin_test.rs | 53 +++++++++ .../lint-group-plugin-deny-cmdline.rs | 27 +++++ src/test/compile-fail/lint-group-style.rs | 40 +++++++ .../run-pass-fulldeps/lint-group-plugin.rs | 28 +++++ 16 files changed, 318 insertions(+), 50 deletions(-) create mode 100644 src/test/auxiliary/lint_group_plugin_test.rs create mode 100644 src/test/compile-fail-fulldeps/lint-group-plugin-deny-cmdline.rs create mode 100644 src/test/compile-fail/lint-group-style.rs create mode 100644 src/test/run-pass-fulldeps/lint-group-plugin.rs diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index a264acf5d03a3..c59de19e822cc 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -157,7 +157,6 @@ macro_rules! impl_hash_tuple( ( $($name:ident)+) => ( impl),*> Hash for ($($name,)*) { - #[allow(uppercase_variables)] #[inline] #[allow(non_snake_case)] fn hash(&self, state: &mut S) { diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 23577dd29e0af..836285bc3135a 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -775,7 +775,7 @@ macro_rules! def_fn_mut( FnMut<($($args,)*),Result> for extern "Rust" fn($($args: $args,)*) -> Result { #[rust_call_abi_hack] - #[allow(uppercase_variables)] + #[allow(non_snake_case)] fn call_mut(&mut self, args: ($($args,)*)) -> Result { let ($($args,)*) = args; (*self)($($args,)*) diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index da20c945cb04a..5ba54a7bfc19f 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -242,13 +242,17 @@ pub fn phase_2_configure_and_expand(sess: &Session, } }); - let Registry { syntax_exts, lint_passes, .. } = registry; + let Registry { syntax_exts, lint_passes, lint_groups, .. } = registry; { let mut ls = sess.lint_store.borrow_mut(); for pass in lint_passes.move_iter() { ls.register_pass(Some(sess), true, pass); } + + for (name, to) in lint_groups.move_iter() { + ls.register_group(Some(sess), true, name, to); + } } // Lint plugins are registered; now we can process command line flags. diff --git a/src/librustc/driver/mod.rs b/src/librustc/driver/mod.rs index dc600e0da3ec0..e6bdf9badc87d 100644 --- a/src/librustc/driver/mod.rs +++ b/src/librustc/driver/mod.rs @@ -180,14 +180,26 @@ Available lint options: lints } + fn sort_lint_groups(lints: Vec<(&'static str, Vec, bool)>) + -> Vec<(&'static str, Vec)> { + let mut lints: Vec<_> = lints.move_iter().map(|(x, y, _)| (x, y)).collect(); + lints.sort_by(|&(x, _): &(&'static str, Vec), + &(y, _): &(&'static str, Vec)| { + x.cmp(&y) + }); + lints + } + let (plugin, builtin) = lint_store.get_lints().partitioned(|&(_, p)| p); let plugin = sort_lints(plugin); let builtin = sort_lints(builtin); - // FIXME (#7043): We should use the width in character cells rather than - // the number of codepoints. + let (plugin_groups, builtin_groups) = lint_store.get_lint_groups().partitioned(|&(_, _, p)| p); + let plugin_groups = sort_lint_groups(plugin_groups); + let builtin_groups = sort_lint_groups(builtin_groups); + let max_name_len = plugin.iter().chain(builtin.iter()) - .map(|&s| s.name.char_len()) + .map(|&s| s.name.width(true)) .max().unwrap_or(0); let padded = |x: &str| { " ".repeat(max_name_len - x.char_len()).append(x) @@ -208,16 +220,48 @@ Available lint options: print_lints(builtin); - match (loaded_plugins, plugin.len()) { - (false, 0) => { - println!("Compiler plugins can provide additional lints. To see a listing of these, \ - re-run `rustc -W help` with a crate filename."); + + + let max_name_len = plugin_groups.iter().chain(builtin_groups.iter()) + .map(|&(s, _)| s.width(true)) + .max().unwrap_or(0); + let padded = |x: &str| { + " ".repeat(max_name_len - x.char_len()).append(x) + }; + + println!("Lint groups provided by rustc:\n"); + println!(" {} {}", padded("name"), "sub-lints"); + println!(" {} {}", padded("----"), "---------"); + + let print_lint_groups = |lints: Vec<(&'static str, Vec)>| { + for (name, to) in lints.move_iter() { + let name = name.chars().map(|x| x.to_lowercase()) + .collect::().replace("_", "-"); + let desc = to.move_iter().map(|x| x.as_str()).collect::>().connect(", "); + println!(" {} {}", + padded(name.as_slice()), desc); } - (false, _) => fail!("didn't load lint plugins but got them anyway!"), - (true, 0) => println!("This crate does not load any lint plugins."), - (true, _) => { - println!("Lint checks provided by plugins loaded by this crate:\n"); - print_lints(plugin); + println!("\n"); + }; + + print_lint_groups(builtin_groups); + + match (loaded_plugins, plugin.len(), plugin_groups.len()) { + (false, 0, _) | (false, _, 0) => { + println!("Compiler plugins can provide additional lints and lint groups. To see a \ + listing of these, re-run `rustc -W help` with a crate filename."); + } + (false, _, _) => fail!("didn't load lint plugins but got them anyway!"), + (true, 0, 0) => println!("This crate does not load any lint plugins or lint groups."), + (true, l, g) => { + if l > 0 { + println!("Lint checks provided by plugins loaded by this crate:\n"); + print_lints(plugin); + } + if g > 0 { + println!("Lint groups provided by plugins loaded by this crate:\n"); + print_lint_groups(plugin_groups); + } } } } diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 71e966d77867e..4f4824a221995 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -736,7 +736,7 @@ impl LintPass for UnusedResult { } } -declare_lint!(NON_CAMEL_CASE_TYPES, Warn, +declare_lint!(pub NON_CAMEL_CASE_TYPES, Warn, "types, variants, traits and type parameters should have camel case names") pub struct NonCamelCaseTypes; @@ -844,7 +844,7 @@ fn method_context(cx: &Context, m: &ast::Method) -> MethodContext { } } -declare_lint!(NON_SNAKE_CASE, Warn, +declare_lint!(pub NON_SNAKE_CASE, Warn, "methods, functions, lifetime parameters and modules should have snake case names") pub struct NonSnakeCase; @@ -930,8 +930,8 @@ impl LintPass for NonSnakeCase { self.check_snake_case(cx, "trait method", t.ident, t.span); } - fn check_lifetime_decl(&mut self, cx: &Context, t: &ast::Lifetime) { - self.check_snake_case(cx, "lifetime", t.name.ident(), t.span); + fn check_lifetime_decl(&mut self, cx: &Context, t: &ast::LifetimeDef) { + self.check_snake_case(cx, "lifetime", t.lifetime.name.ident(), t.lifetime.span); } fn check_pat(&mut self, cx: &Context, p: &ast::Pat) { @@ -962,7 +962,7 @@ impl LintPass for NonSnakeCase { } } -declare_lint!(NON_UPPERCASE_STATICS, Allow, +declare_lint!(pub NON_UPPERCASE_STATICS, Allow, "static constants should have uppercase identifiers") pub struct NonUppercaseStatics; @@ -1143,7 +1143,7 @@ impl LintPass for UnsafeBlock { } } -declare_lint!(UNUSED_MUT, Warn, +declare_lint!(pub UNUSED_MUT, Warn, "detect mut variables which don't need to be mutable") pub struct UnusedMut; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 28e4e1a564ef9..b40916dcc30aa 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -66,6 +66,10 @@ pub struct LintStore { /// Current levels of each lint, and where they were set. levels: HashMap, + + /// Map of registered lint groups to what lints they expand to. The bool + /// is true if the lint group was added by a plugin. + lint_groups: HashMap<&'static str, (Vec, bool)>, } impl LintStore { @@ -90,6 +94,7 @@ impl LintStore { passes: Some(vec!()), by_name: HashMap::new(), levels: HashMap::new(), + lint_groups: HashMap::new(), } } @@ -97,6 +102,10 @@ impl LintStore { self.lints.as_slice() } + pub fn get_lint_groups<'t>(&'t self) -> Vec<(&'static str, Vec, bool)> { + self.lint_groups.iter().map(|(k, &(ref v, b))| (*k, v.clone(), b)).collect() + } + pub fn register_pass(&mut self, sess: Option<&Session>, from_plugin: bool, pass: LintPassObject) { for &lint in pass.get_lints().iter() { @@ -123,6 +132,25 @@ impl LintStore { self.passes.get_mut_ref().push(pass); } + pub fn register_group(&mut self, sess: Option<&Session>, + from_plugin: bool, name: &'static str, + to: Vec) { + let new = self.lint_groups.insert(name, (to, from_plugin)); + + if !new { + let msg = format!("duplicate specification of lint group {}", name); + match (sess, from_plugin) { + // We load builtin lints first, so a duplicate is a compiler bug. + // Use early_error when handling -W help with no crate. + (None, _) => early_error(msg.as_slice()), + (Some(sess), false) => sess.bug(msg.as_slice()), + + // A duplicate name from a plugin is a user error. + (Some(sess), true) => sess.err(msg.as_slice()), + } + } + } + pub fn register_builtin(&mut self, sess: Option<&Session>) { macro_rules! add_builtin ( ( $sess:ident, $($name:ident),*, ) => ( {$( @@ -136,6 +164,10 @@ impl LintStore { )*} )) + macro_rules! add_lint_group ( ( $sess:ident, $name:expr, $($lint:ident),* ) => ( + self.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]); + )) + add_builtin!(sess, HardwiredLints, WhileTrue, @@ -162,6 +194,13 @@ impl LintStore { MissingDoc, ) + add_lint_group!(sess, "bad_style", + NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPERCASE_STATICS) + + add_lint_group!(sess, "unused", + UNUSED_IMPORTS, UNUSED_VARIABLE, DEAD_ASSIGNMENT, DEAD_CODE, + UNUSED_MUT, UNREACHABLE_CODE) + // We have one lint pass defined in this module. self.register_pass(sess, false, box GatherNodeLevels as LintPassObject); } @@ -170,8 +209,20 @@ impl LintStore { for &(ref lint_name, level) in sess.opts.lint_opts.iter() { match self.by_name.find_equiv(&lint_name.as_slice()) { Some(&lint_id) => self.set_level(lint_id, (level, CommandLine)), - None => sess.err(format!("unknown {} flag: {}", - level.as_str(), lint_name).as_slice()), + None => { + match self.lint_groups.iter().map(|(&x, &(ref y, _))| (x, y.clone())) + .collect::>>() + .find_equiv(&lint_name.as_slice()) { + Some(v) => { + v.iter() + .map(|lint_id: &LintId| + self.set_level(*lint_id, (level, CommandLine))) + .collect::>(); + } + None => sess.err(format!("unknown {} flag: {}", + level.as_str(), lint_name).as_slice()), + } + } } } } @@ -305,7 +356,7 @@ impl<'a> Context<'a> { krate: krate, exported_items: exported_items, lints: lint_store, - level_stack: vec!(), + level_stack: vec![], node_levels: RefCell::new(HashMap::new()), } } @@ -359,35 +410,46 @@ impl<'a> Context<'a> { let mut pushed = 0u; for result in gather_attrs(attrs).move_iter() { - let (lint_id, level, span) = match result { + let v = match result { Err(span) => { self.tcx.sess.span_err(span, "malformed lint attribute"); continue; } Ok((lint_name, level, span)) => { match self.lints.by_name.find_equiv(&lint_name.get()) { - Some(&lint_id) => (lint_id, level, span), + Some(&lint_id) => vec![(lint_id, level, span)], None => { - self.span_lint(builtin::UNRECOGNIZED_LINT, span, - format!("unknown `{}` attribute: `{}`", - level.as_str(), lint_name).as_slice()); - continue; + match self.lints.lint_groups.find_equiv(&lint_name.get()) { + Some(&(ref v, _)) => v.iter() + .map(|lint_id: &LintId| + (*lint_id, level, span)) + .collect(), + None => { + self.span_lint(builtin::UNRECOGNIZED_LINT, span, + format!("unknown `{}` attribute: `{}`", + level.as_str(), lint_name).as_slice()); + continue; + } + } } } } }; - let now = self.lints.get_level_source(lint_id).val0(); - if now == Forbid && level != Forbid { - let lint_name = lint_id.as_str(); - self.tcx.sess.span_err(span, - format!("{}({}) overruled by outer forbid({})", - level.as_str(), lint_name, lint_name).as_slice()); - } else if now != level { - let src = self.lints.get_level_source(lint_id).val1(); - self.level_stack.push((lint_id, (now, src))); - pushed += 1; - self.lints.set_level(lint_id, (level, Node(span))); + for (lint_id, level, span) in v.move_iter() { + let now = self.lints.get_level_source(lint_id).val0(); + if now == Forbid && level != Forbid { + let lint_name = lint_id.as_str(); + self.tcx.sess.span_err(span, + format!("{}({}) overruled by outer forbid({})", + level.as_str(), lint_name, + lint_name).as_slice()); + } else if now != level { + let src = self.lints.get_level_source(lint_id).val1(); + self.level_stack.push((lint_id, (now, src))); + pushed += 1; + self.lints.set_level(lint_id, (level, Node(span))); + } } } diff --git a/src/librustc/middle/typeck/infer/equate.rs b/src/librustc/middle/typeck/infer/equate.rs index 391027f9c4bf9..223d37ee1ea62 100644 --- a/src/librustc/middle/typeck/infer/equate.rs +++ b/src/librustc/middle/typeck/infer/equate.rs @@ -27,7 +27,7 @@ pub struct Equate<'f> { fields: CombineFields<'f> } -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] pub fn Equate<'f>(cf: CombineFields<'f>) -> Equate<'f> { Equate { fields: cf } } diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 68b8031a04b68..8ae141ea19cc2 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -34,7 +34,7 @@ pub struct Glb<'f> { fields: CombineFields<'f> } -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] pub fn Glb<'f>(cf: CombineFields<'f>) -> Glb<'f> { Glb { fields: cf } } diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index 9c6c0763ad45e..49760ac92bf7d 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -33,7 +33,7 @@ pub struct Lub<'f> { fields: CombineFields<'f> } -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] pub fn Lub<'f>(cf: CombineFields<'f>) -> Lub<'f> { Lub { fields: cf } } diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index cc3abc279bf34..be4abb1ad8261 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -32,7 +32,7 @@ pub struct Sub<'f> { fields: CombineFields<'f> } -#[allow(non_snake_case_functions)] +#[allow(non_snake_case)] pub fn Sub<'f>(cf: CombineFields<'f>) -> Sub<'f> { Sub { fields: cf } } diff --git a/src/librustc/plugin/registry.rs b/src/librustc/plugin/registry.rs index 2581ba51c2e10..7fa3ee0ac63ed 100644 --- a/src/librustc/plugin/registry.rs +++ b/src/librustc/plugin/registry.rs @@ -10,7 +10,7 @@ //! Used by plugin crates to tell `rustc` about the plugins they provide. -use lint::LintPassObject; +use lint::{LintPassObject, LintId, Lint}; use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT}; use syntax::ext::base::{IdentTT, LetSyntaxTT, ItemDecorator, ItemModifier, BasicMacroExpander}; @@ -19,6 +19,8 @@ use syntax::codemap::Span; use syntax::parse::token; use syntax::ast; +use std::collections::HashMap; + /// Structure used to register plugins. /// /// A plugin registrar function takes an `&mut Registry` and should call @@ -36,6 +38,9 @@ pub struct Registry { #[doc(hidden)] pub lint_passes: Vec, + + #[doc(hidden)] + pub lint_groups: HashMap<&'static str, Vec>, } impl Registry { @@ -45,6 +50,7 @@ impl Registry { krate_span: krate.span, syntax_exts: vec!(), lint_passes: vec!(), + lint_groups: HashMap::new(), } } @@ -80,4 +86,9 @@ impl Registry { pub fn register_lint_pass(&mut self, lint_pass: LintPassObject) { self.lint_passes.push(lint_pass); } + + /// Register a lint group. + pub fn register_lint_group(&mut self, name: &'static str, to: Vec<&'static Lint>) { + self.lint_groups.insert(name, to.move_iter().map(|x| LintId::of(x)).collect()); + } } diff --git a/src/librustrt/local_data.rs b/src/librustrt/local_data.rs index fedea3c31e0b1..70dc03d06d699 100644 --- a/src/librustrt/local_data.rs +++ b/src/librustrt/local_data.rs @@ -218,10 +218,10 @@ impl KeyValue { // Do nothing. None } - (0, Some(newValue)) => { + (0, Some(new_value)) => { // The current value is uninitialized and we're storing a new value. unsafe { - ptr::write(&mut (*value_box).value, newValue); + ptr::write(&mut (*value_box).value, new_value); *(*value_box).refcount.get() = 1; None } @@ -234,10 +234,10 @@ impl KeyValue { Some(ret) } } - (1, Some(newValue)) => { + (1, Some(new_value)) => { // We have an initialized value and we're replacing it. let value_ref = unsafe { &mut (*value_box).value }; - let ret = mem::replace(value_ref, newValue); + let ret = mem::replace(value_ref, new_value); // Refcount is already 1, leave it as that. Some(ret) } diff --git a/src/test/auxiliary/lint_group_plugin_test.rs b/src/test/auxiliary/lint_group_plugin_test.rs new file mode 100644 index 0000000000000..4790ae11b2107 --- /dev/null +++ b/src/test/auxiliary/lint_group_plugin_test.rs @@ -0,0 +1,53 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// force-host + +#![feature(phase, plugin_registrar)] + +extern crate syntax; + +// Load rustc as a plugin to get macros +#[phase(plugin, link)] +extern crate rustc; + +use syntax::ast; +use syntax::parse::token; +use rustc::lint::{Context, LintPass, LintPassObject, LintArray}; +use rustc::plugin::Registry; + +declare_lint!(TEST_LINT, Warn, + "Warn about items named 'lintme'") + +declare_lint!(PLEASE_LINT, Warn, + "Warn about items named 'pleaselintme'") + +struct Pass; + +impl LintPass for Pass { + fn get_lints(&self) -> LintArray { + lint_array!(TEST_LINT, PLEASE_LINT) + } + + fn check_item(&mut self, cx: &Context, it: &ast::Item) { + let name = token::get_ident(it.ident); + if name.get() == "lintme" { + cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); + } else if name.get() == "pleaselintme" { + cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"); + } + } +} + +#[plugin_registrar] +pub fn plugin_registrar(reg: &mut Registry) { + reg.register_lint_pass(box Pass as LintPassObject); + reg.register_lint_group("lint_me", vec![TEST_LINT, PLEASE_LINT]); +} diff --git a/src/test/compile-fail-fulldeps/lint-group-plugin-deny-cmdline.rs b/src/test/compile-fail-fulldeps/lint-group-plugin-deny-cmdline.rs new file mode 100644 index 0000000000000..5edaa78eeea38 --- /dev/null +++ b/src/test/compile-fail-fulldeps/lint-group-plugin-deny-cmdline.rs @@ -0,0 +1,27 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:lint_group_plugin_test.rs +// ignore-stage1 +// compile-flags: -D lint-me + +#![feature(phase)] + +#[phase(plugin)] +extern crate lint_group_plugin_test; + +fn lintme() { } //~ ERROR item is named 'lintme' + +fn pleaselintme() { } //~ ERROR item is named 'pleaselintme' + +pub fn main() { + lintme(); + pleaselintme(); +} diff --git a/src/test/compile-fail/lint-group-style.rs b/src/test/compile-fail/lint-group-style.rs new file mode 100644 index 0000000000000..63d65fc06aa4c --- /dev/null +++ b/src/test/compile-fail/lint-group-style.rs @@ -0,0 +1,40 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(bad_style)] +//~^ NOTE lint level defined here +#![allow(dead_code)] + +fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name + +#[allow(bad_style)] +mod test { + fn CamelCase() {} + + #[forbid(bad_style)] + //~^ NOTE lint level defined here + //~^^ NOTE lint level defined here + mod bad { + fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name + + static bad: int = 1; //~ ERROR static constant `bad` should have an uppercase name + } + + mod warn { + #![warn(bad_style)] + //~^ NOTE lint level defined here + + fn CamelCase() {} //~ WARN function `CamelCase` should have a snake case name + + struct snake_case; //~ WARN type `snake_case` should have a camel case name + } +} + +fn main() {} diff --git a/src/test/run-pass-fulldeps/lint-group-plugin.rs b/src/test/run-pass-fulldeps/lint-group-plugin.rs new file mode 100644 index 0000000000000..726670b5d7f93 --- /dev/null +++ b/src/test/run-pass-fulldeps/lint-group-plugin.rs @@ -0,0 +1,28 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:lint_group_plugin_test.rs +// ignore-stage1 +// ignore-pretty + +#![feature(phase)] + +#[phase(plugin)] +extern crate lint_group_plugin_test; + +fn lintme() { } //~ WARNING item is named 'lintme' +fn pleaselintme() { } //~ WARNING item is named 'pleaselintme' + +#[allow(lint_me)] +pub fn main() { + fn lintme() { } + + fn pleaselintme() { } +}