From 5615aceff0f44f7ac6ec0c51800b162804e22453 Mon Sep 17 00:00:00 2001 From: Samuel Neves Date: Fri, 19 Sep 2014 06:33:52 +0100 Subject: [PATCH 01/14] Include ChaCha pseudorandom generator --- src/librand/chacha.rs | 285 +++++++++++++++++++++++++++++++++++++++++ src/librand/lib.rs | 2 + src/libstd/rand/mod.rs | 2 +- 3 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 src/librand/chacha.rs diff --git a/src/librand/chacha.rs b/src/librand/chacha.rs new file mode 100644 index 0000000000000..df33e6e2ced0c --- /dev/null +++ b/src/librand/chacha.rs @@ -0,0 +1,285 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! The ChaCha random number generator. + +use core::prelude::*; + +use {Rng, SeedableRng, Rand}; + +static KEY_WORDS : uint = 8; // 8 words for the 256-bit key +static STATE_WORDS : uint = 16; +static CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of this writing + +/// A random number generator that uses the ChaCha20 algorithm [1]. +/// +/// The ChaCha algorithm is widely accepted as suitable for +/// cryptographic purposes, but this implementation has not been +/// verified as such. Prefer a generator like `OsRng` that defers to +/// the operating system for cases that need high security. +/// +/// [1]: D. J. Bernstein, [*ChaCha, a variant of +/// Salsa20*](http://cr.yp.to/chacha.html) + +pub struct ChaChaRng { + buffer: [u32, ..STATE_WORDS], // Internal buffer of output + state: [u32, ..STATE_WORDS], // Initial state + index: uint, // Index into state +} + +static EMPTY: ChaChaRng = ChaChaRng { + buffer: [0, ..STATE_WORDS], + state: [0, ..STATE_WORDS], + index: STATE_WORDS +}; + + +macro_rules! quarter_round{ + ($a: expr, $b: expr, $c: expr, $d: expr) => {{ + $a += $b; $d ^= $a; $d = $d.rotate_left(16); + $c += $d; $b ^= $c; $b = $b.rotate_left(12); + $a += $b; $d ^= $a; $d = $d.rotate_left( 8); + $c += $d; $b ^= $c; $b = $b.rotate_left( 7); + }} +} + +macro_rules! double_round{ + ($x: expr) => {{ + // Column round + quarter_round!($x[ 0], $x[ 4], $x[ 8], $x[12]); + quarter_round!($x[ 1], $x[ 5], $x[ 9], $x[13]); + quarter_round!($x[ 2], $x[ 6], $x[10], $x[14]); + quarter_round!($x[ 3], $x[ 7], $x[11], $x[15]); + // Diagonal round + quarter_round!($x[ 0], $x[ 5], $x[10], $x[15]); + quarter_round!($x[ 1], $x[ 6], $x[11], $x[12]); + quarter_round!($x[ 2], $x[ 7], $x[ 8], $x[13]); + quarter_round!($x[ 3], $x[ 4], $x[ 9], $x[14]); + }} +} + +#[inline] +fn core(output: &mut [u32, ..STATE_WORDS], input: &[u32, ..STATE_WORDS]) { + *output = *input; + + for _ in range(0, CHACHA_ROUNDS / 2) { + double_round!(output); + } + + for i in range(0, STATE_WORDS) { + output[i] += input[i]; + } +} + +impl ChaChaRng { + + /// Create an ChaCha random number generator using the default + /// fixed key of 8 zero words. + pub fn new_unseeded() -> ChaChaRng { + let mut rng = EMPTY; + rng.init(&[0, ..KEY_WORDS]); + rng + } + + /// Sets the internal 128-bit ChaCha counter to + /// a user-provided value. This permits jumping + /// arbitrarily ahead (or backwards) in the pseudorandom stream. + /// + /// Since the nonce words are used to extend the counter to 128 bits, + /// users wishing to obtain the conventional ChaCha pseudorandom stream + /// associated with a particular nonce can call this function with + /// arguments `0, desired_nonce`. + pub fn set_counter(&mut self, counter_low: u64, counter_high: u64) { + self.state[12] = (counter_low >> 0) as u32; + self.state[13] = (counter_low >> 32) as u32; + self.state[14] = (counter_high >> 0) as u32; + self.state[15] = (counter_high >> 32) as u32; + self.index = STATE_WORDS; // force recomputation + } + + /// Initializes `self.state` with the appropriate key and constants + /// + /// We deviate slightly from the ChaCha specification regarding + /// the nonce, which is used to extend the counter to 128 bits. + /// This is provably as strong as the original cipher, though, + /// since any distinguishing attack on our variant also works + /// against ChaCha with a chosen-nonce. See the XSalsa20 [1] + /// security proof for a more involved example of this. + /// + /// The modified word layout is: + /// ```notrust + /// constant constant constant constant + /// key key key key + /// key key key key + /// counter counter counter counter + /// ``` + /// [1]: Daniel J. Bernstein. [*Extending the Salsa20 + /// nonce.*](http://cr.yp.to/papers.html#xsalsa) + fn init(&mut self, key: &[u32, ..KEY_WORDS]) { + self.state[0] = 0x61707865; + self.state[1] = 0x3320646E; + self.state[2] = 0x79622D32; + self.state[3] = 0x6B206574; + + for i in range(0, KEY_WORDS) { + self.state[4+i] = key[i]; + } + + self.state[12] = 0; + self.state[13] = 0; + self.state[14] = 0; + self.state[15] = 0; + + self.index = STATE_WORDS; + } + + /// Refill the internal output buffer (`self.buffer`) + fn update(&mut self) { + core(&mut self.buffer, &self.state); + self.index = 0; + // update 128-bit counter + self.state[12] += 1; + if self.state[12] != 0 { return }; + self.state[13] += 1; + if self.state[13] != 0 { return }; + self.state[14] += 1; + if self.state[14] != 0 { return }; + self.state[15] += 1; + } +} + +impl Rng for ChaChaRng { + #[inline] + fn next_u32(&mut self) -> u32 { + if self.index == STATE_WORDS { + self.update(); + } + + let value = self.buffer[self.index % STATE_WORDS]; + self.index += 1; + value + } +} + +impl<'a> SeedableRng<&'a [u32]> for ChaChaRng { + + fn reseed(&mut self, seed: &'a [u32]) { + // reset state + self.init(&[0u32, ..KEY_WORDS]); + // set key inplace + let key = self.state.slice_mut(4, 4+KEY_WORDS); + for (k, s) in key.iter_mut().zip(seed.iter()) { + *k = *s; + } + } + + /// Create a ChaCha generator from a seed, + /// obtained from a variable-length u32 array. + /// Only up to 8 words are used; if less than 8 + /// words are used, the remaining are set to zero. + fn from_seed(seed: &'a [u32]) -> ChaChaRng { + let mut rng = EMPTY; + rng.reseed(seed); + rng + } +} + +impl Rand for ChaChaRng { + fn rand(other: &mut R) -> ChaChaRng { + let mut key : [u32, ..KEY_WORDS] = [0, ..KEY_WORDS]; + for word in key.iter_mut() { + *word = other.gen(); + } + SeedableRng::from_seed(key.as_slice()) + } +} + + +#[cfg(test)] +mod test { + use std::prelude::*; + + use core::iter::order; + use {Rng, SeedableRng}; + use super::ChaChaRng; + + #[test] + fn test_rng_rand_seeded() { + let s = ::test::rng().gen_iter::().take(8).collect::>(); + let mut ra: ChaChaRng = SeedableRng::from_seed(s.as_slice()); + let mut rb: ChaChaRng = SeedableRng::from_seed(s.as_slice()); + assert!(order::equals(ra.gen_ascii_chars().take(100), + rb.gen_ascii_chars().take(100))); + } + + #[test] + fn test_rng_seeded() { + let seed : &[_] = &[0,1,2,3,4,5,6,7]; + let mut ra: ChaChaRng = SeedableRng::from_seed(seed); + let mut rb: ChaChaRng = SeedableRng::from_seed(seed); + assert!(order::equals(ra.gen_ascii_chars().take(100), + rb.gen_ascii_chars().take(100))); + } + + #[test] + fn test_rng_reseed() { + let s = ::test::rng().gen_iter::().take(8).collect::>(); + let mut r: ChaChaRng = SeedableRng::from_seed(s.as_slice()); + let string1: String = r.gen_ascii_chars().take(100).collect(); + + r.reseed(s.as_slice()); + + let string2: String = r.gen_ascii_chars().take(100).collect(); + assert_eq!(string1, string2); + } + + #[test] + fn test_rng_true_values() { + // Test vectors 1 and 2 from + // http://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04 + let seed : &[_] = &[0u32, ..8]; + let mut ra: ChaChaRng = SeedableRng::from_seed(seed); + + let v = Vec::from_fn(16, |_| ra.next_u32()); + assert_eq!(v, + vec!(0xade0b876, 0x903df1a0, 0xe56a5d40, 0x28bd8653, + 0xb819d2bd, 0x1aed8da0, 0xccef36a8, 0xc70d778b, + 0x7c5941da, 0x8d485751, 0x3fe02477, 0x374ad8b8, + 0xf4b8436a, 0x1ca11815, 0x69b687c3, 0x8665eeb2)); + + let v = Vec::from_fn(16, |_| ra.next_u32()); + assert_eq!(v, + vec!(0xbee7079f, 0x7a385155, 0x7c97ba98, 0x0d082d73, + 0xa0290fcb, 0x6965e348, 0x3e53c612, 0xed7aee32, + 0x7621b729, 0x434ee69c, 0xb03371d5, 0xd539d874, + 0x281fed31, 0x45fb0a51, 0x1f0ae1ac, 0x6f4d794b)); + + + let seed : &[_] = &[0,1,2,3,4,5,6,7]; + let mut ra: ChaChaRng = SeedableRng::from_seed(seed); + + // Store the 17*i-th 32-bit word, + // i.e., the i-th word of the i-th 16-word block + let mut v : Vec = Vec::new(); + for _ in range(0u, 16) { + v.push(ra.next_u32()); + for _ in range(0u, 16) { + ra.next_u32(); + } + } + + assert_eq!(v, + vec!(0xf225c81a, 0x6ab1be57, 0x04d42951, 0x70858036, + 0x49884684, 0x64efec72, 0x4be2d186, 0x3615b384, + 0x11cfa18e, 0xd3c50049, 0x75c775f6, 0x434c6530, + 0x2c5bad8f, 0x898881dc, 0x5f1c86d9, 0xc1f8e7f4)); + } +} + diff --git a/src/librand/lib.rs b/src/librand/lib.rs index f8a775478f1f8..3319e75a628b6 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -39,6 +39,7 @@ extern crate core; use core::prelude::*; pub use isaac::{IsaacRng, Isaac64Rng}; +pub use chacha::ChaChaRng; use distributions::{Range, IndependentSample}; use distributions::range::SampleRange; @@ -48,6 +49,7 @@ static RAND_BENCH_N: u64 = 100; pub mod distributions; pub mod isaac; +pub mod chacha; pub mod reseeding; mod rand_impls; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 4b3ddc2f95332..29eae0ced5412 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -233,7 +233,7 @@ use core_rand::IsaacRng as IsaacWordRng; use core_rand::Isaac64Rng as IsaacWordRng; pub use core_rand::{Rand, Rng, SeedableRng, Open01, Closed01}; -pub use core_rand::{XorShiftRng, IsaacRng, Isaac64Rng}; +pub use core_rand::{XorShiftRng, IsaacRng, Isaac64Rng, ChaChaRng}; pub use core_rand::{distributions, reseeding}; pub use rand::os::OsRng; From 06a6ba1d6fb37602cd3dff53491f96dc59aa3d94 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 2 Oct 2014 19:33:38 -0700 Subject: [PATCH 02/14] test: Don't depend on /bin/bash Our FreeBSD bots apparently don't have bash installed, and it's ok to run with sh anyway! Unblocks a snapshot --- src/test/run-make/rustdoc-where/verify.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/rustdoc-where/verify.sh b/src/test/run-make/rustdoc-where/verify.sh index 5d424da02adb9..1d49823101855 100755 --- a/src/test/run-make/rustdoc-where/verify.sh +++ b/src/test/run-make/rustdoc-where/verify.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e # $1 is the TMPDIR From 7e22af3582aa4a8dcb5b2ac00c7914ef78d2486e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 2 Oct 2014 15:06:08 -0700 Subject: [PATCH 03/14] syntax: Enable parsing of `const` globals This rewrites them to the current `ItemStatic` production of the compiler, but I want to get this into a snapshot. It will be illegal to use a `static` in a pattern of a `match` statement, so all those current uses will need to be rewritten to `const` once it's implemented. This requires that the stage0 snapshot is able to parse `const`. cc #17718 --- src/libsyntax/parse/parser.rs | 24 ++++++++++++++++--- .../compile-fail/issue-17718-const-mut.rs | 17 +++++++++++++ src/test/run-pass/issue-17718-parse-const.rs | 15 ++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/issue-17718-const-mut.rs create mode 100644 src/test/run-pass/issue-17718-parse-const.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c8f1b7f9a8e6d..8d70dd3e1a866 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4746,8 +4746,7 @@ impl<'a> Parser<'a> { } } - fn parse_item_const(&mut self) -> ItemInfo { - let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; + fn parse_item_const(&mut self, m: Mutability) -> ItemInfo { let id = self.parse_ident(); self.expect(&token::COLON); let ty = self.parse_ty(true); @@ -5303,7 +5302,26 @@ impl<'a> Parser<'a> { if self.is_keyword(keywords::Static) { // STATIC ITEM self.bump(); - let (ident, item_, extra_attrs) = self.parse_item_const(); + let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; + let (ident, item_, extra_attrs) = self.parse_item_const(m); + let last_span = self.last_span; + let item = self.mk_item(lo, + last_span.hi, + ident, + item_, + visibility, + maybe_append(attrs, extra_attrs)); + return IoviItem(item); + } + if self.is_keyword(keywords::Const) { + // CONST ITEM + self.bump(); + if self.eat_keyword(keywords::Mut) { + let last_span = self.last_span; + self.span_err(last_span, "const globals cannot be mutable, \ + did you mean to declare a static?"); + } + let (ident, item_, extra_attrs) = self.parse_item_const(MutImmutable); let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, diff --git a/src/test/compile-fail/issue-17718-const-mut.rs b/src/test/compile-fail/issue-17718-const-mut.rs new file mode 100644 index 0000000000000..31a5fee2044dc --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-mut.rs @@ -0,0 +1,17 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const +mut //~ ERROR: const globals cannot be mutable, did you mean to declare a static? +FOO: uint = 3; + +fn main() { +} + diff --git a/src/test/run-pass/issue-17718-parse-const.rs b/src/test/run-pass/issue-17718-parse-const.rs new file mode 100644 index 0000000000000..3ca6f473a7900 --- /dev/null +++ b/src/test/run-pass/issue-17718-parse-const.rs @@ -0,0 +1,15 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const FOO: uint = 3; + +fn main() { + assert_eq!(FOO, 3); +} From 94bcd3539c761b4ecf423800bce21057c4e961fa Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 13 Sep 2014 13:55:37 +1200 Subject: [PATCH 04/14] Set the `non_uppercase_statics` lint to warn by default --- src/libnum/bigint.rs | 63 +++--- src/libnum/rational.rs | 3 + src/librand/reseeding.rs | 6 +- src/librustc/driver/config.rs | 2 + src/librustc/lint/builtin.rs | 2 +- src/librustc/lint/mod.rs | 1 + src/librustc/metadata/common.rs | 2 +- src/librustc/metadata/encoder.rs | 1 + src/librustc/middle/borrowck/move_data.rs | 2 + src/librustc/middle/graph.rs | 4 + src/librustc/middle/trans/adt.rs | 2 + src/librustc/middle/trans/builder.rs | 4 +- src/librustc/middle/trans/debuginfo.rs | 7 + src/librustc/middle/ty.rs | 6 +- src/librustc/middle/typeck/infer/resolve.rs | 2 + src/librustc_back/abi.rs | 2 + src/librustrt/c_str.rs | 30 +-- src/librustrt/libunwind.rs | 1 + src/librustrt/local_data.rs | 214 +++++++++--------- src/librustrt/mutex.rs | 8 +- src/librustrt/util.rs | 2 + src/libserialize/json.rs | 2 + src/libstd/bitflags.rs | 10 +- src/libstd/io/process.rs | 1 + src/libstd/macros.rs | 2 + src/libstd/path/posix.rs | 2 + src/libstd/task.rs | 4 +- src/libsyntax/abi.rs | 3 + src/libsyntax/ast_util.rs | 1 + src/libsyntax/parse/token.rs | 7 +- src/libsyntax/print/pprust.rs | 2 + src/libuuid/lib.rs | 1 + .../syntax-extension-regex-unused-static.rs | 1 + src/test/compile-fail/asm-misplaced-option.rs | 2 +- src/test/compile-fail/issue-6804.rs | 2 +- src/test/compile-fail/lint-dead-code-1.rs | 1 + ...int-directives-on-use-items-issue-10534.rs | 1 + 37 files changed, 234 insertions(+), 172 deletions(-) diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index efa3402073f2e..82d320d570223 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -86,9 +86,12 @@ pub mod BigDigit { use super::DoubleBigDigit; // `DoubleBigDigit` size dependent + #[allow(non_uppercase_statics)] pub static bits: uint = 32; + #[allow(non_uppercase_statics)] pub static base: DoubleBigDigit = 1 << bits; + #[allow(non_uppercase_statics)] static lo_mask: DoubleBigDigit = (-1 as DoubleBigDigit) >> bits; #[inline] @@ -1841,7 +1844,7 @@ mod biguint_tests { BigInt::from_biguint(Plus, BigUint::new(vec!(1,2,3)))); } - static sum_triples: &'static [(&'static [BigDigit], + static SUM_TRIPLES: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] = &[ (&[], &[], &[]), @@ -1857,7 +1860,7 @@ mod biguint_tests { #[test] fn test_add() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -1870,7 +1873,7 @@ mod biguint_tests { #[test] fn test_sub() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -1888,7 +1891,7 @@ mod biguint_tests { a - b; } - static mul_triples: &'static [(&'static [BigDigit], + static MUL_TRIPLES: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] = &[ (&[], &[], &[]), @@ -1914,7 +1917,7 @@ mod biguint_tests { (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) ]; - static div_rem_quadruples: &'static [(&'static [BigDigit], + static DIV_REM_QUADRUPLES: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] @@ -1928,7 +1931,7 @@ mod biguint_tests { #[test] fn test_mul() { - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -1938,7 +1941,7 @@ mod biguint_tests { assert!(b * a == c); } - for elm in div_rem_quadruples.iter() { + for elm in DIV_REM_QUADRUPLES.iter() { let (a_vec, b_vec, c_vec, d_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -1952,7 +1955,7 @@ mod biguint_tests { #[test] fn test_div_rem() { - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -1966,7 +1969,7 @@ mod biguint_tests { } } - for elm in div_rem_quadruples.iter() { + for elm in DIV_REM_QUADRUPLES.iter() { let (a_vec, b_vec, c_vec, d_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -1979,7 +1982,7 @@ mod biguint_tests { #[test] fn test_checked_add() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -1992,7 +1995,7 @@ mod biguint_tests { #[test] fn test_checked_sub() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -2012,7 +2015,7 @@ mod biguint_tests { #[test] fn test_checked_mul() { - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -2022,7 +2025,7 @@ mod biguint_tests { assert!(b.checked_mul(&a).unwrap() == c); } - for elm in div_rem_quadruples.iter() { + for elm in DIV_REM_QUADRUPLES.iter() { let (a_vec, b_vec, c_vec, d_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -2036,7 +2039,7 @@ mod biguint_tests { #[test] fn test_checked_div() { - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigUint::from_slice(a_vec); let b = BigUint::from_slice(b_vec); @@ -2440,7 +2443,7 @@ mod bigint_tests { assert_eq!(negative.to_biguint(), None); } - static sum_triples: &'static [(&'static [BigDigit], + static SUM_TRIPLES: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] = &[ (&[], &[], &[]), @@ -2456,7 +2459,7 @@ mod bigint_tests { #[test] fn test_add() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2475,7 +2478,7 @@ mod bigint_tests { #[test] fn test_sub() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2492,7 +2495,7 @@ mod bigint_tests { } } - static mul_triples: &'static [(&'static [BigDigit], + static MUL_TRIPLES: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] = &[ (&[], &[], &[]), @@ -2518,7 +2521,7 @@ mod bigint_tests { (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) ]; - static div_rem_quadruples: &'static [(&'static [BigDigit], + static DIV_REM_QUADRUPLES: &'static [(&'static [BigDigit], &'static [BigDigit], &'static [BigDigit], &'static [BigDigit])] @@ -2532,7 +2535,7 @@ mod bigint_tests { #[test] fn test_mul() { - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2545,7 +2548,7 @@ mod bigint_tests { assert!((-b) * a == -c); } - for elm in div_rem_quadruples.iter() { + for elm in DIV_REM_QUADRUPLES.iter() { let (a_vec, b_vec, c_vec, d_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2584,7 +2587,7 @@ mod bigint_tests { } } - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2594,7 +2597,7 @@ mod bigint_tests { if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); } } - for elm in div_rem_quadruples.iter() { + for elm in DIV_REM_QUADRUPLES.iter() { let (a_vec, b_vec, c_vec, d_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2627,7 +2630,7 @@ mod bigint_tests { check_sub(&a.neg(), b, &q.neg(), &r.neg()); check_sub(&a.neg(), &b.neg(), q, &r.neg()); } - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2637,7 +2640,7 @@ mod bigint_tests { if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); } } - for elm in div_rem_quadruples.iter() { + for elm in DIV_REM_QUADRUPLES.iter() { let (a_vec, b_vec, c_vec, d_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2652,7 +2655,7 @@ mod bigint_tests { #[test] fn test_checked_add() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2671,7 +2674,7 @@ mod bigint_tests { #[test] fn test_checked_sub() { - for elm in sum_triples.iter() { + for elm in SUM_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2690,7 +2693,7 @@ mod bigint_tests { #[test] fn test_checked_mul() { - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2703,7 +2706,7 @@ mod bigint_tests { assert!((-b).checked_mul(&a).unwrap() == -c); } - for elm in div_rem_quadruples.iter() { + for elm in DIV_REM_QUADRUPLES.iter() { let (a_vec, b_vec, c_vec, d_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); @@ -2716,7 +2719,7 @@ mod bigint_tests { } #[test] fn test_checked_div() { - for elm in mul_triples.iter() { + for elm in MUL_TRIPLES.iter() { let (a_vec, b_vec, c_vec) = *elm; let a = BigInt::from_slice(Plus, a_vec); let b = BigInt::from_slice(Plus, b_vec); diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index 2e13d5f0148d2..ceaf685c19a51 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -406,10 +406,13 @@ mod test { pub static _2: Rational = Ratio { numer: 2, denom: 1}; pub static _1_2: Rational = Ratio { numer: 1, denom: 2}; pub static _3_2: Rational = Ratio { numer: 3, denom: 2}; + #[allow(non_uppercase_statics)] pub static _neg1_2: Rational = Ratio { numer: -1, denom: 2}; pub static _1_3: Rational = Ratio { numer: 1, denom: 3}; + #[allow(non_uppercase_statics)] pub static _neg1_3: Rational = Ratio { numer: -1, denom: 3}; pub static _2_3: Rational = Ratio { numer: 2, denom: 3}; + #[allow(non_uppercase_statics)] pub static _neg2_3: Rational = Ratio { numer: -2, denom: 3}; pub fn to_big(n: Rational) -> BigRational { diff --git a/src/librand/reseeding.rs b/src/librand/reseeding.rs index 7a237670890ca..64c6b1739ebb1 100644 --- a/src/librand/reseeding.rs +++ b/src/librand/reseeding.rs @@ -209,15 +209,15 @@ mod test { assert_eq!(string1, string2); } - static fill_bytes_v_len: uint = 13579; + static FILL_BYTES_V_LEN: uint = 13579; #[test] fn test_rng_fill_bytes() { - let mut v = Vec::from_elem(fill_bytes_v_len, 0u8); + let mut v = Vec::from_elem(FILL_BYTES_V_LEN, 0u8); ::test::rng().fill_bytes(v.as_mut_slice()); // Sanity test: if we've gotten here, `fill_bytes` has not infinitely // recursed. - assert_eq!(v.len(), fill_bytes_v_len); + assert_eq!(v.len(), FILL_BYTES_V_LEN); // To test that `fill_bytes` actually did something, check that the // average of `v` is not 0. diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index daa4a6ad75257..9804382dbd91d 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -494,6 +494,7 @@ pub fn get_os(triple: &str) -> Option { } None } +#[allow(non_uppercase_statics)] static os_names : &'static [(&'static str, abi::Os)] = &[ ("mingw32", abi::OsWindows), ("win32", abi::OsWindows), @@ -511,6 +512,7 @@ pub fn get_arch(triple: &str) -> Option { } None } +#[allow(non_uppercase_statics)] static architecture_abis : &'static [(&'static str, abi::Architecture)] = &[ ("i386", abi::X86), ("i486", abi::X86), diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 213e8b44813a0..7a59aeb57895d 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -961,7 +961,7 @@ impl LintPass for NonSnakeCase { } } -declare_lint!(pub NON_UPPERCASE_STATICS, Allow, +declare_lint!(pub NON_UPPERCASE_STATICS, Warn, "static constants should have uppercase identifiers") pub struct NonUppercaseStatics; diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 9a3edbbb70bb0..8047c12efc291 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -98,6 +98,7 @@ macro_rules! declare_lint ( #[macro_export] macro_rules! lint_array ( ($( $lint:expr ),*) => ( { + #[allow(non_uppercase_statics)] static array: LintArray = &[ $( $lint ),* ]; array } diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 2a8aa791c61a6..ef88795762e43 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_camel_case_types)] +#![allow(non_camel_case_types, non_uppercase_statics)] use std::mem; use back::svh::Svh; diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index de0c36f2af33a..642f66e259a62 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -2028,6 +2028,7 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) { } // NB: Increment this as you change the metadata encoding version. +#[allow(non_uppercase_statics)] pub static metadata_encoding_version : &'static [u8] = &[b'r', b'u', b's', b't', 0, 0, 0, 1 ]; pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec { diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 5cc58eb264e07..eda145419616b 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -83,6 +83,7 @@ impl Clone for MovePathIndex { } } +#[allow(non_uppercase_statics)] static InvalidMovePathIndex: MovePathIndex = MovePathIndex(uint::MAX); @@ -96,6 +97,7 @@ impl MoveIndex { } } +#[allow(non_uppercase_statics)] static InvalidMoveIndex: MoveIndex = MoveIndex(uint::MAX); diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 2c79c655a9992..9135ca07935a5 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -57,16 +57,20 @@ pub struct Edge { #[deriving(Clone, PartialEq, Show)] pub struct NodeIndex(pub uint); +#[allow(non_uppercase_statics)] pub static InvalidNodeIndex: NodeIndex = NodeIndex(uint::MAX); #[deriving(PartialEq)] pub struct EdgeIndex(pub uint); +#[allow(non_uppercase_statics)] pub static InvalidEdgeIndex: EdgeIndex = EdgeIndex(uint::MAX); // Use a private field here to guarantee no more instances are created: #[deriving(Show)] pub struct Direction { repr: uint } +#[allow(non_uppercase_statics)] pub static Outgoing: Direction = Direction { repr: 0 }; +#[allow(non_uppercase_statics)] pub static Incoming: Direction = Direction { repr: 1 }; impl NodeIndex { diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 506b12de08467..f88b010c28a35 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -389,10 +389,12 @@ fn mk_cenum(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> Repr { fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntType { debug!("range_to_inttype: {:?} {:?}", hint, bounds); // Lists of sizes to try. u64 is always allowed as a fallback. + #[allow(non_uppercase_statics)] static choose_shortest: &'static[IntType] = &[ attr::UnsignedInt(ast::TyU8), attr::SignedInt(ast::TyI8), attr::UnsignedInt(ast::TyU16), attr::SignedInt(ast::TyI16), attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)]; + #[allow(non_uppercase_statics)] static at_least_32: &'static[IntType] = &[ attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)]; diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index e95f640b44869..0cd8510b750ac 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -31,8 +31,8 @@ pub struct Builder<'a, 'tcx: 'a> { // This is a really awful way to get a zero-length c-string, but better (and a // lot more efficient) than doing str::as_c_str("", ...) every time. pub fn noname() -> *const c_char { - static cnull: c_char = 0; - &cnull as *const c_char + static CNULL: c_char = 0; + &CNULL as *const c_char } impl<'a, 'tcx> Builder<'a, 'tcx> { diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 8920994fd9585..55e34ad48cd0c 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -218,13 +218,20 @@ use syntax::parse::token::special_idents; static DW_LANG_RUST: c_uint = 0x9000; +#[allow(non_uppercase_statics)] static DW_TAG_auto_variable: c_uint = 0x100; +#[allow(non_uppercase_statics)] static DW_TAG_arg_variable: c_uint = 0x101; +#[allow(non_uppercase_statics)] static DW_ATE_boolean: c_uint = 0x02; +#[allow(non_uppercase_statics)] static DW_ATE_float: c_uint = 0x04; +#[allow(non_uppercase_statics)] static DW_ATE_signed: c_uint = 0x05; +#[allow(non_uppercase_statics)] static DW_ATE_unsigned: c_uint = 0x07; +#[allow(non_uppercase_statics)] static DW_ATE_unsigned_char: c_uint = 0x08; static UNKNOWN_LINE_NUMBER: c_uint = 0; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index edbdf427c0bc6..df92251c87e30 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2197,7 +2197,10 @@ macro_rules! def_type_content_sets( #[allow(non_snake_case)] mod $mname { use middle::ty::TypeContents; - $(pub static $name: TypeContents = TypeContents { bits: $bits };)+ + $( + #[allow(non_uppercase_statics)] + pub static $name: TypeContents = TypeContents { bits: $bits }; + )+ } } ) @@ -4650,6 +4653,7 @@ pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId) } pub fn is_binopable(cx: &ctxt, ty: t, op: ast::BinOp) -> bool { + #![allow(non_uppercase_statics)] static tycat_other: int = 0; static tycat_bool: int = 1; static tycat_char: int = 2; diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index 2c0b2dbe2ba79..13659d4b77e1c 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -46,6 +46,8 @@ // future). If you want to resolve everything but one type, you are // probably better off writing `resolve_all - resolve_ivar`. +#![allow(non_uppercase_statics)] + use middle::ty::{FloatVar, FloatVid, IntVar, IntVid, RegionVid, TyVar, TyVid}; use middle::ty::{IntType, UintType}; use middle::ty; diff --git a/src/librustc_back/abi.rs b/src/librustc_back/abi.rs index 72acba542460c..1e69ce003c557 100644 --- a/src/librustc_back/abi.rs +++ b/src/librustc_back/abi.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(non_uppercase_statics)] + pub static box_field_refcnt: uint = 0u; pub static box_field_drop_glue: uint = 1u; pub static box_field_body: uint = 4u; diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 04a4e96ecc40e..934fb0ddd3ce4 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -733,9 +733,9 @@ mod bench { } } - static s_short: &'static str = "Mary"; - static s_medium: &'static str = "Mary had a little lamb"; - static s_long: &'static str = "\ + static S_SHORT: &'static str = "Mary"; + static S_MEDIUM: &'static str = "Mary had a little lamb"; + static S_LONG: &'static str = "\ Mary had a little lamb, Little lamb Mary had a little lamb, Little lamb Mary had a little lamb, Little lamb @@ -752,17 +752,17 @@ mod bench { #[bench] fn bench_to_c_str_short(b: &mut Bencher) { - bench_to_string(b, s_short) + bench_to_string(b, S_SHORT) } #[bench] fn bench_to_c_str_medium(b: &mut Bencher) { - bench_to_string(b, s_medium) + bench_to_string(b, S_MEDIUM) } #[bench] fn bench_to_c_str_long(b: &mut Bencher) { - bench_to_string(b, s_long) + bench_to_string(b, S_LONG) } fn bench_to_c_str_unchecked(b: &mut Bencher, s: &str) { @@ -774,17 +774,17 @@ mod bench { #[bench] fn bench_to_c_str_unchecked_short(b: &mut Bencher) { - bench_to_c_str_unchecked(b, s_short) + bench_to_c_str_unchecked(b, S_SHORT) } #[bench] fn bench_to_c_str_unchecked_medium(b: &mut Bencher) { - bench_to_c_str_unchecked(b, s_medium) + bench_to_c_str_unchecked(b, S_MEDIUM) } #[bench] fn bench_to_c_str_unchecked_long(b: &mut Bencher) { - bench_to_c_str_unchecked(b, s_long) + bench_to_c_str_unchecked(b, S_LONG) } fn bench_with_c_str(b: &mut Bencher, s: &str) { @@ -795,17 +795,17 @@ mod bench { #[bench] fn bench_with_c_str_short(b: &mut Bencher) { - bench_with_c_str(b, s_short) + bench_with_c_str(b, S_SHORT) } #[bench] fn bench_with_c_str_medium(b: &mut Bencher) { - bench_with_c_str(b, s_medium) + bench_with_c_str(b, S_MEDIUM) } #[bench] fn bench_with_c_str_long(b: &mut Bencher) { - bench_with_c_str(b, s_long) + bench_with_c_str(b, S_LONG) } fn bench_with_c_str_unchecked(b: &mut Bencher, s: &str) { @@ -818,16 +818,16 @@ mod bench { #[bench] fn bench_with_c_str_unchecked_short(b: &mut Bencher) { - bench_with_c_str_unchecked(b, s_short) + bench_with_c_str_unchecked(b, S_SHORT) } #[bench] fn bench_with_c_str_unchecked_medium(b: &mut Bencher) { - bench_with_c_str_unchecked(b, s_medium) + bench_with_c_str_unchecked(b, S_MEDIUM) } #[bench] fn bench_with_c_str_unchecked_long(b: &mut Bencher) { - bench_with_c_str_unchecked(b, s_long) + bench_with_c_str_unchecked(b, S_LONG) } } diff --git a/src/librustrt/libunwind.rs b/src/librustrt/libunwind.rs index 2e7408d91591c..bb7a1227e0e47 100644 --- a/src/librustrt/libunwind.rs +++ b/src/librustrt/libunwind.rs @@ -10,6 +10,7 @@ //! Unwind library interface +#![allow(non_uppercase_statics)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(dead_code)] // these are just bindings diff --git a/src/librustrt/local_data.rs b/src/librustrt/local_data.rs index fcef5981f0a35..8d5c49d767f15 100644 --- a/src/librustrt/local_data.rs +++ b/src/librustrt/local_data.rs @@ -416,37 +416,37 @@ mod tests { #[test] fn test_tls_multitask() { - static my_key: Key = &KeyValueKey; - my_key.replace(Some("parent data".to_string())); + static MY_KEY: Key = &KeyValueKey; + MY_KEY.replace(Some("parent data".to_string())); task::spawn(proc() { // TLD shouldn't carry over. - assert!(my_key.get().is_none()); - my_key.replace(Some("child data".to_string())); - assert!(my_key.get().as_ref().unwrap().as_slice() == "child data"); + assert!(MY_KEY.get().is_none()); + MY_KEY.replace(Some("child data".to_string())); + assert!(MY_KEY.get().as_ref().unwrap().as_slice() == "child data"); // should be cleaned up for us }); // Must work multiple times - assert!(my_key.get().unwrap().as_slice() == "parent data"); - assert!(my_key.get().unwrap().as_slice() == "parent data"); - assert!(my_key.get().unwrap().as_slice() == "parent data"); + assert!(MY_KEY.get().unwrap().as_slice() == "parent data"); + assert!(MY_KEY.get().unwrap().as_slice() == "parent data"); + assert!(MY_KEY.get().unwrap().as_slice() == "parent data"); } #[test] fn test_tls_overwrite() { - static my_key: Key = &KeyValueKey; - my_key.replace(Some("first data".to_string())); - my_key.replace(Some("next data".to_string())); // Shouldn't leak. - assert!(my_key.get().unwrap().as_slice() == "next data"); + static MY_KEY: Key = &KeyValueKey; + MY_KEY.replace(Some("first data".to_string())); + MY_KEY.replace(Some("next data".to_string())); // Shouldn't leak. + assert!(MY_KEY.get().unwrap().as_slice() == "next data"); } #[test] fn test_tls_pop() { - static my_key: Key = &KeyValueKey; - my_key.replace(Some("weasel".to_string())); - assert!(my_key.replace(None).unwrap() == "weasel".to_string()); + static MY_KEY: Key = &KeyValueKey; + MY_KEY.replace(Some("weasel".to_string())); + assert!(MY_KEY.replace(None).unwrap() == "weasel".to_string()); // Pop must remove the data from the map. - assert!(my_key.replace(None).is_none()); + assert!(MY_KEY.replace(None).is_none()); } #[test] @@ -457,58 +457,58 @@ mod tests { // to get recorded as something within a rust stack segment. Then a // subsequent upcall (esp. for logging, think vsnprintf) would run on // a stack smaller than 1 MB. - static my_key: Key = &KeyValueKey; + static MY_KEY: Key = &KeyValueKey; task::spawn(proc() { - my_key.replace(Some("hax".to_string())); + MY_KEY.replace(Some("hax".to_string())); }); } #[test] fn test_tls_multiple_types() { - static str_key: Key = &KeyValueKey; - static box_key: Key> = &KeyValueKey; - static int_key: Key = &KeyValueKey; + static STR_KEY: Key = &KeyValueKey; + static BOX_KEY: Key> = &KeyValueKey; + static INT_KEY: Key = &KeyValueKey; task::spawn(proc() { - str_key.replace(Some("string data".to_string())); - box_key.replace(Some(box 0)); - int_key.replace(Some(42)); + STR_KEY.replace(Some("string data".to_string())); + BOX_KEY.replace(Some(box 0)); + INT_KEY.replace(Some(42)); }); } #[test] fn test_tls_overwrite_multiple_types() { - static str_key: Key = &KeyValueKey; - static box_key: Key> = &KeyValueKey; - static int_key: Key = &KeyValueKey; + static STR_KEY: Key = &KeyValueKey; + static BOX_KEY: Key> = &KeyValueKey; + static INT_KEY: Key = &KeyValueKey; task::spawn(proc() { - str_key.replace(Some("string data".to_string())); - str_key.replace(Some("string data 2".to_string())); - box_key.replace(Some(box 0)); - box_key.replace(Some(box 1)); - int_key.replace(Some(42)); + STR_KEY.replace(Some("string data".to_string())); + STR_KEY.replace(Some("string data 2".to_string())); + BOX_KEY.replace(Some(box 0)); + BOX_KEY.replace(Some(box 1)); + INT_KEY.replace(Some(42)); // This could cause a segfault if overwriting-destruction is done // with the crazy polymorphic transmute rather than the provided // finaliser. - int_key.replace(Some(31337)); + INT_KEY.replace(Some(31337)); }); } #[test] #[should_fail] fn test_tls_cleanup_on_failure() { - static str_key: Key = &KeyValueKey; - static box_key: Key> = &KeyValueKey; - static int_key: Key = &KeyValueKey; - str_key.replace(Some("parent data".to_string())); - box_key.replace(Some(box 0)); + static STR_KEY: Key = &KeyValueKey; + static BOX_KEY: Key> = &KeyValueKey; + static INT_KEY: Key = &KeyValueKey; + STR_KEY.replace(Some("parent data".to_string())); + BOX_KEY.replace(Some(box 0)); task::spawn(proc() { - str_key.replace(Some("string data".to_string())); - box_key.replace(Some(box 2)); - int_key.replace(Some(42)); + STR_KEY.replace(Some("string data".to_string())); + BOX_KEY.replace(Some(box 2)); + INT_KEY.replace(Some(42)); fail!(); }); // Not quite nondeterministic. - int_key.replace(Some(31337)); + INT_KEY.replace(Some(31337)); fail!(); } @@ -523,9 +523,9 @@ mod tests { self.tx.send(()); } } - static key: Key = &KeyValueKey; + static KEY: Key = &KeyValueKey; let _ = task::try(proc() { - key.replace(Some(Dropper{ tx: tx })); + KEY.replace(Some(Dropper{ tx: tx })); }); // At this point the task has been cleaned up and the TLD dropped. // If the channel doesn't have a value now, then the Sender was leaked. @@ -534,56 +534,56 @@ mod tests { #[test] fn test_static_pointer() { - static key: Key<&'static int> = &KeyValueKey; + static KEY: Key<&'static int> = &KeyValueKey; static VALUE: int = 0; - key.replace(Some(&VALUE)); + KEY.replace(Some(&VALUE)); } #[test] fn test_owned() { - static key: Key> = &KeyValueKey; - key.replace(Some(box 1)); + static KEY: Key> = &KeyValueKey; + KEY.replace(Some(box 1)); { - let k1 = key.get().unwrap(); - let k2 = key.get().unwrap(); - let k3 = key.get().unwrap(); + let k1 = KEY.get().unwrap(); + let k2 = KEY.get().unwrap(); + let k3 = KEY.get().unwrap(); assert_eq!(**k1, 1); assert_eq!(**k2, 1); assert_eq!(**k3, 1); } - key.replace(Some(box 2)); - assert_eq!(**key.get().unwrap(), 2); + KEY.replace(Some(box 2)); + assert_eq!(**KEY.get().unwrap(), 2); } #[test] fn test_same_key_type() { - static key1: Key = &KeyValueKey; - static key2: Key = &KeyValueKey; - static key3: Key = &KeyValueKey; - static key4: Key = &KeyValueKey; - static key5: Key = &KeyValueKey; - key1.replace(Some(1)); - key2.replace(Some(2)); - key3.replace(Some(3)); - key4.replace(Some(4)); - key5.replace(Some(5)); - - assert_eq!(*key1.get().unwrap(), 1); - assert_eq!(*key2.get().unwrap(), 2); - assert_eq!(*key3.get().unwrap(), 3); - assert_eq!(*key4.get().unwrap(), 4); - assert_eq!(*key5.get().unwrap(), 5); + static KEY1: Key = &KeyValueKey; + static KEY2: Key = &KeyValueKey; + static KEY3: Key = &KeyValueKey; + static KEY4: Key = &KeyValueKey; + static KEY5: Key = &KeyValueKey; + KEY1.replace(Some(1)); + KEY2.replace(Some(2)); + KEY3.replace(Some(3)); + KEY4.replace(Some(4)); + KEY5.replace(Some(5)); + + assert_eq!(*KEY1.get().unwrap(), 1); + assert_eq!(*KEY2.get().unwrap(), 2); + assert_eq!(*KEY3.get().unwrap(), 3); + assert_eq!(*KEY4.get().unwrap(), 4); + assert_eq!(*KEY5.get().unwrap(), 5); } #[test] #[should_fail] fn test_nested_get_set1() { - static key: Key = &KeyValueKey; - assert_eq!(key.replace(Some(4)), None); + static KEY: Key = &KeyValueKey; + assert_eq!(KEY.replace(Some(4)), None); - let _k = key.get(); - key.replace(Some(4)); + let _k = KEY.get(); + KEY.replace(Some(4)); } // ClearKey is a RAII class that ensures the keys are cleared from the map. @@ -601,95 +601,95 @@ mod tests { #[bench] fn bench_replace_none(b: &mut test::Bencher) { - static key: Key = &KeyValueKey; - let _clear = ClearKey(key); - key.replace(None); + static KEY: Key = &KeyValueKey; + let _clear = ClearKey(KEY); + KEY.replace(None); b.iter(|| { - key.replace(None) + KEY.replace(None) }); } #[bench] fn bench_replace_some(b: &mut test::Bencher) { - static key: Key = &KeyValueKey; - let _clear = ClearKey(key); - key.replace(Some(1u)); + static KEY: Key = &KeyValueKey; + let _clear = ClearKey(KEY); + KEY.replace(Some(1u)); b.iter(|| { - key.replace(Some(2)) + KEY.replace(Some(2)) }); } #[bench] fn bench_replace_none_some(b: &mut test::Bencher) { - static key: Key = &KeyValueKey; - let _clear = ClearKey(key); - key.replace(Some(0u)); + static KEY: Key = &KeyValueKey; + let _clear = ClearKey(KEY); + KEY.replace(Some(0u)); b.iter(|| { - let old = key.replace(None).unwrap(); + let old = KEY.replace(None).unwrap(); let new = old + 1; - key.replace(Some(new)) + KEY.replace(Some(new)) }); } #[bench] fn bench_100_keys_replace_last(b: &mut test::Bencher) { - static keys: [KeyValue, ..100] = [KeyValueKey, ..100]; - let _clear = keys.iter().map(ClearKey).collect::>>(); - for (i, key) in keys.iter().enumerate() { + static KEYS: [KeyValue, ..100] = [KeyValueKey, ..100]; + let _clear = KEYS.iter().map(ClearKey).collect::>>(); + for (i, key) in KEYS.iter().enumerate() { key.replace(Some(i)); } b.iter(|| { - let key: Key = &keys[99]; + let key: Key = &KEYS[99]; key.replace(Some(42)) }); } #[bench] fn bench_1000_keys_replace_last(b: &mut test::Bencher) { - static keys: [KeyValue, ..1000] = [KeyValueKey, ..1000]; - let _clear = keys.iter().map(ClearKey).collect::>>(); - for (i, key) in keys.iter().enumerate() { + static KEYS: [KeyValue, ..1000] = [KeyValueKey, ..1000]; + let _clear = KEYS.iter().map(ClearKey).collect::>>(); + for (i, key) in KEYS.iter().enumerate() { key.replace(Some(i)); } b.iter(|| { - let key: Key = &keys[999]; + let key: Key = &KEYS[999]; key.replace(Some(42)) }); - for key in keys.iter() { key.clear(); } + for key in KEYS.iter() { key.clear(); } } #[bench] fn bench_get(b: &mut test::Bencher) { - static key: Key = &KeyValueKey; - let _clear = ClearKey(key); - key.replace(Some(42)); + static KEY: Key = &KeyValueKey; + let _clear = ClearKey(KEY); + KEY.replace(Some(42)); b.iter(|| { - key.get() + KEY.get() }); } #[bench] fn bench_100_keys_get_last(b: &mut test::Bencher) { - static keys: [KeyValue, ..100] = [KeyValueKey, ..100]; - let _clear = keys.iter().map(ClearKey).collect::>>(); - for (i, key) in keys.iter().enumerate() { + static KEYS: [KeyValue, ..100] = [KeyValueKey, ..100]; + let _clear = KEYS.iter().map(ClearKey).collect::>>(); + for (i, key) in KEYS.iter().enumerate() { key.replace(Some(i)); } b.iter(|| { - let key: Key = &keys[99]; + let key: Key = &KEYS[99]; key.get() }); } #[bench] fn bench_1000_keys_get_last(b: &mut test::Bencher) { - static keys: [KeyValue, ..1000] = [KeyValueKey, ..1000]; - let _clear = keys.iter().map(ClearKey).collect::>>(); - for (i, key) in keys.iter().enumerate() { + static KEYS: [KeyValue, ..1000] = [KeyValueKey, ..1000]; + let _clear = KEYS.iter().map(ClearKey).collect::>>(); + for (i, key) in KEYS.iter().enumerate() { key.replace(Some(i)); } b.iter(|| { - let key: Key = &keys[999]; + let key: Key = &KEYS[999]; key.get() }); } diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index 86dc9b85a792d..28b0256f2e6e3 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -376,8 +376,8 @@ mod imp { #[cfg(target_arch = "arm")] static __PTHREAD_COND_SIZE__: uint = 24; - static _PTHREAD_MUTEX_SIG_init: libc::c_long = 0x32AAABA7; - static _PTHREAD_COND_SIG_init: libc::c_long = 0x3CB0B1BB; + static _PTHREAD_MUTEX_SIG_INIT: libc::c_long = 0x32AAABA7; + static _PTHREAD_COND_SIG_INIT: libc::c_long = 0x3CB0B1BB; #[repr(C)] pub struct pthread_mutex_t { @@ -391,11 +391,11 @@ mod imp { } pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - __sig: _PTHREAD_MUTEX_SIG_init, + __sig: _PTHREAD_MUTEX_SIG_INIT, __opaque: [0, ..__PTHREAD_MUTEX_SIZE__], }; pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - __sig: _PTHREAD_COND_SIG_init, + __sig: _PTHREAD_COND_SIG_INIT, __opaque: [0, ..__PTHREAD_COND_SIZE__], }; } diff --git a/src/librustrt/util.rs b/src/librustrt/util.rs index 77e3e25eb0e7e..9fbf4d09cd60d 100644 --- a/src/librustrt/util.rs +++ b/src/librustrt/util.rs @@ -28,7 +28,9 @@ pub static ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || pub struct Stdio(libc::c_int); +#[allow(non_uppercase_statics)] pub static Stdout: Stdio = Stdio(libc::STDOUT_FILENO); +#[allow(non_uppercase_statics)] pub static Stderr: Stdio = Stdio(libc::STDERR_FILENO); impl fmt::FormatWriter for Stdio { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 3007e160bf8ae..654278cf81baf 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -360,7 +360,9 @@ fn escape_char(writer: &mut io::Writer, v: char) -> Result<(), io::IoError> { } fn spaces(wr: &mut io::Writer, mut n: uint) -> Result<(), io::IoError> { + #[allow(non_uppercase_statics)] static len: uint = 16; + #[allow(non_uppercase_statics)] static buf: [u8, ..len] = [b' ', ..len]; while n >= len { diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 1d479b852480c..391d099de87c6 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -123,7 +123,10 @@ macro_rules! bitflags { bits: $T, } - $($(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };)+ + $( + #[allow(non_uppercase_statics)] + $(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value }; + )+ impl $BitFlags { /// Returns an empty set of flags. @@ -240,7 +243,10 @@ macro_rules! bitflags { bitflags! { $(#[$attr])* flags $BitFlags: $T { - $($(#[$Flag_attr])* static $Flag = $value),+ + $( + #[allow(non_uppercase_statics)] + $(#[$Flag_attr])* static $Flag = $value + ),+ } } }; diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index d8be92e451460..73a8aa442c1fd 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -11,6 +11,7 @@ //! Bindings for executing child processes #![allow(experimental)] +#![allow(non_uppercase_statics)] use prelude::*; diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index d949a03dfc140..fa356432a6731 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -304,9 +304,11 @@ macro_rules! println( #[macro_export] macro_rules! local_data_key( ($name:ident: $ty:ty) => ( + #[allow(non_uppercase_statics)] static $name: ::std::local_data::Key<$ty> = &::std::local_data::KeyValueKey; ); (pub $name:ident: $ty:ty) => ( + #[allow(non_uppercase_statics)] pub static $name: ::std::local_data::Key<$ty> = &::std::local_data::KeyValueKey; ); ) diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 9c4139853c540..805db000686a0 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -457,7 +457,9 @@ fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option> { } } +#[allow(non_uppercase_statics)] static dot_static: &'static [u8] = b"."; +#[allow(non_uppercase_statics)] static dot_dot_static: &'static [u8] = b".."; #[cfg(test)] diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 9cace9c80ef5a..977b3018fa74c 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -569,10 +569,10 @@ mod test { // climbing the task tree to dereference each ancestor. (See #1789) // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) - static generations: uint = 16; + static GENERATIONS: uint = 16; fn child_no(x: uint) -> proc(): Send { return proc() { - if x < generations { + if x < GENERATIONS { TaskBuilder::new().spawn(child_no(x+1)); } } diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 6d9b8821bd890..3a02d74edffb7 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -47,7 +47,9 @@ pub enum Architecture { Mipsel } +#[allow(non_uppercase_statics)] static IntelBits: u32 = (1 << (X86 as uint)) | (1 << (X86_64 as uint)); +#[allow(non_uppercase_statics)] static ArmBits: u32 = (1 << (Arm as uint)); pub struct AbiData { @@ -70,6 +72,7 @@ pub enum AbiArchitecture { Archs(u32) } +#[allow(non_uppercase_statics)] static AbiDatas: &'static [AbiData] = &[ // Platform-specific ABIs AbiData {abi: Cdecl, name: "cdecl", abi_arch: Archs(IntelBits)}, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 3186006258041..f746e1f14822a 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -293,6 +293,7 @@ pub fn operator_prec(op: ast::BinOp) -> uint { /// Precedence of the `as` operator, which is a binary operator /// not appearing in the prior table. +#[allow(non_uppercase_statics)] pub static as_prec: uint = 12u; pub fn empty_generics() -> Generics { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a486ac40a97a1..a8c827439cc60 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -383,12 +383,15 @@ macro_rules! declare_special_idents_and_keywords {( pub mod special_idents { use ast::{Ident, Name}; - $( pub static $si_static: Ident = Ident { name: Name($si_name), ctxt: 0 }; )* + $( + #[allow(non_uppercase_statics)] + pub static $si_static: Ident = Ident { name: Name($si_name), ctxt: 0 }; + )* } pub mod special_names { use ast::Name; - $( pub static $si_static: Name = Name($si_name); )* + $( #[allow(non_uppercase_statics)] pub static $si_static: Name = Name($si_name); )* } /** diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8400d9aea3b59..c3a3848019a5d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -89,8 +89,10 @@ pub fn rust_printer_annotated<'a>(writer: Box, } } +#[allow(non_uppercase_statics)] pub static indent_unit: uint = 4u; +#[allow(non_uppercase_statics)] pub static default_columns: uint = 78u; /// Requires you to pass an input filename and reader so that diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index f728205c3a57f..c0c3f707ecb3c 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -173,6 +173,7 @@ impl fmt::Show for ParseError { } // Length of each hyphenated group in hex digits +#[allow(non_uppercase_statics)] static UuidGroupLens: [uint, ..5] = [8u, 4u, 4u, 4u, 12u]; /// UUID support diff --git a/src/test/compile-fail-fulldeps/syntax-extension-regex-unused-static.rs b/src/test/compile-fail-fulldeps/syntax-extension-regex-unused-static.rs index 095acf56e4865..1d14da73b7eeb 100644 --- a/src/test/compile-fail-fulldeps/syntax-extension-regex-unused-static.rs +++ b/src/test/compile-fail-fulldeps/syntax-extension-regex-unused-static.rs @@ -17,6 +17,7 @@ extern crate regex; #[deny(unused_variable)] #[deny(dead_code)] +#[allow(non_uppercase_statics)] // Tests to make sure that extraneous dead code warnings aren't emitted from // the code generated by regex!. diff --git a/src/test/compile-fail/asm-misplaced-option.rs b/src/test/compile-fail/asm-misplaced-option.rs index 8006789d440c3..74bfc6e6ffc1f 100644 --- a/src/test/compile-fail/asm-misplaced-option.rs +++ b/src/test/compile-fail/asm-misplaced-option.rs @@ -12,7 +12,7 @@ #![feature(asm)] -#![allow(dead_code)] +#![allow(dead_code, non_uppercase_statics)] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] diff --git a/src/test/compile-fail/issue-6804.rs b/src/test/compile-fail/issue-6804.rs index 600b28048b4fb..30d3ab17a463e 100644 --- a/src/test/compile-fail/issue-6804.rs +++ b/src/test/compile-fail/issue-6804.rs @@ -30,4 +30,4 @@ fn main() { // At least one error is needed so that compilation fails #[static_assert] -static b: bool = false; //~ ERROR static assertion failed +static B: bool = false; //~ ERROR static assertion failed diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index b7feea775cb43..45380235a2a8b 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -11,6 +11,7 @@ #![no_std] #![allow(unused_variable)] #![allow(non_camel_case_types)] +#![allow(non_uppercase_statics)] #![deny(dead_code)] #![feature(lang_items)] diff --git a/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs b/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs index e920bfd412d4c..bbd88f1f0aade 100644 --- a/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs +++ b/src/test/compile-fail/lint-directives-on-use-items-issue-10534.rs @@ -9,6 +9,7 @@ // except according to those terms. #![deny(unused_imports)] +#![allow(non_uppercase_statics)] // The aim of this test is to ensure that deny/allow/warn directives // are applied to individual "use" statements instead of silently From 333592edde810324c9730a89372fa5164d10871d Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 13 Sep 2014 13:58:35 +1200 Subject: [PATCH 05/14] Update the `unused` lint group to include more lints --- src/librustc/lint/builtin.rs | 8 ++++---- src/librustc/lint/context.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 7a59aeb57895d..8ffda8bd8275f 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -631,7 +631,7 @@ impl LintPass for UnusedAttribute { } } -declare_lint!(PATH_STATEMENT, Warn, +declare_lint!(pub PATH_STATEMENT, Warn, "path statements with no effect") pub struct PathStatement; @@ -655,10 +655,10 @@ impl LintPass for PathStatement { } } -declare_lint!(UNUSED_MUST_USE, Warn, +declare_lint!(pub UNUSED_MUST_USE, Warn, "unused result of a type flagged as #[must_use]") -declare_lint!(UNUSED_RESULT, Allow, +declare_lint!(pub UNUSED_RESULT, Allow, "unused result of an expression in a statement") pub struct UnusedResult; @@ -1136,7 +1136,7 @@ impl LintPass for UnnecessaryImportBraces { } } -declare_lint!(UNUSED_UNSAFE, Warn, +declare_lint!(pub UNUSED_UNSAFE, Warn, "unnecessary use of an `unsafe` block") pub struct UnusedUnsafe; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 51852a347d16e..bb277511463b9 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -203,7 +203,8 @@ impl LintStore { add_lint_group!(sess, "unused", UNUSED_IMPORTS, UNUSED_VARIABLE, DEAD_ASSIGNMENT, DEAD_CODE, - UNUSED_MUT, UNREACHABLE_CODE, UNUSED_EXTERN_CRATE) + UNUSED_MUT, UNREACHABLE_CODE, UNUSED_EXTERN_CRATE, UNUSED_MUST_USE, + UNUSED_UNSAFE, UNUSED_RESULT, PATH_STATEMENT) // We have one lint pass defined in this module. self.register_pass(sess, false, box GatherNodeLevels as LintPassObject); From 45044124e46bbfd1ab9869ffce71259ae93866ff Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 13 Sep 2014 13:59:15 +1200 Subject: [PATCH 06/14] Improve the `non_snake_case` lint to give better suggestions --- src/librustc/lint/builtin.rs | 6 +++++- src/test/compile-fail/lint-non-snake-case-functions.rs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 8ffda8bd8275f..ea647fda84823 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -871,13 +871,17 @@ impl NonSnakeCase { fn to_snake_case(str: &str) -> String { let mut words = vec![]; for s in str.split('_') { + let mut last_upper = false; let mut buf = String::new(); if s.is_empty() { continue; } for ch in s.chars() { - if !buf.is_empty() && buf.as_slice() != "'" && ch.is_uppercase() { + if !buf.is_empty() && buf.as_slice() != "'" + && ch.is_uppercase() + && !last_upper { words.push(buf); buf = String::new(); } + last_upper = ch.is_uppercase(); buf.push_char(ch.to_lowercase()); } words.push(buf); diff --git a/src/test/compile-fail/lint-non-snake-case-functions.rs b/src/test/compile-fail/lint-non-snake-case-functions.rs index ccbe1f006e308..6cfdc6ad90b91 100644 --- a/src/test/compile-fail/lint-non-snake-case-functions.rs +++ b/src/test/compile-fail/lint-non-snake-case-functions.rs @@ -23,11 +23,14 @@ impl Foo { pub fn xyZ(&mut self) {} //~^ ERROR method `xyZ` should have a snake case name such as `xy_z` + + fn render_HTML() {} + //~^ ERROR method `render_HTML` should have a snake case name such as `render_html` } trait X { fn ABC(); - //~^ ERROR trait method `ABC` should have a snake case name such as `a_b_c` + //~^ ERROR trait method `ABC` should have a snake case name such as `abc` fn a_b_C(&self) {} //~^ ERROR trait method `a_b_C` should have a snake case name such as `a_b_c` From 042cdeefc7708291057770ddd5becf14288dad71 Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 13 Sep 2014 14:09:22 +1200 Subject: [PATCH 07/14] Correct error message for invalid `ref`/`mut` bindings Closes #15914. --- src/libsyntax/parse/parser.rs | 7 ++++--- src/test/compile-fail/issue-15914.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/issue-15914.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7cce9c2dc3a80..d2735a425f591 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3402,9 +3402,10 @@ impl<'a> Parser<'a> { binding_mode: ast::BindingMode) -> ast::Pat_ { if !is_plain_ident(&self.token) { - let last_span = self.last_span; - self.span_fatal(last_span, - "expected identifier, found path"); + let span = self.span; + let tok_str = self.this_token_to_string(); + self.span_fatal(span, + format!("expected identifier, found `{}`", tok_str).as_slice()); } let ident = self.parse_ident(); let last_span = self.last_span; diff --git a/src/test/compile-fail/issue-15914.rs b/src/test/compile-fail/issue-15914.rs new file mode 100644 index 0000000000000..45b3abfddfba2 --- /dev/null +++ b/src/test/compile-fail/issue-15914.rs @@ -0,0 +1,14 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let ref + (); //~ ERROR expected identifier, found `(` +} From 073a1abff28c01a541d96a5c7b1bbc5c9c9d0401 Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 13 Sep 2014 14:10:10 +1200 Subject: [PATCH 08/14] Report trait/impl sig inconsistency before method/body inconsistency Closes #15657. --- src/librustc/middle/typeck/check/mod.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index d882ee5d0e59c..ca5d711d360ab 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -693,16 +693,6 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) { debug!("ItemImpl {} with id {}", token::get_ident(it.ident), it.id); let impl_pty = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id)); - for impl_item in impl_items.iter() { - match *impl_item { - ast::MethodImplItem(ref m) => { - check_method_body(ccx, &impl_pty.generics, &**m); - } - ast::TypeImplItem(_) => { - // Nothing to do here. - } - } - } match *opt_trait_ref { Some(ref ast_trait_ref) => { @@ -717,6 +707,17 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) { None => { } } + for impl_item in impl_items.iter() { + match *impl_item { + ast::MethodImplItem(ref m) => { + check_method_body(ccx, &impl_pty.generics, &**m); + } + ast::TypeImplItem(_) => { + // Nothing to do here. + } + } + } + } ast::ItemTrait(_, _, _, ref trait_methods) => { let trait_def = ty::lookup_trait_def(ccx.tcx, local_def(it.id)); From f56c67ba86cf21c09e8ce8f7d7e6d5399bf4b262 Mon Sep 17 00:00:00 2001 From: P1start Date: Sat, 13 Sep 2014 14:12:22 +1200 Subject: [PATCH 09/14] Change rustc pretty-printing to print [T, ..n] instead of [T, .. n] --- src/librustc/util/ppaux.rs | 2 +- src/test/compile-fail/dst-bad-coerce1.rs | 2 +- src/test/compile-fail/dst-bad-coerce4.rs | 2 +- src/test/compile-fail/issue-13482.rs | 2 +- src/test/compile-fail/issue-14845.rs | 4 ++-- src/test/compile-fail/issue-17441.rs | 4 ++-- src/test/compile-fail/issue-2149.rs | 2 +- src/test/compile-fail/issue-4517.rs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 7edd809e4442b..7ed9d556a0ba7 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -427,7 +427,7 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String { ty_vec(t, sz) => { match sz { Some(n) => { - format!("[{}, .. {}]", ty_to_string(cx, t), n) + format!("[{}, ..{}]", ty_to_string(cx, t), n) } None => format!("[{}]", ty_to_string(cx, t)), } diff --git a/src/test/compile-fail/dst-bad-coerce1.rs b/src/test/compile-fail/dst-bad-coerce1.rs index 4247f91a4fc53..59499ac070d6d 100644 --- a/src/test/compile-fail/dst-bad-coerce1.rs +++ b/src/test/compile-fail/dst-bad-coerce1.rs @@ -22,7 +22,7 @@ pub fn main() { let f1 = Fat { ptr: [1, 2, 3] }; let f2: &Fat<[int, ..3]> = &f1; let f3: &Fat<[uint]> = f2; - //~^ ERROR mismatched types: expected `&Fat<[uint]>`, found `&Fat<[int, .. 3]>` + //~^ ERROR mismatched types: expected `&Fat<[uint]>`, found `&Fat<[int, ..3]>` // With a trait. let f1 = Fat { ptr: Foo }; diff --git a/src/test/compile-fail/dst-bad-coerce4.rs b/src/test/compile-fail/dst-bad-coerce4.rs index 9a192334997d2..9010185f76b6a 100644 --- a/src/test/compile-fail/dst-bad-coerce4.rs +++ b/src/test/compile-fail/dst-bad-coerce4.rs @@ -18,5 +18,5 @@ pub fn main() { // With a vec of ints. let f1: &Fat<[int]> = &Fat { ptr: [1, 2, 3] }; let f2: &Fat<[int, ..3]> = f1; - //~^ ERROR mismatched types: expected `&Fat<[int, .. 3]>`, found `&Fat<[int]>` + //~^ ERROR mismatched types: expected `&Fat<[int, ..3]>`, found `&Fat<[int]>` } diff --git a/src/test/compile-fail/issue-13482.rs b/src/test/compile-fail/issue-13482.rs index 2d7458944269c..e5d87395286e4 100644 --- a/src/test/compile-fail/issue-13482.rs +++ b/src/test/compile-fail/issue-13482.rs @@ -12,7 +12,7 @@ fn main() { let x = [1,2]; let y = match x { [] => None, -//~^ ERROR expected `[, .. 2]`, found a fixed vector pattern of size 0 +//~^ ERROR expected `[, ..2]`, found a fixed vector pattern of size 0 [a,_] => Some(a) }; } diff --git a/src/test/compile-fail/issue-14845.rs b/src/test/compile-fail/issue-14845.rs index fc5a591ebd60f..bc606d8139f01 100644 --- a/src/test/compile-fail/issue-14845.rs +++ b/src/test/compile-fail/issue-14845.rs @@ -16,9 +16,9 @@ struct X { fn main() { let x = X { a: [0] }; let _f = &x.a as *mut u8; - //~^ ERROR mismatched types: expected `*mut u8`, found `&[u8, .. 1]` + //~^ ERROR mismatched types: expected `*mut u8`, found `&[u8, ..1]` let local = [0u8]; let _v = &local as *mut u8; - //~^ ERROR mismatched types: expected `*mut u8`, found `&[u8, .. 1]` + //~^ ERROR mismatched types: expected `*mut u8`, found `&[u8, ..1]` } diff --git a/src/test/compile-fail/issue-17441.rs b/src/test/compile-fail/issue-17441.rs index da548ca5ffe3e..da5590971bc3c 100644 --- a/src/test/compile-fail/issue-17441.rs +++ b/src/test/compile-fail/issue-17441.rs @@ -10,7 +10,7 @@ fn main() { let _foo = &[1u, 2] as [uint]; - //~^ ERROR cast to unsized type: `&[uint, .. 2]` as `[uint]` + //~^ ERROR cast to unsized type: `&[uint, ..2]` as `[uint]` //~^^ NOTE consider using an implicit coercion to `&[uint]` instead let _bar = box 1u as std::fmt::Show; //~^ ERROR cast to unsized type: `Box` as `core::fmt::Show` @@ -19,6 +19,6 @@ fn main() { //~^ ERROR cast to unsized type: `uint` as `core::fmt::Show` //~^^ NOTE consider using a box or reference as appropriate let _quux = [1u, 2] as [uint]; - //~^ ERROR cast to unsized type: `[uint, .. 2]` as `[uint]` + //~^ ERROR cast to unsized type: `[uint, ..2]` as `[uint]` //~^^ NOTE consider using a box or reference as appropriate } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 5d07472afbb25..81f57dd96402b 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -22,5 +22,5 @@ impl vec_monad for Vec { } fn main() { ["hi"].bind(|x| [x] ); - //~^ ERROR type `[&str, .. 1]` does not implement any method in scope named `bind` + //~^ ERROR type `[&str, ..1]` does not implement any method in scope named `bind` } diff --git a/src/test/compile-fail/issue-4517.rs b/src/test/compile-fail/issue-4517.rs index d80f2d1263d99..f61ed35fca359 100644 --- a/src/test/compile-fail/issue-4517.rs +++ b/src/test/compile-fail/issue-4517.rs @@ -13,6 +13,6 @@ fn bar(int_param: int) {} fn main() { let foo: [u8, ..4] = [1u8, ..4u]; bar(foo); - //~^ ERROR mismatched types: expected `int`, found `[u8, .. 4]` + //~^ ERROR mismatched types: expected `int`, found `[u8, ..4]` // (expected int, found vector) } From a667a6917b2be3bad44a625badcc11293a97910b Mon Sep 17 00:00:00 2001 From: P1start Date: Wed, 17 Sep 2014 22:34:18 +1200 Subject: [PATCH 10/14] Move the lint for the stability lints to the method name only Closes #17337. --- src/librustc/lint/builtin.rs | 7 +++++-- src/test/compile-fail/issue-17337.rs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-17337.rs diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index ea647fda84823..4c147517a7f03 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -1492,6 +1492,8 @@ impl LintPass for Stability { }); if skip { return; } + let mut span = e.span; + let id = match e.node { ast::ExprPath(..) | ast::ExprStruct(..) => { match cx.tcx.def_map.borrow().find(&e.id) { @@ -1499,7 +1501,8 @@ impl LintPass for Stability { None => return } } - ast::ExprMethodCall(..) => { + ast::ExprMethodCall(i, _, _) => { + span = i.span; let method_call = typeck::MethodCall::expr(e.id); match cx.tcx.method_map.borrow().find(&method_call) { Some(method) => { @@ -1556,7 +1559,7 @@ impl LintPass for Stability { _ => format!("use of {} item", label) }; - cx.span_lint(lint, e.span, msg.as_slice()); + cx.span_lint(lint, span, msg.as_slice()); } } diff --git a/src/test/compile-fail/issue-17337.rs b/src/test/compile-fail/issue-17337.rs new file mode 100644 index 0000000000000..e0f655084ff70 --- /dev/null +++ b/src/test/compile-fail/issue-17337.rs @@ -0,0 +1,23 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(deprecated)] + +struct Foo; + +impl Foo { + #[deprecated] + fn foo(self) {} +} + +fn main() { + Foo + .foo(); //~ ERROR use of deprecated item +} From da7dcee8f16b7ea635b9e0ca83b529e1d92421b0 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Fri, 3 Oct 2014 14:26:07 +0300 Subject: [PATCH 11/14] tests: remove old compile-fail test asserting the removal of `const`. --- src/test/compile-fail/removed-syntax-const-item.rs | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/test/compile-fail/removed-syntax-const-item.rs diff --git a/src/test/compile-fail/removed-syntax-const-item.rs b/src/test/compile-fail/removed-syntax-const-item.rs deleted file mode 100644 index 841c1ec59fdaa..0000000000000 --- a/src/test/compile-fail/removed-syntax-const-item.rs +++ /dev/null @@ -1,11 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -const i: int = 42; //~ ERROR expected item, found `const` From ef693885a78ee21786ae464f590fff6437e43865 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Fri, 3 Oct 2014 17:16:05 +0300 Subject: [PATCH 12/14] Fix a race condition between remove_from_env and other io::process tests. --- src/libstd/io/process.rs | 26 ---------- src/test/run-pass/process-remove-from-env.rs | 53 ++++++++++++++++++++ 2 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 src/test/run-pass/process-remove-from-env.rs diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index d8be92e451460..8b7d1cd0de580 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -1024,32 +1024,6 @@ mod tests { "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); } - #[test] - fn test_remove_from_env() { - use os; - - // save original environment - let old_env = os::getenv("RUN_TEST_NEW_ENV"); - - os::setenv("RUN_TEST_NEW_ENV", "123"); - let prog = env_cmd().env_remove("RUN_TEST_NEW_ENV").spawn().unwrap(); - let result = prog.wait_with_output().unwrap(); - let output = str::from_utf8_lossy(result.output.as_slice()).into_string(); - - // restore original environment - match old_env { - None => { - os::unsetenv("RUN_TEST_NEW_ENV"); - } - Some(val) => { - os::setenv("RUN_TEST_NEW_ENV", val.as_slice()); - } - } - - assert!(!output.as_slice().contains("RUN_TEST_NEW_ENV"), - "found RUN_TEST_NEW_ENV inside of:\n\n{}", output); - } - #[cfg(unix)] pub fn sleeper() -> Process { Command::new("sleep").arg("1000").spawn().unwrap() diff --git a/src/test/run-pass/process-remove-from-env.rs b/src/test/run-pass/process-remove-from-env.rs new file mode 100644 index 0000000000000..eab9c8a95da2c --- /dev/null +++ b/src/test/run-pass/process-remove-from-env.rs @@ -0,0 +1,53 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::io::Command; +use std::os; + +#[cfg(all(unix, not(target_os="android")))] +pub fn env_cmd() -> Command { + Command::new("env") +} +#[cfg(target_os="android")] +pub fn env_cmd() -> Command { + let mut cmd = Command::new("/system/bin/sh"); + cmd.arg("-c").arg("set"); + cmd +} + +#[cfg(windows)] +pub fn env_cmd() -> Command { + let mut cmd = Command::new("cmd"); + cmd.arg("/c").arg("set"); + cmd +} + +fn main() { + // save original environment + let old_env = os::getenv("RUN_TEST_NEW_ENV"); + + os::setenv("RUN_TEST_NEW_ENV", "123"); + + let mut cmd = env_cmd(); + cmd.env_remove("RUN_TEST_NEW_ENV"); + + // restore original environment + match old_env { + None => os::unsetenv("RUN_TEST_NEW_ENV"), + Some(val) => os::setenv("RUN_TEST_NEW_ENV", val.as_slice()) + } + + let prog = cmd.spawn().unwrap(); + let result = prog.wait_with_output().unwrap(); + let output = String::from_utf8_lossy(result.output.as_slice()); + + assert!(!output.as_slice().contains("RUN_TEST_NEW_ENV"), + "found RUN_TEST_NEW_ENV inside of:\n\n{}", output); +} From 7b6ecc009c40f97bd93ec158b6efe9449f6aba1d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 3 Oct 2014 07:25:10 -0700 Subject: [PATCH 13/14] travis: Fix for real this time I ended up botching the merge when making the rollup, and the fix was to just not configure LLVM all via --llvm-root with a nonexistent path. --- .travis.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5bcdafb30eba2..261990052988f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,6 @@ # downloads a rust/cargo snapshot, which we don't really want for building rust. language: c -# Make sure we've got an up-to-date g++ compiler to get past the LLVM configure -# script. -install: - - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - - sudo apt-get update -qq - - sudo apt-get install g++-4.7 - # The test suite is in general way too stressful for travis, especially in # terms of time limit and reliability. In the past we've tried to scale things # back to only build the stage1 compiler and run a subset of tests, but this @@ -18,7 +11,7 @@ install: # As a result, we're just using travis to run `make tidy` now. It'll help # everyone find out about their trailing spaces early on! before_script: - - ./configure + - ./configure --llvm-root=path/to/nowhere script: - make tidy From 39f4bf7b1c9991cfd02f68d45ca59d6c525c4184 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 3 Oct 2014 08:00:27 -0700 Subject: [PATCH 14/14] Test fixes from the rollup --- src/doc/reference.md | 2 +- src/test/pretty/issue-4264.pp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 9cc70118b145f..9a02a3b815e8a 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1412,7 +1412,7 @@ struct BitsNStrings<'a> { mystring: &'a str } -static bits_n_strings: BitsNStrings<'static> = BitsNStrings { +static BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings { mybits: BITS, mystring: STRING }; diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 376a3a38fda1e..2bc09d7e96e58 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -26,33 +26,33 @@ pub fn bar() { static FOO: uint = ((5u as uint) - (4u as uint) as uint); - let _: [(), ..(FOO as uint)] = ([(() as ())] as [(), .. 1]); + let _: [(), ..(FOO as uint)] = ([(() as ())] as [(), ..1]); - let _: [(), ..(1u as uint)] = ([(() as ())] as [(), .. 1]); + let _: [(), ..(1u as uint)] = ([(() as ())] as [(), ..1]); let _ = - (((&((([(1i as int), (2 as int), (3 as int)] as [int, .. 3])) as - [int, .. 3]) as &[int, .. 3]) as *const _ as - *const [int, .. 3]) as *const [int, ..(3u as uint)] as - *const [int, .. 3]); + (((&((([(1i as int), (2 as int), (3 as int)] as [int, ..3])) as + [int, ..3]) as &[int, ..3]) as *const _ as *const [int, ..3]) + as *const [int, ..(3u as uint)] as *const [int, ..3]); + (match (() as ()) { () => { #[inline] #[allow(dead_code)] static __STATIC_FMTSTR: [&'static str, ..(1u as uint)] = - ([("test" as &'static str)] as [&'static str, .. 1]); + ([("test" as &'static str)] as [&'static str, ..1]); let __args_vec = - (&([] as [core::fmt::Argument<'_>, .. 0]) as - &[core::fmt::Argument<'_>, .. 0]); + (&([] as [core::fmt::Argument<'_>, ..0]) as + &[core::fmt::Argument<'_>, ..0]); let __args = (unsafe { ((::std::fmt::Arguments::new as unsafe fn(&'static [&'static str], &'a [core::fmt::Argument<'a>]) -> core::fmt::Arguments<'a>)((__STATIC_FMTSTR as - [&'static str, .. 1]), + [&'static str, ..1]), (__args_vec as - &[core::fmt::Argument<'_>, .. 0])) + &[core::fmt::Argument<'_>, ..0])) as core::fmt::Arguments<'_>) } as core::fmt::Arguments<'_>); @@ -83,8 +83,8 @@ pub fn use_id() { let _ = ((id::<[int, ..(3u as uint)]> as - fn([int, .. 3]) -> [int, .. 3])(([(1 as int), (2 as int), - (3 as int)] as [int, .. 3])) as - [int, .. 3]); + fn([int, ..3]) -> [int, ..3])(([(1 as int), (2 as int), + (3 as int)] as [int, ..3])) as + [int, ..3]); } fn main() { }