Skip to content

Commit 2438434

Browse files
committed
compiletest: rustfmt
1 parent b559710 commit 2438434

File tree

9 files changed

+247
-232
lines changed

9 files changed

+247
-232
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
pub use self::Mode::*;
1111

1212
use std::fmt;
13-
use std::str::FromStr;
1413
use std::path::PathBuf;
14+
use std::str::FromStr;
1515

1616
use test::ColorConfig;
1717

@@ -103,7 +103,7 @@ pub enum CompareMode {
103103
impl CompareMode {
104104
pub(crate) fn to_str(&self) -> &'static str {
105105
match *self {
106-
CompareMode::Nll => "nll"
106+
CompareMode::Nll => "nll",
107107
}
108108
}
109109

@@ -253,16 +253,21 @@ pub struct TestPaths {
253253
}
254254

255255
/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
256-
pub fn expected_output_path(testpaths: &TestPaths,
257-
revision: Option<&str>,
258-
compare_mode: &Option<CompareMode>,
259-
kind: &str) -> PathBuf {
260-
256+
pub fn expected_output_path(
257+
testpaths: &TestPaths,
258+
revision: Option<&str>,
259+
compare_mode: &Option<CompareMode>,
260+
kind: &str,
261+
) -> PathBuf {
261262
assert!(UI_EXTENSIONS.contains(&kind));
262263
let mut parts = Vec::new();
263264

264-
if let Some(x) = revision { parts.push(x); }
265-
if let Some(ref x) = *compare_mode { parts.push(x.to_str()); }
265+
if let Some(x) = revision {
266+
parts.push(x);
267+
}
268+
if let Some(ref x) = *compare_mode {
269+
parts.push(x.to_str());
270+
}
266271
parts.push(kind);
267272

268273
let extension = parts.join(".");

src/tools/compiletest/src/errors.rs

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use self::WhichLine::*;
1111

1212
use std::fmt;
1313
use std::fs::File;
14-
use std::io::BufReader;
1514
use std::io::prelude::*;
15+
use std::io::BufReader;
1616
use std::path::Path;
1717
use std::str::FromStr;
1818

@@ -35,8 +35,7 @@ impl FromStr for ErrorKind {
3535
"ERROR" => Ok(ErrorKind::Error),
3636
"NOTE" => Ok(ErrorKind::Note),
3737
"SUGGESTION" => Ok(ErrorKind::Suggestion),
38-
"WARN" |
39-
"WARNING" => Ok(ErrorKind::Warning),
38+
"WARN" | "WARNING" => Ok(ErrorKind::Warning),
4039
_ => Err(()),
4140
}
4241
}
@@ -101,61 +100,74 @@ pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<Error> {
101100
rdr.lines()
102101
.enumerate()
103102
.filter_map(|(line_num, line)| {
104-
parse_expected(last_nonfollow_error, line_num + 1, &line.unwrap(), &tag)
105-
.map(|(which, error)| {
103+
parse_expected(last_nonfollow_error, line_num + 1, &line.unwrap(), &tag).map(
104+
|(which, error)| {
106105
match which {
107106
FollowPrevious(_) => {}
108107
_ => last_nonfollow_error = Some(error.line_num),
109108
}
110109
error
111-
})
110+
},
111+
)
112112
})
113113
.collect()
114114
}
115115

116-
fn parse_expected(last_nonfollow_error: Option<usize>,
117-
line_num: usize,
118-
line: &str,
119-
tag: &str)
120-
-> Option<(WhichLine, Error)> {
116+
fn parse_expected(
117+
last_nonfollow_error: Option<usize>,
118+
line_num: usize,
119+
line: &str,
120+
tag: &str,
121+
) -> Option<(WhichLine, Error)> {
121122
let start = match line.find(tag) {
122123
Some(i) => i,
123124
None => return None,
124125
};
125126
let (follow, adjusts) = if line[start + tag.len()..].chars().next().unwrap() == '|' {
126127
(true, 0)
127128
} else {
128-
(false, line[start + tag.len()..].chars().take_while(|c| *c == '^').count())
129+
(
130+
false,
131+
line[start + tag.len()..]
132+
.chars()
133+
.take_while(|c| *c == '^')
134+
.count(),
135+
)
129136
};
130137
let kind_start = start + tag.len() + adjusts + (follow as usize);
131138
let (kind, msg);
132139
match line[kind_start..]
133140
.split_whitespace()
134141
.next()
135142
.expect("Encountered unexpected empty comment")
136-
.parse::<ErrorKind>() {
143+
.parse::<ErrorKind>()
144+
{
137145
Ok(k) => {
138146
// If we find `//~ ERROR foo` or something like that:
139147
kind = Some(k);
140148
let letters = line[kind_start..].chars();
141-
msg = letters.skip_while(|c| c.is_whitespace())
149+
msg = letters
150+
.skip_while(|c| c.is_whitespace())
142151
.skip_while(|c| !c.is_whitespace())
143152
.collect::<String>();
144153
}
145154
Err(_) => {
146155
// Otherwise we found `//~ foo`:
147156
kind = None;
148157
let letters = line[kind_start..].chars();
149-
msg = letters.skip_while(|c| c.is_whitespace())
158+
msg = letters
159+
.skip_while(|c| c.is_whitespace())
150160
.collect::<String>();
151161
}
152162
}
153163
let msg = msg.trim().to_owned();
154164

155165
let (which, line_num) = if follow {
156166
assert_eq!(adjusts, 0, "use either //~| or //~^, not both.");
157-
let line_num = last_nonfollow_error.expect("encountered //~| without \
158-
preceding //~^ line.");
167+
let line_num = last_nonfollow_error.expect(
168+
"encountered //~| without \
169+
preceding //~^ line.",
170+
);
159171
(FollowPrevious(line_num), line_num)
160172
} else {
161173
let which = if adjusts > 0 {
@@ -167,16 +179,16 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
167179
(which, line_num)
168180
};
169181

170-
debug!("line={} tag={:?} which={:?} kind={:?} msg={:?}",
171-
line_num,
172-
tag,
173-
which,
174-
kind,
175-
msg);
176-
Some((which,
177-
Error {
178-
line_num,
179-
kind,
180-
msg,
181-
}))
182+
debug!(
183+
"line={} tag={:?} which={:?} kind={:?} msg={:?}",
184+
line_num, tag, which, kind, msg
185+
);
186+
Some((
187+
which,
188+
Error {
189+
line_num,
190+
kind,
191+
msg,
192+
},
193+
))
182194
}

src/tools/compiletest/src/header.rs

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
use std::env;
1212
use std::fs::File;
13-
use std::io::BufReader;
1413
use std::io::prelude::*;
14+
use std::io::BufReader;
1515
use std::path::{Path, PathBuf};
1616

17-
use common::Config;
1817
use common;
18+
use common::Config;
1919
use util;
2020

2121
use extract_gdb_version;
@@ -38,19 +38,14 @@ impl EarlyProps {
3838
revisions: vec![],
3939
};
4040

41-
iter_header(testfile,
42-
None,
43-
&mut |ln| {
41+
iter_header(testfile, None, &mut |ln| {
4442
// we should check if any only-<platform> exists and if it exists
4543
// and does not matches the current platform, skip the test
46-
props.ignore =
47-
props.ignore ||
48-
config.parse_cfg_name_directive(ln, "ignore") ||
49-
(config.has_cfg_prefix(ln, "only") &&
50-
!config.parse_cfg_name_directive(ln, "only")) ||
51-
ignore_gdb(config, ln) ||
52-
ignore_lldb(config, ln) ||
53-
ignore_llvm(config, ln);
44+
props.ignore = props.ignore || config.parse_cfg_name_directive(ln, "ignore")
45+
|| (config.has_cfg_prefix(ln, "only")
46+
&& !config.parse_cfg_name_directive(ln, "only"))
47+
|| ignore_gdb(config, ln) || ignore_lldb(config, ln)
48+
|| ignore_llvm(config, ln);
5449

5550
if let Some(s) = config.parse_aux_build(ln) {
5651
props.aux.push(s);
@@ -149,7 +144,7 @@ impl EarlyProps {
149144

150145
fn ignore_llvm(config: &Config, line: &str) -> bool {
151146
if config.system_llvm && line.starts_with("no-system-llvm") {
152-
return true;
147+
return true;
153148
}
154149
if let Some(ref actual_version) = config.llvm_version {
155150
if line.starts_with("min-llvm-version") {
@@ -272,11 +267,7 @@ impl TestProps {
272267
}
273268
}
274269

275-
pub fn from_aux_file(&self,
276-
testfile: &Path,
277-
cfg: Option<&str>,
278-
config: &Config)
279-
-> Self {
270+
pub fn from_aux_file(&self, testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
280271
let mut props = TestProps::new();
281272

282273
// copy over select properties to the aux build:
@@ -296,20 +287,15 @@ impl TestProps {
296287
/// tied to a particular revision `foo` (indicated by writing
297288
/// `//[foo]`), then the property is ignored unless `cfg` is
298289
/// `Some("foo")`.
299-
fn load_from(&mut self,
300-
testfile: &Path,
301-
cfg: Option<&str>,
302-
config: &Config) {
303-
iter_header(testfile,
304-
cfg,
305-
&mut |ln| {
290+
fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
291+
iter_header(testfile, cfg, &mut |ln| {
306292
if let Some(ep) = config.parse_error_pattern(ln) {
307293
self.error_patterns.push(ep);
308294
}
309295

310296
if let Some(flags) = config.parse_compile_flags(ln) {
311-
self.compile_flags.extend(flags.split_whitespace()
312-
.map(|s| s.to_owned()));
297+
self.compile_flags
298+
.extend(flags.split_whitespace().map(|s| s.to_owned()));
313299
}
314300

315301
if let Some(r) = config.parse_revisions(ln) {
@@ -382,8 +368,7 @@ impl TestProps {
382368

383369
if !self.compile_pass {
384370
// run-pass implies must_compile_sucessfully
385-
self.compile_pass =
386-
config.parse_compile_pass(ln) || self.run_pass;
371+
self.compile_pass = config.parse_compile_pass(ln) || self.run_pass;
387372
}
388373

389374
if !self.skip_trans {
@@ -453,7 +438,7 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
453438
None => false,
454439
};
455440
if matches {
456-
it(ln[(close_brace + 1) ..].trim_left());
441+
it(ln[(close_brace + 1)..].trim_left());
457442
}
458443
} else {
459444
panic!("malformed condition directive: expected `{}foo]`, found `{}`",
@@ -554,9 +539,7 @@ impl Config {
554539
fn parse_env(&self, line: &str, name: &str) -> Option<(String, String)> {
555540
self.parse_name_value_directive(line, name).map(|nv| {
556541
// nv is either FOO or FOO=BAR
557-
let mut strs: Vec<String> = nv.splitn(2, '=')
558-
.map(str::to_owned)
559-
.collect();
542+
let mut strs: Vec<String> = nv.splitn(2, '=').map(str::to_owned).collect();
560543

561544
match strs.len() {
562545
1 => (strs.pop().unwrap(), "".to_owned()),
@@ -599,7 +582,10 @@ impl Config {
599582
/// or `normalize-stderr-32bit`. Returns `true` if the line matches it.
600583
fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> bool {
601584
if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
602-
let name = line[prefix.len()+1 ..].split(&[':', ' '][..]).next().unwrap();
585+
let name = line[prefix.len() + 1..]
586+
.split(&[':', ' '][..])
587+
.next()
588+
.unwrap();
603589

604590
name == "test" ||
605591
util::matches_os(&self.target, name) || // target
@@ -612,8 +598,7 @@ impl Config {
612598
common::DebugInfoLldb => name == "lldb",
613599
common::Pretty => name == "pretty",
614600
_ => false,
615-
} ||
616-
(self.target != self.host && name == "cross-compile")
601+
} || (self.target != self.host && name == "cross-compile")
617602
} else {
618603
false
619604
}
@@ -631,14 +616,14 @@ impl Config {
631616
// the line says "ignore-x86_64".
632617
line.starts_with(directive) && match line.as_bytes().get(directive.len()) {
633618
None | Some(&b' ') | Some(&b':') => true,
634-
_ => false
619+
_ => false,
635620
}
636621
}
637622

638623
pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
639624
let colon = directive.len();
640625
if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') {
641-
let value = line[(colon + 1) ..].to_owned();
626+
let value = line[(colon + 1)..].to_owned();
642627
debug!("{}: {}", directive, value);
643628
Some(expand_variables(value, self))
644629
} else {
@@ -665,8 +650,10 @@ impl Config {
665650
}
666651

667652
pub fn lldb_version_to_int(version_string: &str) -> isize {
668-
let error_string = format!("Encountered LLDB version string with unexpected format: {}",
669-
version_string);
653+
let error_string = format!(
654+
"Encountered LLDB version string with unexpected format: {}",
655+
version_string
656+
);
670657
version_string.parse().expect(&error_string)
671658
}
672659

@@ -713,6 +700,6 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
713700
None => return None,
714701
};
715702
let result = line[begin..end].to_owned();
716-
*line = &line[end+1..];
703+
*line = &line[end + 1..];
717704
Some(result)
718705
}

0 commit comments

Comments
 (0)