From e1048b5ab64cceba5ce8edb1f41614e063edb78d Mon Sep 17 00:00:00 2001 From: Corey Farwell <coreyf@rwell.org> Date: Wed, 9 Mar 2016 21:44:35 -0800 Subject: [PATCH 1/2] Prefer `Option::expect` over explicit unwrapping. --- src/compiletest/errors.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index 44634e4d565ff..264e32f1d06c0 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -93,9 +93,8 @@ fn parse_expected(last_nonfollow_error: Option<usize>, let (which, line) = if follow { assert!(adjusts == 0, "use either //~| or //~^, not both."); - let line = last_nonfollow_error.unwrap_or_else(|| { - panic!("encountered //~| without preceding //~^ line.") - }); + let line = last_nonfollow_error.expect("encountered //~| without \ + preceding //~^ line."); (FollowPrevious(line), line) } else { let which = From 410333be64c23e9b38c81cdd14cae20cffa3f3c8 Mon Sep 17 00:00:00 2001 From: Corey Farwell <coreyf@rwell.org> Date: Wed, 9 Mar 2016 22:13:51 -0800 Subject: [PATCH 2/2] Differentiate "line" and "line number" variable names. --- src/compiletest/errors.rs | 25 ++++++++++++------------- src/compiletest/runtest.rs | 4 ++-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index 264e32f1d06c0..c1fbfcda47559 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -15,7 +15,7 @@ use std::io::prelude::*; use std::path::Path; pub struct ExpectedError { - pub line: usize, + pub line_num: usize, pub kind: String, pub msg: String, } @@ -53,15 +53,15 @@ pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<ExpectedError> { rdr.lines() .enumerate() - .filter_map(|(line_no, ln)| { + .filter_map(|(line_num, line)| { parse_expected(last_nonfollow_error, - line_no + 1, - &ln.unwrap(), + line_num + 1, + &line.unwrap(), &tag) .map(|(which, error)| { match which { FollowPrevious(_) => {} - _ => last_nonfollow_error = Some(error.line), + _ => last_nonfollow_error = Some(error.line_num), } error }) @@ -91,22 +91,21 @@ fn parse_expected(last_nonfollow_error: Option<usize>, .skip_while(|c| !c.is_whitespace()) .collect::<String>().trim().to_owned(); - let (which, line) = if follow { + let (which, line_num) = if follow { assert!(adjusts == 0, "use either //~| or //~^, not both."); - let line = last_nonfollow_error.expect("encountered //~| without \ - preceding //~^ line."); - (FollowPrevious(line), line) + let line_num = last_nonfollow_error.expect("encountered //~| without \ + preceding //~^ line."); + (FollowPrevious(line_num), line_num) } else { let which = if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine }; - let line = line_num - adjusts; - (which, line) + let line_num = line_num - adjusts; + (which, line_num) }; debug!("line={} tag={:?} which={:?} kind={:?} msg={:?}", line_num, tag, which, kind, msg); - - Some((which, ExpectedError { line: line, + Some((which, ExpectedError { line_num: line_num, kind: kind, msg: msg, })) } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 1d2f560f5f65b..8c3ee3fb5f4b6 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -1004,7 +1004,7 @@ fn check_expected_errors(revision: Option<&str>, } let prefixes = expected_errors.iter().map(|ee| { - let expected = format!("{}:{}:", testpaths.file.display(), ee.line); + let expected = format!("{}:{}:", testpaths.file.display(), ee.line_num); // On windows just translate all '\' path separators to '/' expected.replace(r"\", "/") }).collect::<Vec<String>>(); @@ -1076,7 +1076,7 @@ fn check_expected_errors(revision: Option<&str>, if !flag { let ee = &expected_errors[i]; error(revision, &format!("expected {} on line {} not found: {}", - ee.kind, ee.line, ee.msg)); + ee.kind, ee.line_num, ee.msg)); not_found += 1; } }