From 69c385e8105c7fad07a5728979e86a2a6a5e88ba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Jul 2018 16:32:27 +0300 Subject: [PATCH] Fix compilation for real --- cli/src/main.rs | 6 +++--- tools/src/lib.rs | 5 ++--- tools/src/main.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 94183c552e8..f8787813782 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -55,12 +55,12 @@ fn read_stdin() -> Result { fn render_test(file: &Path, line: usize) -> Result<(String, String)> { let text = fs::read_to_string(file)?; let tests = collect_tests(&text); - let test = tests.into_iter().find(|t| { - t.start_line <= line && line <= t.start_line + t.text.lines().count() + let test = tests.into_iter().find(|(start_line, t)| { + *start_line <= line && line <= *start_line + t.text.lines().count() }); let test = match test { None => bail!("No test found at line {} at {}", line, file.display()), - Some(test) => test, + Some((_start_line, test)) => test, }; let file = libsyntax2::parse(test.text.clone()); let tree = libsyntax2::utils::dump_tree(&file); diff --git a/tools/src/lib.rs b/tools/src/lib.rs index 1b7ef3ca9c1..7a0de3e3c80 100644 --- a/tools/src/lib.rs +++ b/tools/src/lib.rs @@ -5,7 +5,6 @@ use itertools::Itertools; #[derive(Debug, Eq)] pub struct Test { - pub start_line: usize, pub name: String, pub text: String, } @@ -22,7 +21,7 @@ impl hash::Hash for Test { } } -pub fn collect_tests(s: &str) -> Vec { +pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { let mut res = vec![]; let prefix = "// "; let comment_blocks = s @@ -52,7 +51,7 @@ pub fn collect_tests(s: &str) -> Vec { "\n" ); assert!(!text.trim().is_empty() && text.ends_with("\n")); - res.push(Test { start_line, name, text }) + res.push((start_line, Test {name, text })) } res } diff --git a/tools/src/main.rs b/tools/src/main.rs index 783e3395b92..6786b81cac7 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs @@ -108,7 +108,7 @@ fn tests_from_dir(dir: &Path) -> Result> { } let text = fs::read_to_string(entry.path())?; - for test in collect_tests(&text) { + for (_, test) in collect_tests(&text) { if let Some(old_test) = res.replace(test) { bail!("Duplicate test: {}", old_test.name) }