Skip to content

Commit 0fb2b7a

Browse files
Drop json::from_reader
Performing UTF-8 decode outside the JSON module makes more sense in almost all cases.
1 parent cb18e83 commit 0fb2b7a

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

compiler/rustc_serialize/src/json.rs

-22
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ use self::ParserState::*;
185185

186186
use std::borrow::Cow;
187187
use std::collections::{BTreeMap, HashMap};
188-
use std::io;
189-
use std::io::prelude::*;
190188
use std::mem::swap;
191189
use std::num::FpCategory as Fp;
192190
use std::ops::Index;
@@ -250,7 +248,6 @@ pub enum ErrorCode {
250248
pub enum ParserError {
251249
/// msg, line, col
252250
SyntaxError(ErrorCode, usize, usize),
253-
IoError(io::ErrorKind, String),
254251
}
255252

256253
// Builder and Parser have the same errors.
@@ -329,10 +326,6 @@ impl fmt::Display for ErrorCode {
329326
}
330327
}
331328

332-
fn io_error_to_error(io: io::Error) -> ParserError {
333-
IoError(io.kind(), io.to_string())
334-
}
335-
336329
impl fmt::Display for ParserError {
337330
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
338331
// FIXME this should be a nicer error
@@ -2163,21 +2156,6 @@ impl<T: Iterator<Item = char>> Builder<T> {
21632156
}
21642157
}
21652158

2166-
/// Decodes a json value from an `&mut io::Read`
2167-
pub fn from_reader(rdr: &mut dyn Read) -> Result<Json, BuilderError> {
2168-
let mut contents = Vec::new();
2169-
match rdr.read_to_end(&mut contents) {
2170-
Ok(c) => c,
2171-
Err(e) => return Err(io_error_to_error(e)),
2172-
};
2173-
let s = match str::from_utf8(&contents).ok() {
2174-
Some(s) => s,
2175-
_ => return Err(SyntaxError(NotUtf8, 0, 0)),
2176-
};
2177-
let mut builder = Builder::new(s.chars());
2178-
builder.build()
2179-
}
2180-
21812159
/// Decodes a json value from a string
21822160
pub fn from_str(s: &str) -> Result<Json, BuilderError> {
21832161
let mut builder = Builder::new(s.chars());

compiler/rustc_target/src/spec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2145,8 +2145,8 @@ impl Target {
21452145
use std::fs;
21462146

21472147
fn load_file(path: &Path) -> Result<(Target, TargetWarnings), String> {
2148-
let contents = fs::read(path).map_err(|e| e.to_string())?;
2149-
let obj = json::from_reader(&mut &contents[..]).map_err(|e| e.to_string())?;
2148+
let contents = fs::read_to_string(path).map_err(|e| e.to_string())?;
2149+
let obj = json::from_str(&contents).map_err(|e| e.to_string())?;
21502150
Target::from_json(obj)
21512151
}
21522152

0 commit comments

Comments
 (0)