Skip to content

Commit 0e53f19

Browse files
authored
Rollup merge of rust-lang#93680 - Mark-Simulacrum:drop-json-reader, r=bjorn3
Drop json::from_reader Just a small cleanup -- this was essentially unused; the one use site is better suited to reading from &str regardless.
2 parents 3ad5779 + 0fb2b7a commit 0e53f19

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
@@ -2148,8 +2148,8 @@ impl Target {
21482148
use std::fs;
21492149

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

0 commit comments

Comments
 (0)