Skip to content

Commit 712c630

Browse files
committed
auto merge of #12300 : DaGenix/rust/uppercase-variable-lint, r=alexcrichton
I added a new lint for variables whose names contain uppercase characters, since, by convention, variable names should be all lowercase. What motivated me to work on this was when I ran into something like the following: ```rust use std::io::File; use std::io::IoError; fn main() { let mut f = File::open(&Path::new("/something.txt")); let mut buff = [0u8, ..16]; match f.read(buff) { Ok(cnt) => println!("read this many bytes: {}", cnt), Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {}", EndOfFile.to_str()), } } ``` I then got compile errors when I tried to add a wildcard match pattern at the end which I found very confusing since I believed that the 2nd match arm was only matching the EndOfFile condition. The problem is that I hadn't imported io::EndOfFile into the local scope. So, I thought that I was using EndOfFile as a sub-pattern, however, what I was actually doing was creating a new local variable named EndOfFile. This lint makes this error easier to spot by providing a warning that the variable name EndOfFile contains a uppercase characters which provides a nice hint as to why the code isn't doing what is intended. The lint warns on local bindings as well: ```rust let Hi = 0; ``` And also struct fields: ```rust struct Something { X: uint } ```
2 parents 3cc761f + 258dbd0 commit 712c630

File tree

27 files changed

+698
-605
lines changed

27 files changed

+698
-605
lines changed

src/compiletest/runtest.rs

+80-80
Large diffs are not rendered by default.

src/libnum/bigint.rs

