Skip to content

Commit 55f1555

Browse files
committed
auto merge of #7523 : huonw/rust/uppercase-statics-lint, r=cmr
Adds a lint for `static some_lowercase_name: uint = 1;`. Warning by default since it causes confusion, e.g. `static a: uint = 1; ... let a = 2;` => `error: only refutable patterns allowed here`.
2 parents 6caaa34 + c437a16 commit 55f1555

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+277
-172
lines changed

doc/rust.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1107,20 +1107,20 @@ The derived types are borrowed pointers with the `'static` lifetime,
11071107
fixed-size arrays, tuples, and structs.
11081108

11091109
~~~~
1110-
static bit1: uint = 1 << 0;
1111-
static bit2: uint = 1 << 1;
1110+
static BIT1: uint = 1 << 0;
1111+
static BIT2: uint = 1 << 1;
11121112
1113-
static bits: [uint, ..2] = [bit1, bit2];
1114-
static string: &'static str = "bitstring";
1113+
static BITS: [uint, ..2] = [BIT1, BIT2];
1114+
static STRING: &'static str = "bitstring";
11151115
11161116
struct BitsNStrings<'self> {
11171117
mybits: [uint, ..2],
11181118
mystring: &'self str
11191119
}
11201120
11211121
static bits_n_strings: BitsNStrings<'static> = BitsNStrings {
1122-
mybits: bits,
1123-
mystring: string
1122+
mybits: BITS,
1123+
mystring: STRING
11241124
};
11251125
~~~~
11261126

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ can specify a variable's type by following it with a colon, then the type
237237
name. Static items, on the other hand, always require a type annotation.
238238

239239
~~~~
240-
static monster_factor: float = 57.8;
241-
let monster_size = monster_factor * 10.0;
240+
static MONSTER_FACTOR: float = 57.8;
241+
let monster_size = MONSTER_FACTOR * 10.0;
242242
let monster_size: int = 50;
243243
~~~~
244244

