From 26a8c3b6b6ae8cf45a5d6fb37373e8638a8f7b78 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Sat, 2 Apr 2016 09:39:27 -0400 Subject: [PATCH 1/3] Wrote a failing test case --- .../lint-non-snake-case-two-underscores.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/run-pass/lint-non-snake-case-two-underscores.rs diff --git a/src/test/run-pass/lint-non-snake-case-two-underscores.rs b/src/test/run-pass/lint-non-snake-case-two-underscores.rs new file mode 100644 index 0000000000000..380af72eba4ca --- /dev/null +++ b/src/test/run-pass/lint-non-snake-case-two-underscores.rs @@ -0,0 +1,42 @@ +// 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)] + +// These tests should not fail because they all begin with '__'. + +struct Foo { + __FooVariable: i32, + __cOoKiE: f64 +} + +impl Foo { + fn __TestMethod() { } + fn __nOn____snake__CASE() { } +} + +trait X { + fn __ABC() { } + fn __X_y__ZZ() { } +} + +impl X for Foo { + fn __ABC() { } + fn __X_y__ZZ() { } +} + +fn __BISCUIT() { } +fn __THIs_____iSNoT____snaKE____caSE() { } + +fn main() { + let __barXYZ: i32 = 0; + let __Foo22 = "str"; +} From cf3766e6f7d21eafc27e004fa9d754d343c754e6 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Sat, 2 Apr 2016 11:11:07 -0400 Subject: [PATCH 2/3] Anything that begins with '__' and should be checked for snake case will not be checked for snake case This satisfies the test case I made earlier --- src/librustc_lint/bad_style.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 66d435a7581d9..1412e787e6c8c 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -179,6 +179,9 @@ impl NonSnakeCase { fn check_snake_case(&self, cx: &LateContext, sort: &str, name: &str, span: Option) { fn is_snake_case(ident: &str) -> bool { + if ident.starts_with("__") { + return true; + } if ident.is_empty() { return true; } From b924582f403462d61573d8f7bad6ee486813739d Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Sat, 2 Apr 2016 11:14:18 -0400 Subject: [PATCH 3/3] Added a comment --- src/librustc_lint/bad_style.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 1412e787e6c8c..11d68b83c4e64 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -179,6 +179,7 @@ impl NonSnakeCase { fn check_snake_case(&self, cx: &LateContext, sort: &str, name: &str, span: Option) { fn is_snake_case(ident: &str) -> bool { + // Items starting with '__' will be counted as snake case even if they are not if ident.starts_with("__") { return true; }