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]
This commit is contained in:
parent
bd159d3867
commit
de7abd8824
51 changed files with 214 additions and 176 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ preamble = '''// Copyright 2012-2014 The Rust Project Developers. See the COPYRI
|
|||
|
||||
// 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:
|
||||
|
|
|
@ -159,6 +159,7 @@ macro_rules! impl_hash_tuple(
|
|||
impl<S: Writer, $($name: Hash<S>),*> Hash<S> for ($($name,)*) {
|
||||
#[allow(uppercase_variables)]
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
fn hash(&self, state: &mut S) {
|
||||
match *self {
|
||||
($(ref $name,)*) => {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,7 +760,6 @@ impl LintPass for NonCamelCaseTypes {
|
|||
)).collect()
|
||||
}
|
||||
|
||||
fn check_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
|
||||
let s = token::get_ident(ident);
|
||||
|
||||
if !is_camel_case(ident) {
|
||||
|
@ -777,7 +772,14 @@ impl LintPass for NonCamelCaseTypes {
|
|||
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")
|
||||
|
||||
|
|
|
@ -146,10 +146,8 @@ impl LintStore {
|
|||
PathStatement,
|
||||
UnusedResult,
|
||||
NonCamelCaseTypes,
|
||||
NonSnakeCaseFunctions,
|
||||
NonSnakeCase,
|
||||
NonUppercaseStatics,
|
||||
NonUppercasePatternStatics,
|
||||
UppercaseVariables,
|
||||
UnnecessaryParens,
|
||||
UnusedUnsafe,
|
||||
UnsafeBlock,
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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 };)+
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()),*])
|
||||
|
|
|
@ -481,7 +481,7 @@ macro_rules! tuple (
|
|||
() => ();
|
||||
( $($name:ident,)+ ) => (
|
||||
impl<E, D:Decoder<E>,$($name:Decodable<D, E>),*> Decodable<D,E> 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<E, S:Encoder<E>,$($name:Encodable<S, E>),*> Encodable<S, E> 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#![experimental]
|
||||
|
||||
#![allow(missing_doc)]
|
||||
#![allow(non_snake_case_functions)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use clone::Clone;
|
||||
use collections::{Collection, MutableSeq};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -29,7 +29,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder};
|
|||
// FIXME(eddyb) #10676 use Rc<T> in the future.
|
||||
pub type P<T> = Gc<T>;
|
||||
|
||||
#[allow(non_snake_case_functions)]
|
||||
#[allow(non_snake_case)]
|
||||
/// Construct a P<T> from a T value.
|
||||
pub fn P<T: 'static>(value: T) -> P<T> {
|
||||
box(GC) value
|
||||
|
|
|
@ -27,7 +27,7 @@ pub struct WinConsole<T> {
|
|||
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;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -32,6 +32,8 @@ enum Foo5 {
|
|||
trait foo6 { //~ ERROR trait `foo6` should have a camel case name such as `Foo6`
|
||||
}
|
||||
|
||||
fn f<ty>(_: ty) {} //~ ERROR type parameter `ty` should have a camel case name such as `Ty`
|
||||
|
||||
#[repr(C)]
|
||||
struct foo7 {
|
||||
bar: int,
|
||||
|
|
|
@ -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;
|
||||
|
|
18
src/test/compile-fail/lint-non-snake-case-lifetimes.rs
Normal file
18
src/test/compile-fail/lint-non-snake-case-lifetimes.rs
Normal file
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() { }
|
20
src/test/compile-fail/lint-non-snake-case-modules.rs
Normal file
20
src/test/compile-fail/lint-non-snake-case-modules.rs
Normal file
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() { }
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue