diff options
| author | bors <bors@rust-lang.org> | 2016-10-17 04:32:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-17 04:32:15 -0700 |
| commit | 07b86d0d4d41976f52aa318960e605534ee42d4f (patch) | |
| tree | 411b4c9dade7d519fa31f35aab7180a69725f8d5 | |
| parent | da7f8c540b47c5bb063356bf5ad05a6a49ed0ff1 (diff) | |
| parent | 066d62d4b4d508f7a46d773c9100dc6516ac34f6 (diff) | |
| download | rust-07b86d0d4d41976f52aa318960e605534ee42d4f.tar.gz rust-07b86d0d4d41976f52aa318960e605534ee42d4f.zip | |
Auto merge of #37162 - matklad:static-mut-lint, r=jseyfried
Lint against lowercase static mut Closes #37145. Lint for non mut statics was added in https://github.com/rust-lang/rust/pull/7523, and it explicitly did not cover mut statics. I am not sure why.
| -rw-r--r-- | src/libcollectionstest/vec.rs | 10 | ||||
| -rw-r--r-- | src/libcollectionstest/vec_deque.rs | 22 | ||||
| -rw-r--r-- | src/librustc_lint/bad_style.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sync/once.rs | 14 | ||||
| -rw-r--r-- | src/rtstartup/rsbegin.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-group-style.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-non-uppercase-statics.rs | 5 | ||||
| -rw-r--r-- | src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs | 19 |
8 files changed, 33 insertions, 50 deletions
diff --git a/src/libcollectionstest/vec.rs b/src/libcollectionstest/vec.rs index 8417be289eb..991c456fe74 100644 --- a/src/libcollectionstest/vec.rs +++ b/src/libcollectionstest/vec.rs @@ -326,22 +326,22 @@ fn test_zip_unzip() { #[test] fn test_vec_truncate_drop() { - static mut drops: u32 = 0; + static mut DROPS: u32 = 0; struct Elem(i32); impl Drop for Elem { fn drop(&mut self) { unsafe { - drops += 1; + DROPS += 1; } } } let mut v = vec![Elem(1), Elem(2), Elem(3), Elem(4), Elem(5)]; - assert_eq!(unsafe { drops }, 0); + assert_eq!(unsafe { DROPS }, 0); v.truncate(3); - assert_eq!(unsafe { drops }, 2); + assert_eq!(unsafe { DROPS }, 2); v.truncate(0); - assert_eq!(unsafe { drops }, 5); + assert_eq!(unsafe { DROPS }, 5); } #[test] diff --git a/src/libcollectionstest/vec_deque.rs b/src/libcollectionstest/vec_deque.rs index 5e8633a9748..9dfd3430268 100644 --- a/src/libcollectionstest/vec_deque.rs +++ b/src/libcollectionstest/vec_deque.rs @@ -695,12 +695,12 @@ fn test_show() { #[test] fn test_drop() { - static mut drops: i32 = 0; + static mut DROPS: i32 = 0; struct Elem; impl Drop for Elem { fn drop(&mut self) { unsafe { - drops += 1; + DROPS += 1; } } } @@ -712,17 +712,17 @@ fn test_drop() { ring.push_front(Elem); drop(ring); - assert_eq!(unsafe { drops }, 4); + assert_eq!(unsafe { DROPS }, 4); } #[test] fn test_drop_with_pop() { - static mut drops: i32 = 0; + static mut DROPS: i32 = 0; struct Elem; impl Drop for Elem { fn drop(&mut self) { unsafe { - drops += 1; + DROPS += 1; } } } @@ -735,20 +735,20 @@ fn test_drop_with_pop() { drop(ring.pop_back()); drop(ring.pop_front()); - assert_eq!(unsafe { drops }, 2); + assert_eq!(unsafe { DROPS }, 2); drop(ring); - assert_eq!(unsafe { drops }, 4); + assert_eq!(unsafe { DROPS }, 4); } #[test] fn test_drop_clear() { - static mut drops: i32 = 0; + static mut DROPS: i32 = 0; struct Elem; impl Drop for Elem { fn drop(&mut self) { unsafe { - drops += 1; + DROPS += 1; } } } @@ -759,10 +759,10 @@ fn test_drop_clear() { ring.push_back(Elem); ring.push_front(Elem); ring.clear(); - assert_eq!(unsafe { drops }, 4); + assert_eq!(unsafe { DROPS }, 4); drop(ring); - assert_eq!(unsafe { drops }, 4); + assert_eq!(unsafe { DROPS }, 4); } #[test] diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index acb92bec7c7..fea3de59520 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -355,9 +355,8 @@ impl LintPass for NonUpperCaseGlobals { impl LateLintPass for NonUpperCaseGlobals { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { - // only check static constants - hir::ItemStatic(_, hir::MutImmutable, _) => { - NonUpperCaseGlobals::check_upper_case(cx, "static constant", it.name, it.span); + hir::ItemStatic(..) => { + NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span); } hir::ItemConst(..) => { NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name, it.span); diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index ad9d0b37544..71e163321ae 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -387,7 +387,7 @@ mod tests { #[test] fn stampede_once() { static O: Once = Once::new(); - static mut run: bool = false; + static mut RUN: bool = false; let (tx, rx) = channel(); for _ in 0..10 { @@ -396,10 +396,10 @@ mod tests { for _ in 0..4 { thread::yield_now() } unsafe { O.call_once(|| { - assert!(!run); - run = true; + assert!(!RUN); + RUN = true; }); - assert!(run); + assert!(RUN); } tx.send(()).unwrap(); }); @@ -407,10 +407,10 @@ mod tests { unsafe { O.call_once(|| { - assert!(!run); - run = true; + assert!(!RUN); + RUN = true; }); - assert!(run); + assert!(RUN); } for _ in 0..10 { diff --git a/src/rtstartup/rsbegin.rs b/src/rtstartup/rsbegin.rs index b57b7e84321..65c85697ce7 100644 --- a/src/rtstartup/rsbegin.rs +++ b/src/rtstartup/rsbegin.rs @@ -44,7 +44,7 @@ pub mod eh_frames { // Scratch space for unwinder's internal book-keeping. // This is defined as `struct object` in $GCC/libgcc/unwind-dw2-fde.h. - static mut obj: [isize; 6] = [0; 6]; + static mut OBJ: [isize; 6] = [0; 6]; // Unwind info registration/deregistration routines. // See the docs of `unwind` module in libstd. @@ -56,13 +56,13 @@ pub mod eh_frames { unsafe fn init() { // register unwind info on module startup rust_eh_register_frames(&__EH_FRAME_BEGIN__ as *const u8, - &mut obj as *mut _ as *mut u8); + &mut OBJ as *mut _ as *mut u8); } unsafe fn uninit() { // unregister on shutdown rust_eh_unregister_frames(&__EH_FRAME_BEGIN__ as *const u8, - &mut obj as *mut _ as *mut u8); + &mut OBJ as *mut _ as *mut u8); } // MSVC-specific init/uninit routine registration diff --git a/src/test/compile-fail/lint-group-style.rs b/src/test/compile-fail/lint-group-style.rs index 393e46ab539..b2e6072c985 100644 --- a/src/test/compile-fail/lint-group-style.rs +++ b/src/test/compile-fail/lint-group-style.rs @@ -24,7 +24,7 @@ mod test { mod bad { fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name - static bad: isize = 1; //~ ERROR static constant `bad` should have an upper case name + static bad: isize = 1; //~ ERROR static variable `bad` should have an upper case name } mod warn { diff --git a/src/test/compile-fail/lint-non-uppercase-statics.rs b/src/test/compile-fail/lint-non-uppercase-statics.rs index e1fbc73bbed..463a93612ca 100644 --- a/src/test/compile-fail/lint-non-uppercase-statics.rs +++ b/src/test/compile-fail/lint-non-uppercase-statics.rs @@ -11,6 +11,9 @@ #![forbid(non_upper_case_globals)] #![allow(dead_code)] -static foo: isize = 1; //~ ERROR static constant `foo` should have an upper case name such as `FOO` +static foo: isize = 1; //~ ERROR static variable `foo` should have an upper case name such as `FOO` + +static mut bar: isize = 1; + //~^ ERROR static variable `bar` should have an upper case name such as `BAR` fn main() { } diff --git a/src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs b/src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs deleted file mode 100644 index aa5b3834c01..00000000000 --- a/src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2013 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. - - -// pretty-expanded FIXME #23616 - -#![forbid(non_camel_case_types)] -#![forbid(non_upper_case_globals)] - -static mut bar: isize = 2; - -pub fn main() {} |
