Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit de63283

Browse files
committed
Merge #54
54: Don't loop{} on errors during suggestion parsing r=killercup a=oli-obk
2 parents a71ff8a + c057d60 commit de63283

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ use std::collections::HashSet;
77
pub mod diagnostics;
88
use diagnostics::{Diagnostic, DiagnosticSpan};
99

10-
pub fn get_suggestions_from_json<S: ::std::hash::BuildHasher>(input: &str, only: &HashSet<String, S>) -> Vec<Suggestion> {
11-
serde_json::Deserializer::from_str(input)
12-
.into_iter::<Diagnostic>()
13-
// eat parsing errors
14-
.flat_map(|line| line.ok())
10+
pub fn get_suggestions_from_json<S: ::std::hash::BuildHasher>(
11+
input: &str,
12+
only: &HashSet<String, S>,
13+
) -> serde_json::error::Result<Vec<Suggestion>> {
14+
let mut result = Vec::new();
15+
for cargo_msg in serde_json::Deserializer::from_str(input).into_iter::<Diagnostic>() {
1516
// One diagnostic line might have multiple suggestions
16-
.filter_map(|cargo_msg| collect_suggestions(&cargo_msg, only))
17-
.collect()
17+
result.extend(collect_suggestions(&cargo_msg?, only));
18+
}
19+
Ok(result)
1820
}
1921

2022
#[derive(Debug, Copy, Clone, Hash, PartialEq)]

tests/everything.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
125125
debug!("next up: {:?}", file);
126126
let code = read_file(file)?;
127127
let errors = compile_and_get_json_errors(file)?;
128-
let suggestions = rustfix::get_suggestions_from_json(&errors, &HashSet::new());
128+
let suggestions = rustfix::get_suggestions_from_json(&errors, &HashSet::new()).expect("could not load suggestions");
129129

130130
if std::env::var("RUSTFIX_TEST_RECORD_JSON").is_ok() {
131131
use std::io::Write;
@@ -134,7 +134,7 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
134134
}
135135

136136
let expected_json = read_file(&json_file)?;
137-
let expected_suggestions = rustfix::get_suggestions_from_json(&expected_json, &HashSet::new());
137+
let expected_suggestions = rustfix::get_suggestions_from_json(&expected_json, &HashSet::new()).expect("could not load expected suggesitons");
138138
assert_eq!(
139139
expected_suggestions,
140140
suggestions,

0 commit comments

Comments
 (0)