Skip to content

Commit 739056d

Browse files
authored
Rollup merge of rust-lang#52299 - ljedrz:dyn_libserialize, r=cramertj
Deny bare trait objects in src/libserialize Enforce `#![deny(bare_trait_objects)]` in `src/libserialize`.
2 parents 36a4b20 + 0878453 commit 739056d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/libserialize/json.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl From<fmt::Error> for EncoderError {
371371
pub type EncodeResult = Result<(), EncoderError>;
372372
pub type DecodeResult<T> = Result<T, DecoderError>;
373373

374-
fn escape_str(wr: &mut fmt::Write, v: &str) -> EncodeResult {
374+
fn escape_str(wr: &mut dyn fmt::Write, v: &str) -> EncodeResult {
375375
wr.write_str("\"")?;
376376

377377
let mut start = 0;
@@ -433,11 +433,11 @@ fn escape_str(wr: &mut fmt::Write, v: &str) -> EncodeResult {
433433
Ok(())
434434
}
435435

436-
fn escape_char(writer: &mut fmt::Write, v: char) -> EncodeResult {
436+
fn escape_char(writer: &mut dyn fmt::Write, v: char) -> EncodeResult {
437437
escape_str(writer, v.encode_utf8(&mut [0; 4]))
438438
}
439439

440-
fn spaces(wr: &mut fmt::Write, mut n: usize) -> EncodeResult {
440+
fn spaces(wr: &mut dyn fmt::Write, mut n: usize) -> EncodeResult {
441441
const BUF: &'static str = " ";
442442

443443
while n >= BUF.len() {
@@ -461,14 +461,14 @@ fn fmt_number_or_null(v: f64) -> string::String {
461461

462462
/// A structure for implementing serialization to JSON.
463463
pub struct Encoder<'a> {
464-
writer: &'a mut (fmt::Write+'a),
464+
writer: &'a mut (dyn fmt::Write+'a),
465465
is_emitting_map_key: bool,
466466
}
467467

468468
impl<'a> Encoder<'a> {
469469
/// Creates a new JSON encoder whose output will be written to the writer
470470
/// specified.
471-
pub fn new(writer: &'a mut fmt::Write) -> Encoder<'a> {
471+
pub fn new(writer: &'a mut dyn fmt::Write) -> Encoder<'a> {
472472
Encoder { writer: writer, is_emitting_map_key: false, }
473473
}
474474
}
@@ -707,15 +707,15 @@ impl<'a> ::Encoder for Encoder<'a> {
707707
/// Another encoder for JSON, but prints out human-readable JSON instead of
708708
/// compact data
709709
pub struct PrettyEncoder<'a> {
710-
writer: &'a mut (fmt::Write+'a),
710+
writer: &'a mut (dyn fmt::Write+'a),
711711
curr_indent: usize,
712712
indent: usize,
713713
is_emitting_map_key: bool,
714714
}
715715

716716
impl<'a> PrettyEncoder<'a> {
717717
/// Creates a new encoder whose output will be written to the specified writer
718-
pub fn new(writer: &'a mut fmt::Write) -> PrettyEncoder<'a> {
718+
pub fn new(writer: &'a mut dyn fmt::Write) -> PrettyEncoder<'a> {
719719
PrettyEncoder {
720720
writer,
721721
curr_indent: 0,
@@ -2053,7 +2053,7 @@ impl<T: Iterator<Item=char>> Builder<T> {
20532053
}
20542054

20552055
/// Decodes a json value from an `&mut io::Read`
2056-
pub fn from_reader(rdr: &mut Read) -> Result<Json, BuilderError> {
2056+
pub fn from_reader(rdr: &mut dyn Read) -> Result<Json, BuilderError> {
20572057
let mut contents = Vec::new();
20582058
match rdr.read_to_end(&mut contents) {
20592059
Ok(c) => c,

src/libserialize/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
Core encoding and decoding interfaces.
1515
*/
1616

17+
#![deny(bare_trait_objects)]
18+
1719
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
1820
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
1921
html_root_url = "https://doc.rust-lang.org/nightly/",

0 commit comments

Comments
 (0)