Adopt inclusive range syntax

This commit is contained in:
David Tolnay 2020-01-22 14:06:03 -08:00
parent 17824dc1ea
commit 50faa3c000
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 35 additions and 35 deletions

View File

@ -284,7 +284,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
Err(err) => return err,
}
}
b'0'...b'9' => match self.parse_any_number(true) {
b'0'..=b'9' => match self.parse_any_number(true) {
Ok(n) => n.invalid_type(exp),
Err(err) => return err,
},
@ -320,7 +320,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
tri!(self.parse_integer(false)).visit(visitor)
}
b'0'...b'9' => tri!(self.parse_integer(true)).visit(visitor),
b'0'..=b'9' => tri!(self.parse_integer(true)).visit(visitor),
_ => Err(self.peek_invalid_type(&visitor)),
};
@ -337,15 +337,15 @@ impl<'de, R: Read<'de>> Deserializer<R> {
buf.push('0');
// There can be only one leading '0'.
match tri!(self.peek_or_null()) {
b'0'...b'9' => {
b'0'..=b'9' => {
Err(self.peek_error(ErrorCode::InvalidNumber))
}
_ => Ok(()),
}
}
c @ b'1'...b'9' => {
c @ b'1'..=b'9' => {
buf.push(c as char);
while let c @ b'0'...b'9' = tri!(self.peek_or_null()) {
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
buf.push(c as char);
}
@ -392,16 +392,16 @@ impl<'de, R: Read<'de>> Deserializer<R> {
b'0' => {
// There can be only one leading '0'.
match tri!(self.peek_or_null()) {
b'0'...b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
b'0'..=b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
_ => self.parse_number(positive, 0),
}
}
c @ b'1'...b'9' => {
c @ b'1'..=b'9' => {
let mut res = (c - b'0') as u64;
loop {
match tri!(self.peek_or_null()) {
c @ b'0'...b'9' => {
c @ b'0'..=b'9' => {
self.eat_char();
let digit = (c - b'0') as u64;
@ -436,7 +436,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
) -> Result<f64> {
loop {
match tri!(self.peek_or_null()) {
b'0'...b'9' => {
b'0'..=b'9' => {
self.eat_char();
// This could overflow... if your integer is gigabytes long.
// Ignore that possibility.
@ -485,7 +485,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
let mut at_least_one_digit = false;
while let c @ b'0'...b'9' = tri!(self.peek_or_null()) {
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
let digit = (c - b'0') as u64;
at_least_one_digit = true;
@ -493,7 +493,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
if overflow!(significand * 10 + digit, u64::max_value()) {
// The next multiply/add would overflow, so just ignore all
// further digits.
while let b'0'...b'9' = tri!(self.peek_or_null()) {
while let b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
}
break;
@ -545,13 +545,13 @@ impl<'de, R: Read<'de>> Deserializer<R> {
// Make sure a digit follows the exponent place.
let mut exp = match next {
c @ b'0'...b'9' => (c - b'0') as i32,
c @ b'0'..=b'9' => (c - b'0') as i32,
_ => {
return Err(self.error(ErrorCode::InvalidNumber));
}
};
while let c @ b'0'...b'9' = tri!(self.peek_or_null()) {
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
let digit = (c - b'0') as i32;
@ -586,7 +586,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
return Err(self.error(ErrorCode::NumberOutOfRange));
}
while let b'0'...b'9' = tri!(self.peek_or_null()) {
while let b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
}
Ok(if positive { 0.0 } else { -0.0 })
@ -605,7 +605,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
self.parse_any_number(false)
}
b'0'...b'9' => self.parse_any_number(true),
b'0'..=b'9' => self.parse_any_number(true),
_ => Err(self.peek_error(ErrorCode::InvalidNumber)),
};
@ -657,13 +657,13 @@ impl<'de, R: Read<'de>> Deserializer<R> {
b'0' => {
// There can be only one leading '0'.
match tri!(self.peek_or_null()) {
b'0'...b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
b'0'..=b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
_ => self.scan_number(buf),
}
}
b'1'...b'9' => loop {
b'1'..=b'9' => loop {
match tri!(self.peek_or_null()) {
c @ b'0'...b'9' => {
c @ b'0'..=b'9' => {
self.eat_char();
buf.push(c as char);
}
@ -691,7 +691,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
buf.push('.');
let mut at_least_one_digit = false;
while let c @ b'0'...b'9' = tri!(self.peek_or_null()) {
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
buf.push(c as char);
at_least_one_digit = true;
@ -728,13 +728,13 @@ impl<'de, R: Read<'de>> Deserializer<R> {
// Make sure a digit follows the exponent place.
match tri!(self.scan_or_eof(buf)) {
b'0'...b'9' => {}
b'0'..=b'9' => {}
_ => {
return Err(self.error(ErrorCode::InvalidNumber));
}
}
while let c @ b'0'...b'9' = tri!(self.peek_or_null()) {
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
buf.push(c as char);
}
@ -851,7 +851,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
tri!(self.ignore_integer());
None
}
b'0'...b'9' => {
b'0'..=b'9' => {
tri!(self.ignore_integer());
None
}
@ -937,12 +937,12 @@ impl<'de, R: Read<'de>> Deserializer<R> {
match tri!(self.next_char_or_null()) {
b'0' => {
// There can be only one leading '0'.
if let b'0'...b'9' = tri!(self.peek_or_null()) {
if let b'0'..=b'9' = tri!(self.peek_or_null()) {
return Err(self.peek_error(ErrorCode::InvalidNumber));
}
}
b'1'...b'9' => {
while let b'0'...b'9' = tri!(self.peek_or_null()) {
b'1'..=b'9' => {
while let b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
}
}
@ -962,7 +962,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
self.eat_char();
let mut at_least_one_digit = false;
while let b'0'...b'9' = tri!(self.peek_or_null()) {
while let b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
at_least_one_digit = true;
}
@ -987,13 +987,13 @@ impl<'de, R: Read<'de>> Deserializer<R> {
// Make sure a digit follows the exponent place.
match tri!(self.next_char_or_null()) {
b'0'...b'9' => {}
b'0'..=b'9' => {}
_ => {
return Err(self.error(ErrorCode::InvalidNumber));
}
}
while let b'0'...b'9' = tri!(self.peek_or_null()) {
while let b'0'..=b'9' = tri!(self.peek_or_null()) {
self.eat_char();
}
@ -1135,7 +1135,7 @@ impl<'de, 'a, R: Read<'de>> de::Deserializer<'de> for &'a mut Deserializer<R> {
self.eat_char();
tri!(self.parse_any_number(false)).visit(visitor)
}
b'0'...b'9' => tri!(self.parse_any_number(true)).visit(visitor),
b'0'..=b'9' => tri!(self.parse_any_number(true)).visit(visitor),
b'"' => {
self.eat_char();
self.scratch.clear();

View File

@ -292,7 +292,7 @@
//! [`serde-json-core`]: https://japaric.github.io/serde-json-core/serde_json_core/
#![doc(html_root_url = "https://docs.rs/serde_json/1.0.44")]
#![allow(bare_trait_objects, ellipsis_inclusive_range_patterns)]
#![allow(bare_trait_objects)]
#![deny(clippy::all, clippy::pedantic)]
// Ignored clippy lints
#![allow(

View File

@ -682,7 +682,7 @@ impl<'a> Read<'a> for StrRead<'a> {
// Lookup table of bytes that must be escaped. A value of true at index i means
// that byte i requires an escape sequence in the input.
static ESCAPE: [bool; 256] = {
const CT: bool = true; // control character \x00...\x1F
const CT: bool = true; // control character \x00..=\x1F
const QU: bool = true; // quote \x22
const BS: bool = true; // backslash \x5C
const __: bool = false; // allow unescaped
@ -739,13 +739,13 @@ fn parse_escape<'de, R: Read<'de>>(read: &mut R, scratch: &mut Vec<u8>) -> Resul
b't' => scratch.push(b'\t'),
b'u' => {
let c = match tri!(read.decode_hex_escape()) {
0xDC00...0xDFFF => {
0xDC00..=0xDFFF => {
return error(read, ErrorCode::LoneLeadingSurrogateInHexEscape);
}
// Non-BMP characters are encoded as a sequence of
// two hex escapes, representing UTF-16 surrogates.
n1 @ 0xD800...0xDBFF => {
n1 @ 0xD800..=0xDBFF => {
if tri!(next_or_eof(read)) != b'\\' {
return error(read, ErrorCode::UnexpectedEndOfHexEscape);
}
@ -796,13 +796,13 @@ fn ignore_escape<'de, R: ?Sized + Read<'de>>(read: &mut R) -> Result<()> {
b'"' | b'\\' | b'/' | b'b' | b'f' | b'n' | b'r' | b't' => {}
b'u' => {
let n = match tri!(read.decode_hex_escape()) {
0xDC00...0xDFFF => {
0xDC00..=0xDFFF => {
return error(read, ErrorCode::LoneLeadingSurrogateInHexEscape);
}
// Non-BMP characters are encoded as a sequence of
// two hex escapes, representing UTF-16 surrogates.
n1 @ 0xD800...0xDBFF => {
n1 @ 0xD800..=0xDBFF => {
if tri!(next_or_eof(read)) != b'\\' {
return error(read, ErrorCode::UnexpectedEndOfHexEscape);
}