Skip to content

Commit

Permalink
Merge branch 'serde-rs:master' into json_map_with_capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 committed Jul 15, 2022
2 parents 7dd7d81 + 5b441a2 commit 6d18459
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 129 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: [beta, stable, 1.53.0, 1.46.0, 1.45.0, 1.40.0, 1.38.0, 1.36.0]
rust: [beta, stable, 1.56.1, 1.53.0, 1.46.0, 1.45.0, 1.40.0, 1.38.0, 1.36.0]
os: [ubuntu]
include:
- rust: stable
Expand All @@ -51,9 +51,9 @@ jobs:
- run: cargo check --manifest-path tests/crate/Cargo.toml --no-default-features --features alloc
- run: cargo check --manifest-path tests/crate/Cargo.toml --no-default-features --features alloc,raw_value
- run: cargo check --features preserve_order
if: matrix.rust != '1.45.0' && matrix.rust != '1.40.0' && matrix.rust != '1.38.0' && matrix.rust != '1.36.0'
if: matrix.rust != '1.53.0' && matrix.rust != '1.46.0' && matrix.rust != '1.45.0' && matrix.rust != '1.40.0' && matrix.rust != '1.38.0' && matrix.rust != '1.36.0'
- run: cargo check --manifest-path tests/crate/Cargo.toml --no-default-features --features alloc,preserve_order
if: matrix.rust != '1.45.0' && matrix.rust != '1.40.0' && matrix.rust != '1.38.0' && matrix.rust != '1.36.0'
if: matrix.rust != '1.53.0' && matrix.rust != '1.46.0' && matrix.rust != '1.45.0' && matrix.rust != '1.40.0' && matrix.rust != '1.38.0' && matrix.rust != '1.36.0'
- name: Build without std
run: |
rustup target add aarch64-unknown-none
Expand Down Expand Up @@ -101,5 +101,15 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz --debug
- uses: dtolnay/install@cargo-fuzz
- run: cargo fuzz build -O

outdated:
name: Outdated
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v3
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --workspace --exit-code 1
- run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "serde_json"
version = "1.0.81" # remember to update html_root_url
version = "1.0.82" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "A JSON serialization file format"
Expand Down
6 changes: 3 additions & 3 deletions fuzz/Cargo.toml
@@ -1,9 +1,8 @@
[package]
name = "serde_json-fuzz"
version = "0.0.0"
authors = ["David Korczynski <david@adalogics.com>"]
publish = false
edition = "2018"
edition = "2021"

[package.metadata]
cargo-fuzz = true
Expand All @@ -15,6 +14,7 @@ serde_json = { path = ".." }
[[bin]]
name = "from_slice"
path = "fuzz_targets/from_slice.rs"
test = false
doc = false

