Skip to content

Commit 9254b02

Browse files
committed
Replace IoError(io::Error) with IoError(Rc<io::Error>)
As per rust-lang/rust#23919, the Clone and PartialEq traits were removed from io::Error, breaking the derived Clone and PartialEq trait of ParserError. Use Rc<io::Error> to get Clone back, and implement PartialEq manually. [breaking-change] Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 6f2fb38 commit 9254b02

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/json.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ use std::io::prelude::*;
243243
use std::mem::swap;
244244
use std::num::{Float, Int};
245245
use std::ops::Index;
246+
use std::rc::Rc;
246247
use std::str::FromStr;
247248
use std::string;
248249
use std::{char, f64, fmt, io, str};
@@ -294,11 +295,22 @@ pub enum ErrorCode {
294295
NotUtf8,
295296
}
296297

297-
#[derive(Clone, PartialEq, Debug)]
298+
#[derive(Clone, Debug)]
298299
pub enum ParserError {
299300
/// msg, line, col
300301
SyntaxError(ErrorCode, usize, usize),
301-
IoError(io::Error),
302+
IoError(Rc<io::Error>),
303+
}
304+
305+
impl PartialEq for ParserError {
306+
fn eq(&self, other: &ParserError) -> bool {
307+
match (self, other) {
308+
(&SyntaxError(msg0, line0, col0), &SyntaxError(msg1, line1, col1)) =>
309+
msg0 == msg1 && line0 == line1 && col0 == col1,
310+
(&IoError(_), _) => false,
311+
(_, &IoError(_)) => false,
312+
}
313+
}
302314
}
303315

304316
// Builder and Parser have the same errors.
@@ -372,7 +384,7 @@ impl fmt::Debug for ErrorCode {
372384
}
373385

374386
fn io_error_to_error(err: io::Error) -> ParserError {
375-
IoError(err)
387+
IoError(Rc::new(err))
376388
}
377389

378390
impl StdError for DecoderError {

0 commit comments

Comments
 (0)