Skip to content

Commit 24e489f

Browse files
committed
auto merge of #14520 : Ryman/rust/SnakeCaseLint, r=alexcrichton
This enforces `snake_case` for functions and methods only. Might be worth extending it to fields and locals too at some point in the future. A number of breaking changes each detailed in the attached commits.
2 parents 36c2c56 + 030b3a2 commit 24e489f

Some content is hidden

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

71 files changed

+605
-488
lines changed

src/compiletest/runtest.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn run_cfail_test(config: &Config, props: &TestProps, testfile: &Path) {
7373
let proc_res = compile_test(config, props, testfile);
7474

7575
if proc_res.status.success() {
76-
fatal_ProcRes("compile-fail test compiled successfully!".to_string(),
76+
fatal_proc_rec("compile-fail test compiled successfully!".to_string(),
7777
&proc_res);
7878
}
7979

@@ -97,7 +97,7 @@ fn run_rfail_test(config: &Config, props: &TestProps, testfile: &Path) {
9797
let proc_res = compile_test(config, props, testfile);
9898

9999
if !proc_res.status.success() {
100-
fatal_ProcRes("compilation failed!".to_string(), &proc_res);
100+
fatal_proc_rec("compilation failed!".to_string(), &proc_res);
101101
}
102102

103103
exec_compiled_test(config, props, testfile)
@@ -108,7 +108,7 @@ fn run_rfail_test(config: &Config, props: &TestProps, testfile: &Path) {
108108
// The value our Makefile configures valgrind to return on failure
109109
static VALGRIND_ERR: int = 100;
110110
if proc_res.status.matches_exit_status(VALGRIND_ERR) {
111-
fatal_ProcRes("run-fail test isn't valgrind-clean!".to_string(),
111+
fatal_proc_rec("run-fail test isn't valgrind-clean!".to_string(),
112112
&proc_res);
113113
}
114114

@@ -120,7 +120,7 @@ fn check_correct_failure_status(proc_res: &ProcRes) {
120120
// The value the rust runtime returns on failure
121121
static RUST_ERR: int = 101;
122122
if !proc_res.status.matches_exit_status(RUST_ERR) {
123-
fatal_ProcRes(
123+
fatal_proc_rec(
124124
format!("failure produced the wrong error: {}", proc_res.status),
125125
proc_res);
126126
}
@@ -131,19 +131,19 @@ fn run_rpass_test(config: &Config, props: &TestProps, testfile: &Path) {
131131
let mut proc_res = compile_test(config, props, testfile);
132132

133133
if !proc_res.status.success() {
134-
fatal_ProcRes("compilation failed!".to_string(), &proc_res);
134+
fatal_proc_rec("compilation failed!".to_string(), &proc_res);
135135
}
136136

137137
proc_res = exec_compiled_test(config, props, testfile);
138138

139139
if !proc_res.status.success() {
140-
fatal_ProcRes("test run failed!".to_string(), &proc_res);
140+
fatal_proc_rec("test run failed!".to_string(), &proc_res);
141141
}
142142
} else {
143143
let proc_res = jit_test(config, props, testfile);
144144

145145
if !proc_res.status.success() {
146-
fatal_ProcRes("jit failed!".to_string(), &proc_res);
146+
fatal_proc_rec("jit failed!".to_string(), &proc_res);
147147
}
148148
}
149149
}
@@ -172,7 +172,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
172172
"normal");
173173

174174
if !proc_res.status.success() {
175-
fatal_ProcRes(format!("pretty-printing failed in round {}", round),
175+
fatal_proc_rec(format!("pretty-printing failed in round {}", round),
176176
&proc_res);
177177
}
178178

@@ -204,21 +204,21 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
204204
let proc_res = typecheck_source(config, props, testfile, actual);
205205

206206
if !proc_res.status.success() {
207-
fatal_ProcRes("pretty-printed source does not typecheck".to_string(),
207+
fatal_proc_rec("pretty-printed source does not typecheck".to_string(),
208208
&proc_res);
209209
}
210210
if props.no_pretty_expanded { return }
211211

212212
// additionally, run `--pretty expanded` and try to build it.
213213
let proc_res = print_source(config, props, testfile, (*srcs.get(round)).clone(), "expanded");
214214
if !proc_res.status.success() {
215-
fatal_ProcRes(format!("pretty-printing (expanded) failed"), &proc_res);
215+
fatal_proc_rec(format!("pretty-printing (expanded) failed"), &proc_res);
216216
}
217217

218218
let ProcRes{ stdout: expanded_src, .. } = proc_res;
219219
let proc_res = typecheck_source(config, props, testfile, expanded_src);
220220
if !proc_res.status.success() {
221-
fatal_ProcRes(format!("pretty-printed source (expanded) does \
221+
fatal_proc_rec(format!("pretty-printed source (expanded) does \
222222
not typecheck"),
223223
&proc_res);
224224
}
@@ -326,7 +326,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
326326
// compile test file (it shoud have 'compile-flags:-g' in the header)
327327
let compiler_run_result = compile_test(config, props, testfile);
328328
if !compiler_run_result.status.success() {
329-
fatal_ProcRes("compilation failed!".to_string(), &compiler_run_result);
329+
fatal_proc_rec("compilation failed!".to_string(), &compiler_run_result);
330330
}
331331

332332
let exe_file = make_exe_name(config, testfile);
@@ -517,7 +517,7 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
517517
// compile test file (it shoud have 'compile-flags:-g' in the header)
518518
let compile_result = compile_test(config, props, testfile);
519519
if !compile_result.status.success() {
520-
fatal_ProcRes("compilation failed!".to_string(), &compile_result);
520+
fatal_proc_rec("compilation failed!".to_string(), &compile_result);
521521
}
522522

523523
let exe_file = make_exe_name(config, testfile);
@@ -560,7 +560,7 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
560560
let debugger_run_result = run_lldb(config, &exe_file, &debugger_script);
561561

562562
if !debugger_run_result.status.success() {
563-
fatal_ProcRes("Error while running LLDB".to_string(),
563+
fatal_proc_rec("Error while running LLDB".to_string(),
564564
&debugger_run_result);
565565
}
566566

@@ -720,7 +720,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
720720
}
721721
}
722722
if i != num_check_lines {
723-
fatal_ProcRes(format!("line not found in debugger output: {}",
723+
fatal_proc_rec(format!("line not found in debugger output: {}",
724724
check_lines.get(i).unwrap()),
725725
debugger_run_result);
726726
}
@@ -764,22 +764,22 @@ fn check_error_patterns(props: &TestProps,
764764
let missing_patterns =
765765
props.error_patterns.slice(next_err_idx, props.error_patterns.len());
766766
if missing_patterns.len() == 1u {
767-
fatal_ProcRes(format!("error pattern '{}' not found!",
767+
fatal_proc_rec(format!("error pattern '{}' not found!",
768768
missing_patterns[0]),
769769
proc_res);
770770
} else {
771771
for pattern in missing_patterns.iter() {
772772
error(format!("error pattern '{}' not found!", *pattern));
773773
}
774-
fatal_ProcRes("multiple error patterns not found".to_string(),
774+
fatal_proc_rec("multiple error patterns not found".to_string(),
775775
proc_res);
776776
}
777777
}
778778

779779
fn check_no_compiler_crash(proc_res: &ProcRes) {
780780
for line in proc_res.stderr.as_slice().lines() {
781781
if line.starts_with("error: internal compiler error:") {
782-
fatal_ProcRes("compiler encountered internal error".to_string(),
782+
fatal_proc_rec("compiler encountered internal error".to_string(),
783783
proc_res);
784784
}
785785
}
@@ -857,7 +857,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
857857
}
858858

859859
if !was_expected && is_compiler_error_or_warning(line) {
860-
fatal_ProcRes(format!("unexpected compiler error or warning: '{}'",
860+
fatal_proc_rec(format!("unexpected compiler error or warning: '{}'",
861861
line),
862862
proc_res);
863863
}
@@ -866,7 +866,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
866866
for (i, &flag) in found_flags.iter().enumerate() {
867867
if !flag {
868868
let ee = expected_errors.get(i);
869-
fatal_ProcRes(format!("expected {} on line {} not found: {}",
869+
fatal_proc_rec(format!("expected {} on line {} not found: {}",
870870
ee.kind, ee.line, ee.msg),
871871
proc_res);
872872
}
@@ -1047,7 +1047,7 @@ fn compose_and_run_compiler(
10471047
config.compile_lib_path.as_slice(),
10481048
None);
10491049
if !auxres.status.success() {
1050-
fatal_ProcRes(
1050+
fatal_proc_rec(
10511051
format!("auxiliary build of {} failed to compile: ",
10521052
abs_ab.display()),
10531053
&auxres);
@@ -1286,7 +1286,7 @@ fn error(err: String) { println!("\nerror: {}", err); }
12861286

12871287
fn fatal(err: String) -> ! { error(err); fail!(); }
12881288

1289-
fn fatal_ProcRes(err: String, proc_res: &ProcRes) -> ! {
1289+
fn fatal_proc_rec(err: String, proc_res: &ProcRes) -> ! {
12901290
print!("\n\
12911291
error: {}\n\
12921292
status: {}\n\
@@ -1562,35 +1562,35 @@ fn run_codegen_test(config: &Config, props: &TestProps,
15621562

15631563
let mut proc_res = compile_test_and_save_bitcode(config, props, testfile);
15641564
if !proc_res.status.success() {
1565-
fatal_ProcRes("compilation failed!".to_string(), &proc_res);
1565+
fatal_proc_rec("compilation failed!".to_string(), &proc_res);
15661566
}
15671567

15681568
proc_res = extract_function_from_bitcode(config, props, "test", testfile, "");
15691569
if !proc_res.status.success() {
1570-
fatal_ProcRes("extracting 'test' function failed".to_string(),
1570+
fatal_proc_rec("extracting 'test' function failed".to_string(),
15711571
&proc_res);
15721572
}
15731573

15741574
proc_res = disassemble_extract(config, props, testfile, "");
15751575
if !proc_res.status.success() {
1576-
fatal_ProcRes("disassembling extract failed".to_string(), &proc_res);
1576+
fatal_proc_rec("disassembling extract failed".to_string(), &proc_res);
15771577
}
15781578

15791579

15801580
let mut proc_res = compile_cc_with_clang_and_save_bitcode(config, props, testfile);
15811581
if !proc_res.status.success() {
1582-
fatal_ProcRes("compilation failed!".to_string(), &proc_res);
1582+
fatal_proc_rec("compilation failed!".to_string(), &proc_res);
15831583
}
15841584

15851585
proc_res = extract_function_from_bitcode(config, props, "test", testfile, "clang");
15861586
if !proc_res.status.success() {
1587-
fatal_ProcRes("extracting 'test' function failed".to_string(),
1587+
fatal_proc_rec("extracting 'test' function failed".to_string(),
15881588
&proc_res);
15891589
}
15901590

15911591
proc_res = disassemble_extract(config, props, testfile, "clang");
15921592
if !proc_res.status.success() {
1593-
fatal_ProcRes("disassembling extract failed".to_string(), &proc_res);
1593+
fatal_proc_rec("disassembling extract failed".to_string(), &proc_res);
15941594
}
15951595

15961596
let base = output_base_name(config, testfile);

src/doc/guide-ffi.md

+1
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ extern crate libc;
476476
477477
#[cfg(target_os = "win32", target_arch = "x86")]
478478
#[link(name = "kernel32")]
479+
#[allow(non_snake_case_functions)]
479480
extern "stdcall" {
480481
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> libc::c_int;
481482
}

src/libcollections/smallintmap.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,20 @@ mod test_map {
296296

297297
// given a new key, initialize it with this new count,
298298
// given an existing key, add more to its count
299-
fn addMoreToCount(_k: uint, v0: uint, v1: uint) -> uint {
299+
fn add_more_to_count(_k: uint, v0: uint, v1: uint) -> uint {
300300
v0 + v1
301301
}
302302

303-
fn addMoreToCount_simple(v0: uint, v1: uint) -> uint {
303+
fn add_more_to_count_simple(v0: uint, v1: uint) -> uint {
304304
v0 + v1
305305
}
306306

307307
// count integers
308-
map.update(3, 1, addMoreToCount_simple);
309-
map.update_with_key(9, 1, addMoreToCount);
310-
map.update(3, 7, addMoreToCount_simple);
311-
map.update_with_key(5, 3, addMoreToCount);
312-
map.update_with_key(3, 2, addMoreToCount);
308+
map.update(3, 1, add_more_to_count_simple);
309+
map.update_with_key(9, 1, add_more_to_count);
310+
map.update(3, 7, add_more_to_count_simple);
311+
map.update_with_key(5, 3, add_more_to_count);
312+
map.update_with_key(3, 2, add_more_to_count);
313313

314314
// check the total counts
315315
assert_eq!(map.find(&3).unwrap(), &10);

src/libcore/char.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -23,6 +23,7 @@
2323
//! however the converse is not always true due to the above range limits
2424
//! and, as such, should be performed via the `from_u32` function..
2525
26+
#![allow(non_snake_case_functions)]
2627

2728
use mem::transmute;
2829
use option::{None, Option, Some};

src/libcore/unicode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// NOTE: The following code was generated by "src/etc/unicode.py", do not edit directly
1212

13-
#![allow(missing_doc, non_uppercase_statics)]
13+
#![allow(missing_doc, non_uppercase_statics, non_snake_case_functions)]
1414

1515

1616
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {

src/libdebug/reflect.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -42,11 +42,12 @@ pub fn align(size: uint, align: uint) -> uint {
4242
pub struct MovePtrAdaptor<V> {
4343
inner: V
4444
}
45-
pub fn MovePtrAdaptor<V:TyVisitor + MovePtr>(v: V) -> MovePtrAdaptor<V> {
46-
MovePtrAdaptor { inner: v }
47-
}
4845

4946
impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
47+
pub fn new(v: V) -> MovePtrAdaptor<V> {
48+
MovePtrAdaptor { inner: v }
49+
}
50+
5051
#[inline]
5152
pub fn bump(&mut self, sz: uint) {
5253
self.inner.move_ptr(|p| ((p as uint) + sz) as *u8)

src/libdebug/repr.rs

+14-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -99,17 +99,6 @@ pub struct ReprVisitor<'a> {
9999
last_err: Option<io::IoError>,
100100
}
101101

102-
pub fn ReprVisitor<'a>(ptr: *u8,
103-
writer: &'a mut io::Writer) -> ReprVisitor<'a> {
104-
ReprVisitor {
105-
ptr: ptr,
106-
ptr_stk: vec!(),
107-
var_stk: vec!(),
108-
writer: writer,
109-
last_err: None,
110-
}
111-
}
112-
113102
impl<'a> MovePtr for ReprVisitor<'a> {
114103
#[inline]
115104
fn move_ptr(&mut self, adjustment: |*u8| -> *u8) {
@@ -125,6 +114,15 @@ impl<'a> MovePtr for ReprVisitor<'a> {
125114

126115
impl<'a> ReprVisitor<'a> {
127116
// Various helpers for the TyVisitor impl
117+
pub fn new(ptr: *u8, writer: &'a mut io::Writer) -> ReprVisitor<'a> {
118+
ReprVisitor {
119+
ptr: ptr,
120+
ptr_stk: vec!(),
121+
var_stk: vec!(),
122+
writer: writer,
123+
last_err: None,
124+
}
125+
}
128126

129127
#[inline]
130128
pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T| -> bool) -> bool {
@@ -141,16 +139,8 @@ impl<'a> ReprVisitor<'a> {
141139
#[inline]
142140
pub fn visit_ptr_inner(&mut self, ptr: *u8, inner: *TyDesc) -> bool {
143141
unsafe {
144-
// This should call the constructor up above, but due to limiting
145-
// issues we have to recreate it here.
146-
let u = ReprVisitor {
147-
ptr: ptr,
148-
ptr_stk: vec!(),
149-
var_stk: vec!(),
150-
writer: mem::transmute_copy(&self.writer),
151-
last_err: None,
152-
};
153-
let mut v = reflect::MovePtrAdaptor(u);
142+
let u = ReprVisitor::new(ptr, mem::transmute_copy(&self.writer));
143+
let mut v = reflect::MovePtrAdaptor::new(u);
154144
// Obviously this should not be a thing, but blame #8401 for now
155145
visit_tydesc(inner, &mut v as &mut TyVisitor);
156146
match v.unwrap().last_err {
@@ -584,8 +574,8 @@ pub fn write_repr<T>(writer: &mut io::Writer, object: &T) -> io::IoResult<()> {
584574
unsafe {
585575
let ptr = object as *T as *u8;
586576
let tydesc = get_tydesc::<T>();
587-
let u = ReprVisitor(ptr, writer);
588-
let mut v = reflect::MovePtrAdaptor(u);
577+
let u = ReprVisitor::new(ptr, writer);
578+
let mut v = reflect::MovePtrAdaptor::new(u);
589579
visit_tydesc(tydesc, &mut v as &mut TyVisitor);
590580
match v.unwrap().last_err {
591581
Some(e) => Err(e),

src/liblibc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -71,6 +71,7 @@
7171
*/
7272

7373
#![allow(non_camel_case_types)]
74+
#![allow(non_snake_case_functions)]
7475
#![allow(non_uppercase_statics)]
7576
#![allow(missing_doc)]
7677
#![allow(uppercase_variables)]

0 commit comments

Comments
 (0)