Skip to content

Commit 07b86d0

Browse files
authored
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 #7523, and it explicitly did not cover mut statics. I am not sure why.
2 parents da7f8c5 + 066d62d commit 07b86d0

File tree

8 files changed

+33
-50
lines changed

8 files changed

+33
-50
lines changed

src/libcollectionstest/vec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,22 @@ fn test_zip_unzip() {
326326

327327
#[test]
328328
fn test_vec_truncate_drop() {
329-
static mut drops: u32 = 0;
329+
static mut DROPS: u32 = 0;
330330
struct Elem(i32);
331331
impl Drop for Elem {
332332
fn drop(&mut self) {
333333
unsafe {
334-
drops += 1;
334+
DROPS += 1;
335335
}
336336
}
337337
}
338338

339339
let mut v = vec![Elem(1), Elem(2), Elem(3), Elem(4), Elem(5)];
340-
assert_eq!(unsafe { drops }, 0);
340+
assert_eq!(unsafe { DROPS }, 0);
341341
v.truncate(3);
342-
assert_eq!(unsafe { drops }, 2);
342+
assert_eq!(unsafe { DROPS }, 2);
343343
v.truncate(0);
344-
assert_eq!(unsafe { drops }, 5);
344+
assert_eq!(unsafe { DROPS }, 5);
345345
}
346346

347347
#[test]

src/libcollectionstest/vec_deque.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,12 @@ fn test_show() {
695695

696696
#[test]
697697
fn test_drop() {
698-
static mut drops: i32 = 0;
698+
static mut DROPS: i32 = 0;
699699
struct Elem;
700700
impl Drop for Elem {
701701
fn drop(&mut self) {
702702
unsafe {
703-
drops += 1;
703+
DROPS += 1;
704704
}
705705
}
706706
}
@@ -712,17 +712,17 @@ fn test_drop() {
712712
ring.push_front(Elem);
713713
drop(ring);
714714

715-
assert_eq!(unsafe { drops }, 4);
715+
assert_eq!(unsafe { DROPS }, 4);
716716
}
717717

718718
#[test]
719719
fn test_drop_with_pop() {
720-
static mut drops: i32 = 0;
720+
static mut DROPS: i32 = 0;
721721
struct Elem;
722722
impl Drop for Elem {
723723
fn drop(&mut self) {
724724
unsafe {
725-
drops += 1;
725+
DROPS += 1;
726726
}
727727
}
728728
}
@@ -735,20 +735,20 @@ fn test_drop_with_pop() {
735735

736736
drop(ring.pop_back());
737737
drop(ring.pop_front());
738-
assert_eq!(unsafe { drops }, 2);
738+
assert_eq!(unsafe { DROPS }, 2);
739739

740740
drop(ring);
741-
assert_eq!(unsafe { drops }, 4);
741+
assert_eq!(unsafe { DROPS }, 4);
742742
}
743743

744744
#[test]
745745
fn test_drop_clear() {
746-
static mut drops: i32 = 0;
746+
static mut DROPS: i32 = 0;
747747
struct Elem;
748748
impl Drop for Elem {
749749
fn drop(&mut self) {
750750
unsafe {
751-
drops += 1;
751+
DROPS += 1;
752752
}
753753
}
754754
}
@@ -759,10 +759,10 @@ fn test_drop_clear() {
759759
ring.push_back(Elem);
760760
ring.push_front(Elem);
761761
ring.clear();
762-
assert_eq!(unsafe { drops }, 4);
762+
assert_eq!(unsafe { DROPS }, 4);
763763

764764
drop(ring);
765-
assert_eq!(unsafe { drops }, 4);
765+
assert_eq!(unsafe { DROPS }, 4);
766766
}
767767

768768
#[test]

src/librustc_lint/bad_style.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,8 @@ impl LintPass for NonUpperCaseGlobals {
355355
impl LateLintPass for NonUpperCaseGlobals {
356356
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
357357
match it.node {
358-
// only check static constants
359-
hir::ItemStatic(_, hir::MutImmutable, _) => {
360-
NonUpperCaseGlobals::check_upper_case(cx, "static constant", it.name, it.span);
358+
hir::ItemStatic(..) => {
359+
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
361360
}
362361
hir::ItemConst(..) => {
363362
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name, it.span);

src/libstd/sync/once.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ mod tests {
387387
#[test]
388388
fn stampede_once() {
389389
static O: Once = Once::new();
390-
static mut run: bool = false;
390+
static mut RUN: bool = false;
391391

392392
let (tx, rx) = channel();
393393
for _ in 0..10 {
@@ -396,21 +396,21 @@ mod tests {
396396
for _ in 0..4 { thread::yield_now() }
397397
unsafe {
398398
O.call_once(|| {
399-
assert!(!run);
400-
run = true;
399+
assert!(!RUN);
400+
RUN = true;
401401
});
402-
assert!(run);
402+
assert!(RUN);
403403
}
404404
tx.send(()).unwrap();
405405
});
406406
}
407407

408408
unsafe {
409409
O.call_once(|| {
410-
assert!(!run);
411-
run = true;
410+
assert!(!RUN);
411+
RUN = true;
412412
});
413-
assert!(run);
413+
assert!(RUN);
414414
}
415415

416416
for _ in 0..10 {

src/rtstartup/rsbegin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod eh_frames {
4444

4545
// Scratch space for unwinder's internal book-keeping.
4646
// This is defined as `struct object` in $GCC/libgcc/unwind-dw2-fde.h.
47-
static mut obj: [isize; 6] = [0; 6];
47+
static mut OBJ: [isize; 6] = [0; 6];
4848

4949
// Unwind info registration/deregistration routines.
5050
// See the docs of `unwind` module in libstd.
@@ -56,13 +56,13 @@ pub mod eh_frames {
5656
unsafe fn init() {
5757
// register unwind info on module startup
5858
rust_eh_register_frames(&__EH_FRAME_BEGIN__ as *const u8,
59-
&mut obj as *mut _ as *mut u8);
59+
&mut OBJ as *mut _ as *mut u8);
6060
}
6161

6262
unsafe fn uninit() {
6363
// unregister on shutdown
6464
rust_eh_unregister_frames(&__EH_FRAME_BEGIN__ as *const u8,
65-
&mut obj as *mut _ as *mut u8);
65+
&mut OBJ as *mut _ as *mut u8);
6666
}
6767

6868
// MSVC-specific init/uninit routine registration

src/test/compile-fail/lint-group-style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod test {
2424
mod bad {
2525
fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name
2626

27-
static bad: isize = 1; //~ ERROR static constant `bad` should have an upper case name
27+
static bad: isize = 1; //~ ERROR static variable `bad` should have an upper case name
2828
}
2929

3030
mod warn {

src/test/compile-fail/lint-non-uppercase-statics.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#![forbid(non_upper_case_globals)]
1212
#![allow(dead_code)]
1313

14-
static foo: isize = 1; //~ ERROR static constant `foo` should have an upper case name such as `FOO`
14+
static foo: isize = 1; //~ ERROR static variable `foo` should have an upper case name such as `FOO`
15+
16+
static mut bar: isize = 1;
17+
//~^ ERROR static variable `bar` should have an upper case name such as `BAR`
1518

1619
fn main() { }

src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs

-19
This file was deleted.

0 commit comments

Comments
 (0)