src/compiletest/runtest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ fn run_rfail_test(config: &config, props: &TestProps, testfile: &Path) {
7979
};
8080
8181
// The value our Makefile configures valgrind to return on failure
82-
static valgrind_err: int = 100;
83-
if ProcRes.status == valgrind_err {
82+
static VALGRIND_ERR: int = 100;
83+
if ProcRes.status == VALGRIND_ERR {
8484
fatal_ProcRes(~"run-fail test isn't valgrind-clean!", &ProcRes);
8585
}
8686
@@ -102,8 +102,8 @@ fn run_rfail_test(config: &config, props: &TestProps, testfile: &Path) {
102102

103103
fn check_correct_failure_status(ProcRes: &ProcRes) {
104104
// The value the rust runtime returns on failure
105-
static rust_err: int = 101;
106-
if ProcRes.status != rust_err {
105+
static RUST_ERR: int = 101;
106+
if ProcRes.status != RUST_ERR {
107107
fatal_ProcRes(
108108
fmt!("failure produced the wrong error code: %d",
109109
ProcRes.status),

src/etc/unicode.py

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def emit_decomp_module(f, canon, compat):
250250
// The following code was generated by "src/etc/unicode.py"
251251
252252
#[allow(missing_doc)];
253+
#[allow(non_uppercase_statics)];
253254
254255
''')
255256

src/libextra/bitv.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ mod tests {
872872
use std::rand;
873873
use std::rand::Rng;
874874

875-
static bench_bits : uint = 1 << 14;
875+
static BENCH_BITS : uint = 1 << 14;
876876

877877
#[test]
878878
fn test_to_str() {
@@ -1452,19 +1452,19 @@ mod tests {
14521452
fn bench_big_bitv_big(b: &mut BenchHarness) {
14531453
let mut r = rng();
14541454
let mut storage = ~[];
1455-
storage.grow(bench_bits / uint::bits, &0);
1455+
storage.grow(BENCH_BITS / uint::bits, &0);
14561456
let mut bitv = BigBitv::new(storage);
14571457
do b.iter {
1458-
bitv.set((r.next() as uint) % bench_bits, true);
1458+
bitv.set((r.next() as uint) % BENCH_BITS, true);
14591459
}
14601460
}
14611461

14621462
#[bench]
14631463
fn bench_bitv_big(b: &mut BenchHarness) {
14641464
let mut r = rng();
1465-
let mut bitv = Bitv::new(bench_bits, false);
1465+
let mut bitv = Bitv::new(BENCH_BITS, false);
14661466
do b.iter {
1467-
bitv.set((r.next() as uint) % bench_bits, true);
1467+
bitv.set((r.next() as uint) % BENCH_BITS, true);
14681468
}
14691469
}
14701470

@@ -1491,14 +1491,14 @@ mod tests {
14911491
let mut r = rng();
14921492
let mut bitv = BitvSet::new();
14931493
do b.iter {
1494-
bitv.insert((r.next() as uint) % bench_bits);
1494+
bitv.insert((r.next() as uint) % BENCH_BITS);
14951495
}
14961496
}
14971497

14981498
#[bench]
14991499
fn bench_bitv_big_union(b: &mut BenchHarness) {
1500-
let mut b1 = Bitv::new(bench_bits, false);
1501-
let b2 = Bitv::new(bench_bits, false);
1500+
let mut b1 = Bitv::new(BENCH_BITS, false);
1501+
let b2 = Bitv::new(BENCH_BITS, false);
15021502
do b.iter {
15031503
b1.union(&b2);
15041504
}

src/libextra/deque.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::util::replace;
1515
use std::vec;
1616
use std::cast::transmute;
1717

18-
static initial_capacity: uint = 32u; // 2^5
18+
static INITIAL_CAPACITY: uint = 32u; // 2^5
1919

2020
#[allow(missing_doc)]
2121
pub struct Deque<T> {
@@ -47,7 +47,7 @@ impl<T> Deque<T> {
4747
/// Create an empty Deque
4848
pub fn new() -> Deque<T> {
4949
Deque{nelts: 0, lo: 0, hi: 0,
50-
elts: vec::from_fn(initial_capacity, |_| None)}
50+
elts: vec::from_fn(INITIAL_CAPACITY, |_| None)}
5151
}
5252

5353
/// Return a reference to the first element in the deque

src/libextra/ebml.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ pub mod writer {
748748

749749
// Set to true to generate more debugging in EBML code.
750750
// Totally lame approach.
751-
static debug: bool = true;
751+
static DEBUG: bool = true;
752752

753753
impl Encoder {
754754
// used internally to emit things like the vector length and so on
@@ -764,7 +764,7 @@ pub mod writer {
764764
// efficiency. When debugging, though, we can emit such
765765
// labels and then they will be checked by decoder to
766766
// try and check failures more quickly.
767-
if debug { self.wr_tagged_str(EsLabel as uint, label) }
767+
if DEBUG { self.wr_tagged_str(EsLabel as uint, label) }
768768
}
769769
}
770770

src/libextra/flate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ pub mod rustrt {
3939
}
4040
}
4141

42-
static lz_none : c_int = 0x0; // Huffman-coding only.
43-
static lz_fast : c_int = 0x1; // LZ with only one probe
44-
static lz_norm : c_int = 0x80; // LZ with 128 probes, "normal"
45-
static lz_best : c_int = 0xfff; // LZ with 4095 probes, "best"
42+
static LZ_NONE : c_int = 0x0; // Huffman-coding only.
43+
static LZ_FAST : c_int = 0x1; // LZ with only one probe
44+
static LZ_NORM : c_int = 0x80; // LZ with 128 probes, "normal"
45+
static LZ_BEST : c_int = 0xfff; // LZ with 4095 probes, "best"
4646

4747
pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
4848
do vec::as_imm_buf(bytes) |b, len| {
@@ -52,7 +52,7 @@ pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
5252
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
5353
len as size_t,
5454
&mut outsz,
55-
lz_norm);
55+
LZ_NORM);
5656
assert!(res as int != 0);
5757
let out = vec::raw::from_buf_raw(res as *u8,
5858
outsz as uint);

src/libextra/num/bigint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ A BigInt is a combination of BigUint and Sign.
1717
*/
1818

1919
#[allow(missing_doc)];
20+
#[allow(non_uppercase_statics)];
2021

2122
use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2223
use std::int;

src/libextra/num/complex.rs

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ impl<T: ToStrRadix + Num + Ord> ToStrRadix for Cmplx<T> {
191191

192192
#[cfg(test)]
193193
mod test {
194+
#[allow(non_uppercase_statics)];
195+
194196
use super::*;
195197
use std::num::{Zero,One,Real};
196198

src/libextra/par.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use future_spawn = future::spawn;
2020
* The maximum number of tasks this module will spawn for a single
2121
* operation.
2222
*/
23-
static max_tasks : uint = 32u;
23+
static MAX_TASKS : uint = 32u;
2424

2525
/// The minimum number of elements each task will process.
26-
static min_granularity : uint = 1024u;
26+
static MIN_GRANULARITY : uint = 1024u;
2727

2828
/**
2929
* An internal helper to map a function over a large vector and
@@ -38,13 +38,13 @@ fn map_slices<A:Copy + Send,B:Copy + Send>(
3838
-> ~[B] {
3939

4040
let len = xs.len();
41-
if len < min_granularity {
41+
if len < MIN_GRANULARITY {
4242
info!("small slice");
4343
// This is a small vector, fall back on the normal map.
4444
~[f()(0u, xs)]
4545
}
4646
else {
47-
let num_tasks = uint::min(max_tasks, len / min_granularity);
47+
let num_tasks = uint::min(MAX_TASKS, len / MIN_GRANULARITY);
4848

4949
let items_per_task = len / num_tasks;
5050

src/libextra/rope.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -632,14 +632,14 @@ pub mod node {
632632
*
633633
* This is not a strict value
634634
*/
635-
pub static hint_max_leaf_char_len: uint = 256u;
635+
pub static HINT_MAX_LEAF_CHAR_LEN: uint = 256u;
636636

637637
/**
638638
* The maximal height that _should_ be permitted in a tree.
639639
*
640640
* This is not a strict value
641641
*/
642-
pub static hint_max_node_height: uint = 16u;
642+
pub static HINT_MAX_NODE_HEIGHT: uint = 16u;
643643

644644
/**
645645
* Adopt a string as a node.
@@ -707,26 +707,26 @@ pub mod node {
707707
char_len: char_len,
708708
content: str,
709709
});
710-
if char_len <= hint_max_leaf_char_len {
710+
if char_len <= HINT_MAX_LEAF_CHAR_LEN {
711711
return candidate;
712712
} else {
713-
//Firstly, split `str` in slices of hint_max_leaf_char_len
714-
let mut leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
713+
//Firstly, split `str` in slices of HINT_MAX_LEAF_CHAR_LEN
714+
let mut leaves = uint::div_ceil(char_len, HINT_MAX_LEAF_CHAR_LEN);
715715
//Number of leaves
716716
let mut nodes = vec::from_elem(leaves, candidate);
717717

718718
let mut i = 0u;
719719
let mut offset = byte_start;
720720
let first_leaf_char_len =
721-
if char_len%hint_max_leaf_char_len == 0u {
722-
hint_max_leaf_char_len
721+
if char_len%HINT_MAX_LEAF_CHAR_LEN == 0u {
722+
HINT_MAX_LEAF_CHAR_LEN
723723
} else {
724-
char_len%hint_max_leaf_char_len
724+
char_len%HINT_MAX_LEAF_CHAR_LEN
725725
};
726726
while i < leaves {
727727
let chunk_char_len: uint =
728728
if i == 0u { first_leaf_char_len }
729-
else { hint_max_leaf_char_len };
729+
else { HINT_MAX_LEAF_CHAR_LEN };
730730
let chunk_byte_len =
731731
str.slice_from(offset).slice_chars(0, chunk_char_len).len();
732732
nodes[i] = @Leaf(Leaf {
@@ -792,22 +792,22 @@ pub mod node {
792792
let right_len= char_len(right);
793793
let mut left_height= height(left);
794794
let mut right_height=height(right);
795-
if left_len + right_len > hint_max_leaf_char_len {
796-
if left_len <= hint_max_leaf_char_len {
795+
if left_len + right_len > HINT_MAX_LEAF_CHAR_LEN {
796+
if left_len <= HINT_MAX_LEAF_CHAR_LEN {
797797
left = flatten(left);
798798
left_height = height(left);
799799
}
800-
if right_len <= hint_max_leaf_char_len {
800+
if right_len <= HINT_MAX_LEAF_CHAR_LEN {
801801
right = flatten(right);
802802
right_height = height(right);
803803
}
804804
}
805-
if left_height >= hint_max_node_height {
805+
if left_height >= HINT_MAX_NODE_HEIGHT {
806806
left = of_substr_unsafer(@serialize_node(left),
807807
0u,byte_len(left),
808808
left_len);
809809
}
810-
if right_height >= hint_max_node_height {
810+
if right_height >= HINT_MAX_NODE_HEIGHT {
811811
right = of_substr_unsafer(@serialize_node(right),
812812
0u,byte_len(right),
813813
right_len);
@@ -875,7 +875,7 @@ pub mod node {
875875
*
876876
* # Algorithm
877877
*
878-
* * if the node height is smaller than `hint_max_node_height`, do nothing
878+
* * if the node height is smaller than `HINT_MAX_NODE_HEIGHT`, do nothing
879879
* * otherwise, gather all leaves as a forest, rebuild a balanced node,
880880
* concatenating small leaves along the way
881881
*
@@ -886,7 +886,7 @@ pub mod node {
886886
* as `node` bot lower height and/or fragmentation.
887887
*/
888888
pub fn bal(node: @Node) -> Option<@Node> {
889-
if height(node) < hint_max_node_height { return None; }
889+
if height(node) < HINT_MAX_NODE_HEIGHT { return None; }
890890
//1. Gather all leaves as a forest
891891
let mut forest = ~[];
892892
let mut it = leaf_iterator::start(node);

src/libextra/term.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ use std::io;
2626
pub mod color {
2727
pub type Color = u16;
2828

29-
pub static black: Color = 0u16;
30-
pub static red: Color = 1u16;
31-
pub static green: Color = 2u16;
32-
pub static yellow: Color = 3u16;
33-
pub static blue: Color = 4u16;
34-
pub static magenta: Color = 5u16;
35-
pub static cyan: Color = 6u16;
36-
pub static white: Color = 7u16;
37-
38-
pub static bright_black: Color = 8u16;
39-
pub static bright_red: Color = 9u16;
40-
pub static bright_green: Color = 10u16;
41-
pub static bright_yellow: Color = 11u16;
42-
pub static bright_blue: Color = 12u16;
43-
pub static bright_magenta: Color = 13u16;
44-
pub static bright_cyan: Color = 14u16;
45-
pub static bright_white: Color = 15u16;
29+
pub static BLACK: Color = 0u16;
30+
pub static RED: Color = 1u16;
31+
pub static GREEN: Color = 2u16;
32+
pub static YELLOW: Color = 3u16;
33+
pub static BLUE: Color = 4u16;
34+
pub static MAGENTA: Color = 5u16;
35+
pub static CYAN: Color = 6u16;
36+
pub static WHITE: Color = 7u16;
37+
38+
pub static BRIGHT_BLACK: Color = 8u16;
39+
pub static BRIGHT_RED: Color = 9u16;
40+
pub static BRIGHT_GREEN: Color = 10u16;
41+
pub static BRIGHT_YELLOW: Color = 11u16;
42+
pub static BRIGHT_BLUE: Color = 12u16;
43+
pub static BRIGHT_MAGENTA: Color = 13u16;
44+
pub static BRIGHT_CYAN: Color = 14u16;
45+
pub static BRIGHT_WHITE: Color = 15u16;
4646
}
4747

4848
#[cfg(not(target_os = "win32"))]

src/libextra/terminfo/parser/compiled.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[allow(non_uppercase_statics)];
12+
1113
/// ncurses-compatible compiled terminfo format parsing (term(5))
1214
1315

0 commit comments

Comments
 (0)