+67-67
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ impl Mul<BigUint, BigUint> for BigUint {
266266
// (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
267267
// a0*b0
268268
let half_len = cmp::max(s_len, o_len) / 2;
269-
let (sHi, sLo) = cut_at(self, half_len);
270-
let (oHi, oLo) = cut_at(other, half_len);
269+
let (s_hi, s_lo) = cut_at(self, half_len);
270+
let (o_hi, o_lo) = cut_at(other, half_len);
271271

272-
let ll = sLo * oLo;
273-
let hh = sHi * oHi;
272+
let ll = s_lo * o_lo;
273+
let hh = s_hi * o_hi;
274274
let mm = {
275-
let (s1, n1) = sub_sign(sHi, sLo);
276-
let (s2, n2) = sub_sign(oHi, oLo);
275+
let (s1, n1) = sub_sign(s_hi, s_lo);
276+
let (s2, n2) = sub_sign(o_hi, o_lo);
277277
match (s1, s2) {
278278
(Equal, _) | (_, Equal) => hh + ll,
279279
(Less, Greater) | (Greater, Less) => hh + ll + (n1 * n2),
@@ -1778,10 +1778,10 @@ mod biguint_tests {
17781778
#[test]
17791779
fn test_add() {
17801780
for elm in sum_triples.iter() {
1781-
let (aVec, bVec, cVec) = *elm;
1782-
let a = BigUint::from_slice(aVec);
1783-
let b = BigUint::from_slice(bVec);
1784-
let c = BigUint::from_slice(cVec);
1781+
let (a_vec, b_vec, c_vec) = *elm;
1782+
let a = BigUint::from_slice(a_vec);
1783+
let b = BigUint::from_slice(b_vec);
1784+
let c = BigUint::from_slice(c_vec);
17851785

17861786
assert!(a + b == c);
17871787
assert!(b + a == c);
@@ -1791,10 +1791,10 @@ mod biguint_tests {
17911791
#[test]
17921792
fn test_sub() {
17931793
for elm in sum_triples.iter() {
1794-
let (aVec, bVec, cVec) = *elm;
1795-
let a = BigUint::from_slice(aVec);
1796-
let b = BigUint::from_slice(bVec);
1797-
let c = BigUint::from_slice(cVec);
1794+
let (a_vec, b_vec, c_vec) = *elm;
1795+
let a = BigUint::from_slice(a_vec);
1796+
let b = BigUint::from_slice(b_vec);
1797+
let c = BigUint::from_slice(c_vec);
17981798

17991799
assert!(c - a == b);
18001800
assert!(c - b == a);
@@ -1842,21 +1842,21 @@ mod biguint_tests {
18421842
#[test]
18431843
fn test_mul() {
18441844
for elm in mul_triples.iter() {
1845-
let (aVec, bVec, cVec) = *elm;
1846-
let a = BigUint::from_slice(aVec);
1847-
let b = BigUint::from_slice(bVec);
1848-
let c = BigUint::from_slice(cVec);
1845+
let (a_vec, b_vec, c_vec) = *elm;
1846+
let a = BigUint::from_slice(a_vec);
1847+
let b = BigUint::from_slice(b_vec);
1848+
let c = BigUint::from_slice(c_vec);
18491849

18501850
assert!(a * b == c);
18511851
assert!(b * a == c);
18521852
}
18531853

18541854
for elm in div_rem_quadruples.iter() {
1855-
let (aVec, bVec, cVec, dVec) = *elm;
1856-
let a = BigUint::from_slice(aVec);
1857-
let b = BigUint::from_slice(bVec);
1858-
let c = BigUint::from_slice(cVec);
1859-
let d = BigUint::from_slice(dVec);
1855+
let (a_vec, b_vec, c_vec, d_vec) = *elm;
1856+
let a = BigUint::from_slice(a_vec);
1857+
let b = BigUint::from_slice(b_vec);
1858+
let c = BigUint::from_slice(c_vec);
1859+
let d = BigUint::from_slice(d_vec);
18601860

18611861
assert!(a == b * c + d);
18621862
assert!(a == c * b + d);
@@ -1866,10 +1866,10 @@ mod biguint_tests {
18661866
#[test]
18671867
fn test_div_rem() {
18681868
for elm in mul_triples.iter() {
1869-
let (aVec, bVec, cVec) = *elm;
1870-
let a = BigUint::from_slice(aVec);
1871-
let b = BigUint::from_slice(bVec);
1872-
let c = BigUint::from_slice(cVec);
1869+
let (a_vec, b_vec, c_vec) = *elm;
1870+
let a = BigUint::from_slice(a_vec);
1871+
let b = BigUint::from_slice(b_vec);
1872+
let c = BigUint::from_slice(c_vec);
18731873

18741874
if !a.is_zero() {
18751875
assert_eq!(c.div_rem(&a), (b.clone(), Zero::zero()));
@@ -1880,11 +1880,11 @@ mod biguint_tests {
18801880
}
18811881

18821882
for elm in div_rem_quadruples.iter() {
1883-
let (aVec, bVec, cVec, dVec) = *elm;
1884-
let a = BigUint::from_slice(aVec);
1885-
let b = BigUint::from_slice(bVec);
1886-
let c = BigUint::from_slice(cVec);
1887-
let d = BigUint::from_slice(dVec);
1883+
let (a_vec, b_vec, c_vec, d_vec) = *elm;
1884+
let a = BigUint::from_slice(a_vec);
1885+
let b = BigUint::from_slice(b_vec);
1886+
let c = BigUint::from_slice(c_vec);
1887+
let d = BigUint::from_slice(d_vec);
18881888

18891889
if !b.is_zero() { assert!(a.div_rem(&b) == (c, d)); }
18901890
}
@@ -2351,10 +2351,10 @@ mod bigint_tests {
23512351
#[test]
23522352
fn test_add() {
23532353
for elm in sum_triples.iter() {
2354-
let (aVec, bVec, cVec) = *elm;
2355-
let a = BigInt::from_slice(Plus, aVec);
2356-
let b = BigInt::from_slice(Plus, bVec);
2357-
let c = BigInt::from_slice(Plus, cVec);
2354+
let (a_vec, b_vec, c_vec) = *elm;
2355+
let a = BigInt::from_slice(Plus, a_vec);
2356+
let b = BigInt::from_slice(Plus, b_vec);
2357+
let c = BigInt::from_slice(Plus, c_vec);
23582358

23592359
assert!(a + b == c);
23602360
assert!(b + a == c);
@@ -2370,10 +2370,10 @@ mod bigint_tests {
23702370
#[test]
23712371
fn test_sub() {
23722372
for elm in sum_triples.iter() {
2373-
let (aVec, bVec, cVec) = *elm;
2374-
let a = BigInt::from_slice(Plus, aVec);
2375-
let b = BigInt::from_slice(Plus, bVec);
2376-
let c = BigInt::from_slice(Plus, cVec);
2373+
let (a_vec, b_vec, c_vec) = *elm;
2374+
let a = BigInt::from_slice(Plus, a_vec);
2375+
let b = BigInt::from_slice(Plus, b_vec);
2376+
let c = BigInt::from_slice(Plus, c_vec);
23772377

23782378
assert!(c - a == b);
23792379
assert!(c - b == a);
@@ -2427,10 +2427,10 @@ mod bigint_tests {
24272427
#[test]
24282428
fn test_mul() {
24292429
for elm in mul_triples.iter() {
2430-
let (aVec, bVec, cVec) = *elm;
2431-
let a = BigInt::from_slice(Plus, aVec);
2432-
let b = BigInt::from_slice(Plus, bVec);
2433-
let c = BigInt::from_slice(Plus, cVec);
2430+
let (a_vec, b_vec, c_vec) = *elm;
2431+
let a = BigInt::from_slice(Plus, a_vec);
2432+
let b = BigInt::from_slice(Plus, b_vec);
2433+
let c = BigInt::from_slice(Plus, c_vec);
24342434

24352435
assert!(a * b == c);
24362436
assert!(b * a == c);
@@ -2440,11 +2440,11 @@ mod bigint_tests {
24402440
}
24412441

24422442
for elm in div_rem_quadruples.iter() {
2443-
let (aVec, bVec, cVec, dVec) = *elm;
2444-
let a = BigInt::from_slice(Plus, aVec);
2445-
let b = BigInt::from_slice(Plus, bVec);
2446-
let c = BigInt::from_slice(Plus, cVec);
2447-
let d = BigInt::from_slice(Plus, dVec);
2443+
let (a_vec, b_vec, c_vec, d_vec) = *elm;
2444+
let a = BigInt::from_slice(Plus, a_vec);
2445+
let b = BigInt::from_slice(Plus, b_vec);
2446+
let c = BigInt::from_slice(Plus, c_vec);
2447+
let d = BigInt::from_slice(Plus, d_vec);
24482448

24492449
assert!(a == b * c + d);
24502450
assert!(a == c * b + d);
@@ -2479,21 +2479,21 @@ mod bigint_tests {
24792479
}
24802480

24812481
for elm in mul_triples.iter() {
2482-
let (aVec, bVec, cVec) = *elm;
2483-
let a = BigInt::from_slice(Plus, aVec);
2484-
let b = BigInt::from_slice(Plus, bVec);
2485-
let c = BigInt::from_slice(Plus, cVec);
2482+
let (a_vec, b_vec, c_vec) = *elm;
2483+
let a = BigInt::from_slice(Plus, a_vec);
2484+
let b = BigInt::from_slice(Plus, b_vec);
2485+
let c = BigInt::from_slice(Plus, c_vec);
24862486

24872487
if !a.is_zero() { check(&c, &a, &b, &Zero::zero()); }
24882488
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
24892489
}
24902490

24912491
for elm in div_rem_quadruples.iter() {
2492-
let (aVec, bVec, cVec, dVec) = *elm;
2493-
let a = BigInt::from_slice(Plus, aVec);
2494-
let b = BigInt::from_slice(Plus, bVec);
2495-
let c = BigInt::from_slice(Plus, cVec);
2496-
let d = BigInt::from_slice(Plus, dVec);
2492+
let (a_vec, b_vec, c_vec, d_vec) = *elm;
2493+
let a = BigInt::from_slice(Plus, a_vec);
2494+
let b = BigInt::from_slice(Plus, b_vec);
2495+
let c = BigInt::from_slice(Plus, c_vec);
2496+
let d = BigInt::from_slice(Plus, d_vec);
24972497

24982498
if !b.is_zero() {
24992499
check(&a, &b, &c, &d);
@@ -2522,21 +2522,21 @@ mod bigint_tests {
25222522
check_sub(&a.neg(), &b.neg(), q, &r.neg());
25232523
}
25242524
for elm in mul_triples.iter() {
2525-
let (aVec, bVec, cVec) = *elm;
2526-
let a = BigInt::from_slice(Plus, aVec);
2527-
let b = BigInt::from_slice(Plus, bVec);
2528-
let c = BigInt::from_slice(Plus, cVec);
2525+
let (a_vec, b_vec, c_vec) = *elm;
2526+
let a = BigInt::from_slice(Plus, a_vec);
2527+
let b = BigInt::from_slice(Plus, b_vec);
2528+
let c = BigInt::from_slice(Plus, c_vec);
25292529

25302530
if !a.is_zero() { check(&c, &a, &b, &Zero::zero()); }
25312531
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
25322532
}
25332533

25342534
for elm in div_rem_quadruples.iter() {
2535-
let (aVec, bVec, cVec, dVec) = *elm;
2536-
let a = BigInt::from_slice(Plus, aVec);
2537-
let b = BigInt::from_slice(Plus, bVec);
2538-
let c = BigInt::from_slice(Plus, cVec);
2539-
let d = BigInt::from_slice(Plus, dVec);
2535+
let (a_vec, b_vec, c_vec, d_vec) = *elm;
2536+
let a = BigInt::from_slice(Plus, a_vec);
2537+
let b = BigInt::from_slice(Plus, b_vec);
2538+
let c = BigInt::from_slice(Plus, c_vec);
2539+
let d = BigInt::from_slice(Plus, d_vec);
25402540

25412541
if !b.is_zero() {
25422542
check(&a, &b, &c, &d);

src/librustc/back/link.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
6868

6969
pub fn WriteOutputFile(
7070
sess: Session,
71-
Target: lib::llvm::TargetMachineRef,
72-
PM: lib::llvm::PassManagerRef,
73-
M: ModuleRef,
74-
Output: &Path,
75-
FileType: lib::llvm::FileType) {
71+
target: lib::llvm::TargetMachineRef,
72+
pm: lib::llvm::PassManagerRef,
73+
m: ModuleRef,
74+
output: &Path,
75+
file_type: lib::llvm::FileType) {
7676
unsafe {
77-
Output.with_c_str(|Output| {
77+
output.with_c_str(|output| {
7878
let result = llvm::LLVMRustWriteOutputFile(
79-
Target, PM, M, Output, FileType);
79+
target, pm, m, output, file_type);
8080
if !result {
8181
llvm_err(sess, ~"could not write output");
8282
}
@@ -138,7 +138,7 @@ pub mod write {
138138
})
139139
}
140140

141-
let OptLevel = match sess.opts.optimize {
141+
let opt_level = match sess.opts.optimize {
142142
session::No => lib::llvm::CodeGenLevelNone,
143143
session::Less => lib::llvm::CodeGenLevelLess,
144144
session::Default => lib::llvm::CodeGenLevelDefault,
@@ -152,14 +152,14 @@ pub mod write {
152152
(sess.targ_cfg.os == abi::OsMacos &&
153153
sess.targ_cfg.arch == abi::X86_64);
154154

155-
let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|T| {
156-
sess.opts.cg.target_cpu.with_c_str(|CPU| {
157-
target_feature(&sess).with_c_str(|Features| {
155+
let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|t| {
156+
sess.opts.cg.target_cpu.with_c_str(|cpu| {
157+
target_feature(&sess).with_c_str(|features| {
158158
llvm::LLVMRustCreateTargetMachine(
159-
T, CPU, Features,
159+
t, cpu, features,
160160
lib::llvm::CodeModelDefault,
161161
lib::llvm::RelocPIC,
162-
OptLevel,
162+
opt_level,
163163
true,
164164
use_softfp,
165165
no_fp_elim
@@ -185,7 +185,7 @@ pub mod write {
185185
if !sess.opts.cg.no_prepopulate_passes {
186186
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
187187
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);
188-
populate_llvm_passes(fpm, mpm, llmod, OptLevel);
188+
populate_llvm_passes(fpm, mpm, llmod, opt_level);
189189
}
190190

191191
for pass in sess.opts.cg.passes.iter() {

0 commit comments

Comments
 (0)