# Prevent this from interfering with workspaces
[workspace]
12 changes: 6 additions & 6 deletions src/error.rs
Expand Up @@ -284,9 +284,9 @@ impl Error {

impl Display for ErrorCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ErrorCode::Message(ref msg) => f.write_str(msg),
ErrorCode::Io(ref err) => Display::fmt(err, f),
match self {
ErrorCode::Message(msg) => f.write_str(msg),
ErrorCode::Io(err) => Display::fmt(err, f),
ErrorCode::EofWhileParsingList => f.write_str("EOF while parsing a list"),
ErrorCode::EofWhileParsingObject => f.write_str("EOF while parsing an object"),
ErrorCode::EofWhileParsingString => f.write_str("EOF while parsing a string"),
Expand Down Expand Up @@ -318,8 +318,8 @@ impl Display for ErrorCode {
impl serde::de::StdError for Error {
#[cfg(feature = "std")]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self.err.code {
ErrorCode::Io(ref err) => Some(err),
match &self.err.code {
ErrorCode::Io(err) => Some(err),
_ => None,
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ fn parse_line_col(msg: &mut String) -> Option<(usize, usize)> {
}

fn starts_with_digit(slice: &str) -> bool {
match slice.as_bytes().get(0) {
match slice.as_bytes().first() {
None => false,
Some(&byte) => byte >= b'0' && byte <= b'9',
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Expand Up @@ -300,14 +300,15 @@
//! [macro]: https://docs.serde.rs/serde_json/macro.json.html
//! [`serde-json-core`]: https://github.com/rust-embedded-community/serde-json-core

#![doc(html_root_url = "https://docs.rs/serde_json/1.0.81")]
#![doc(html_root_url = "https://docs.rs/serde_json/1.0.82")]
// Ignored clippy lints
#![allow(
clippy::collapsible_else_if,
clippy::comparison_chain,
clippy::deprecated_cfg_attr,
clippy::doc_markdown,
clippy::excessive_precision,
clippy::explicit_auto_deref,
clippy::float_cmp,
clippy::manual_range_contains,
clippy::match_like_matches_macro,
Expand Down
14 changes: 7 additions & 7 deletions src/map.rs
Expand Up @@ -323,10 +323,10 @@ impl Eq for Map<String, Value> {}
/// #
/// # let val = &Value::String("".to_owned());
/// # let _ =
/// match *val {
/// Value::String(ref s) => Some(s.as_str()),
/// Value::Array(ref arr) => arr[0].as_str(),
/// Value::Object(ref map) => map["type"].as_str(),
/// match val {
/// Value::String(s) => Some(s.as_str()),
/// Value::Array(arr) => arr[0].as_str(),
/// Value::Object(map) => map["type"].as_str(),
/// _ => None,
/// }
/// # ;
Expand Down Expand Up @@ -530,9 +530,9 @@ impl<'a> Entry<'a> {
/// assert_eq!(map.entry("serde").key(), &"serde");
/// ```
pub fn key(&self) -> &String {
match *self {
Entry::Vacant(ref e) => e.key(),
Entry::Occupied(ref e) => e.key(),
match self {
Entry::Vacant(e) => e.key(),
Entry::Occupied(e) => e.key(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/read.rs
Expand Up @@ -252,7 +252,7 @@ where
Some(ch) => {
#[cfg(feature = "raw_value")]
{
if let Some(ref mut buf) = self.raw_buffer {
if let Some(buf) = &mut self.raw_buffer {
buf.push(ch);
}
}
Expand All @@ -263,7 +263,7 @@ where
Some(Ok(ch)) => {
#[cfg(feature = "raw_value")]
{
if let Some(ref mut buf) = self.raw_buffer {
if let Some(buf) = &mut self.raw_buffer {
buf.push(ch);
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@ where
#[cfg(feature = "raw_value")]
fn discard(&mut self) {
if let Some(ch) = self.ch.take() {
if let Some(ref mut buf) = self.raw_buffer {
if let Some(buf) = &mut self.raw_buffer {
buf.push(ch);
}
}
Expand Down
24 changes: 9 additions & 15 deletions src/ser.rs
Expand Up @@ -533,11 +533,8 @@ where
where
T: ?Sized + Serialize,
{
match *self {
Compound::Map {
ref mut ser,
ref mut state,
} => {
match self {
Compound::Map { ser, state } => {
tri!(ser
.formatter
.begin_array_value(&mut ser.writer, *state == State::First)
Expand Down Expand Up @@ -671,11 +668,8 @@ where
where
T: ?Sized + Serialize,
{
match *self {
Compound::Map {
ref mut ser,
ref mut state,
} => {
match self {
Compound::Map { ser, state } => {
tri!(ser
.formatter
.begin_object_key(&mut ser.writer, *state == State::First)
Expand All @@ -702,8 +696,8 @@ where
where
T: ?Sized + Serialize,
{
match *self {
Compound::Map { ref mut ser, .. } => {
match self {
Compound::Map { ser, .. } => {
tri!(ser
.formatter
.begin_object_value(&mut ser.writer)
Expand Down Expand Up @@ -753,10 +747,10 @@ where
where
T: ?Sized + Serialize,
{
match *self {
match self {
Compound::Map { .. } => ser::SerializeMap::serialize_entry(self, key, value),
#[cfg(feature = "arbitrary_precision")]
Compound::Number { ref mut ser, .. } => {
Compound::Number { ser, .. } => {
if key == crate::number::TOKEN {
tri!(value.serialize(NumberStrEmitter(ser)));
Ok(())
Expand All @@ -765,7 +759,7 @@ where
}
}
#[cfg(feature = "raw_value")]
Compound::RawValue { ref mut ser, .. } => {
Compound::RawValue { ser, .. } => {
if key == crate::raw::TOKEN {
tri!(value.serialize(RawValueStrEmitter(ser)));
Ok(())
Expand Down
60 changes: 30 additions & 30 deletions src/value/de.rs
Expand Up @@ -648,8 +648,8 @@ macro_rules! deserialize_value_ref_number {
where
V: Visitor<'de>,
{
match *self {
Value::Number(ref n) => n.deserialize_any(visitor),
match self {
Value::Number(n) => n.deserialize_any(visitor),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand All @@ -659,8 +659,8 @@ macro_rules! deserialize_value_ref_number {
where
V: Visitor<'de>,
{
match *self {
Value::Number(ref n) => n.$method(visitor),
match self {
Value::Number(n) => n.$method(visitor),
_ => self.deserialize_any(visitor),
}
}
Expand Down Expand Up @@ -710,13 +710,13 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
match *self {
match self {
Value::Null => visitor.visit_unit(),
Value::Bool(v) => visitor.visit_bool(v),
Value::Number(ref n) => n.deserialize_any(visitor),
Value::String(ref v) => visitor.visit_borrowed_str(v),
Value::Array(ref v) => visit_array_ref(v, visitor),
Value::Object(ref v) => visit_object_ref(v, visitor),
Value::Bool(v) => visitor.visit_bool(*v),
Value::Number(n) => n.deserialize_any(visitor),
Value::String(v) => visitor.visit_borrowed_str(v),
Value::Array(v) => visit_array_ref(v, visitor),
Value::Object(v) => visit_object_ref(v, visitor),
}
}

Expand Down Expand Up @@ -755,8 +755,8 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
let (variant, value) = match *self {
Value::Object(ref value) => {
let (variant, value) = match self {
Value::Object(value) => {
let mut iter = value.into_iter();
let (variant, value) = match iter.next() {
Some(v) => v,
Expand All @@ -776,8 +776,8 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
}
(variant, Some(value))
}
Value::String(ref variant) => (variant, None),
ref other => {
Value::String(variant) => (variant, None),
other => {
return Err(serde::de::Error::invalid_type(
other.unexpected(),
&"string or map",
Expand Down Expand Up @@ -831,8 +831,8 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
match *self {
Value::String(ref v) => visitor.visit_borrowed_str(v),
match self {
Value::String(v) => visitor.visit_borrowed_str(v),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand All @@ -848,9 +848,9 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
match *self {
Value::String(ref v) => visitor.visit_borrowed_str(v),
Value::Array(ref v) => visit_array_ref(v, visitor),
match self {
Value::String(v) => visitor.visit_borrowed_str(v),
Value::Array(v) => visit_array_ref(v, visitor),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand Down Expand Up @@ -883,8 +883,8 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
match *self {
Value::Array(ref v) => visit_array_ref(v, visitor),
match self {
Value::Array(v) => visit_array_ref(v, visitor),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand Down Expand Up @@ -912,8 +912,8 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
match *self {
Value::Object(ref v) => visit_object_ref(v, visitor),
match self {
Value::Object(v) => visit_object_ref(v, visitor),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand All @@ -927,9 +927,9 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
match *self {
Value::Array(ref v) => visit_array_ref(v, visitor),
Value::Object(ref v) => visit_object_ref(v, visitor),
match self {
Value::Array(v) => visit_array_ref(v, visitor),
Value::Object(v) => visit_object_ref(v, visitor),
_ => Err(self.invalid_type(&visitor)),
}
}
Expand Down Expand Up @@ -1274,11 +1274,11 @@ impl Value {

#[cold]
fn unexpected(&self) -> Unexpected {
match *self {
match self {
Value::Null => Unexpected::Unit,
Value::Bool(b) => Unexpected::Bool(b),
Value::Number(ref n) => n.unexpected(),
Value::String(ref s) => Unexpected::Str(s),
Value::Bool(b) => Unexpected::Bool(*b),
Value::Number(n) => n.unexpected(),
Value::String(s) => Unexpected::Str(s),
Value::Array(_) => Unexpected::Seq,
Value::Object(_) => Unexpected::Map,
}
Expand Down
12 changes: 12 additions & 0 deletions src/value/from.rs
Expand Up @@ -268,3 +268,15 @@ impl From<()> for Value {
Value::Null
}
}

impl<T> From<Option<T>> for Value
where
T: Into<Value>,
{
fn from(opt: Option<T>) -> Self {
match opt {
None => Value::Null,
Some(value) => Into::into(value),
}
}
}

0 comments on commit 6d18459

Please sign in to comment.