Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint against lowercase static mut #37162

Merged
merged 3 commits into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,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]
Expand Down
22 changes: 11 additions & 11 deletions src/libcollectionstest/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -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;
}
}
}
Expand All @@ -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;
}
}
}
Expand All @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Copy link
Contributor

@jseyfried jseyfried Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the above two arms could be merged into a single arm:

    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);
Expand Down
14 changes: 7 additions & 7 deletions src/libstd/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -396,21 +396,21 @@ 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();
});
}

unsafe {
O.call_once(|| {
assert!(!run);
run = true;
assert!(!RUN);
RUN = true;
});
assert!(run);
assert!(RUN);
}

for _ in 0..10 {
Expand Down
6 changes: 3 additions & 3 deletions src/rtstartup/rsbegin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/lint-group-style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/test/compile-fail/lint-non-uppercase-statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }

This file was deleted.