diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8bb8db2d..b4ef5cfc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,8 +80,8 @@ jobs: set -euo pipefail # Install the appropriate version of Rust. - rustup toolchain install 1.65.0 # [ref:rust_1.65.0] - rustup default 1.65.0 # [ref:rust_1.65.0] + rustup toolchain install 1.72.0 # [ref:rust_1.72.0] + rustup default 1.72.0 # [ref:rust_1.72.0] # Add the targets. rustup target add x86_64-pc-windows-msvc @@ -120,8 +120,8 @@ jobs: set -euo pipefail # Install the appropriate version of Rust. - rustup toolchain install 1.65.0 # [ref:rust_1.65.0] - rustup default 1.65.0 # [ref:rust_1.65.0] + rustup toolchain install 1.72.0 # [ref:rust_1.72.0] + rustup default 1.72.0 # [ref:rust_1.72.0] # Add the targets. rustup target add x86_64-apple-darwin @@ -193,8 +193,8 @@ jobs: set -euo pipefail # Install the appropriate version of Rust. - rustup toolchain install 1.65.0 # [ref:rust_1.65.0] - rustup default 1.65.0 # [ref:rust_1.65.0] + rustup toolchain install 1.72.0 # [ref:rust_1.72.0] + rustup default 1.72.0 # [ref:rust_1.72.0] # Fetch the program version. VERSION="$(cargo pkgid | cut -d# -f2 | cut -d: -f2)" diff --git a/Cargo.lock b/Cargo.lock index 195af9ea..845e1de9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,20 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - [[package]] name = "ansi_term" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ "winapi", ] @@ -26,26 +17,41 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "clap" -version = "2.33.3" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", - "bitflags", + "bitflags 1.3.2", "strsim", "term_size", "textwrap 0.11.0", @@ -55,24 +61,62 @@ dependencies = [ [[package]] name = "colored" -version = "1.9.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +checksum = "5a5f741c91823341bebf717d4c71bda820630ce065443b58bd1b7451af008355" dependencies = [ - "atty", + "is-terminal", "lazy_static", "winapi", ] +[[package]] +name = "errno" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi 0.3.2", + "rustix", + "windows-sys", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -81,15 +125,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.93" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] -name = "memchr" -version = "2.4.1" +name = "linux-raw-sys" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "pad" @@ -101,22 +145,18 @@ dependencies = [ ] [[package]] -name = "regex" -version = "1.5.4" +name = "rustix" +version = "0.38.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", ] -[[package]] -name = "regex-syntax" -version = "0.6.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" - [[package]] name = "smawk" version = "0.3.1" @@ -173,24 +213,21 @@ dependencies = [ [[package]] name = "unicode-linebreak" -version = "0.1.2" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a52dcaab0c48d931f7cc8ef826fa51690a08e1ea55117ef26f89864f532383f" -dependencies = [ - "regex", -] +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "vec_map" @@ -219,3 +256,69 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/benchmarks/rust/src/main.rs b/benchmarks/rust/src/main.rs index 43496d30..37d5a42d 100644 --- a/benchmarks/rust/src/main.rs +++ b/benchmarks/rust/src/main.rs @@ -76,7 +76,7 @@ fn benchmark(message: &T, iterations: usize) -> io let mut buffer = Vec::::new(); buffer.reserve(message_size); - println!("Message size: {}", message_size); + println!("Message size: {message_size}"); let serialization_instant = Instant::now(); @@ -87,7 +87,7 @@ fn benchmark(message: &T, iterations: usize) -> io let serialization_duration = serialization_instant.elapsed(); println!("Wrote {} bytes.", buffer.len()); - println!("Serialization duration: {:?}", serialization_duration); + println!("Serialization duration: {serialization_duration:?}"); println!( "Serialization rate: {} bytes/second", (buffer.len() as f64) / serialization_duration.as_secs_f64() @@ -102,7 +102,7 @@ fn benchmark(message: &T, iterations: usize) -> io let deserialization_duration = deserialization_instant.elapsed(); - println!("Deserialization duration: {:?}", deserialization_duration); + println!("Deserialization duration: {deserialization_duration:?}"); println!( "Deserialization rate: {} bytes/second", (buffer.len() as f64) / deserialization_duration.as_secs_f64() diff --git a/integration_tests/rust/src/assertions.rs b/integration_tests/rust/src/assertions.rs index fae854ea..1b06c287 100644 --- a/integration_tests/rust/src/assertions.rs +++ b/integration_tests/rust/src/assertions.rs @@ -18,14 +18,14 @@ pub fn assert_match( actual: &T, expected: &U, ) -> io::Result<()> { - println!("Message to be serialized: {:?}", actual); + println!("Message to be serialized: {actual:?}"); let size = actual.size(); - println!("Expected size of the serialized value: {:?}", size); + println!("Expected size of the serialized value: {size:?}"); let mut buffer = Vec::::new(); actual.serialize(&mut buffer)?; - println!("Bytes from serialization: {:?}", buffer); + println!("Bytes from serialization: {buffer:?}"); println!("Size of the serialized value: {:?}", buffer.len()); if buffer.len() != size { return Err(Error::new(ErrorKind::Other, "Mismatch!")); @@ -39,9 +39,9 @@ pub fn assert_match( file.write_all(&buffer).unwrap(); let replica = U::deserialize(buffer.as_slice())?; - println!("Message deserialized from those bytes: {:?}", replica); + println!("Message deserialized from those bytes: {replica:?}"); - if format!("{:?}", replica) != format!("{:?}", expected) { + if format!("{replica:?}") != format!("{expected:?}") { return Err(Error::new(ErrorKind::Other, "Mismatch!")); } diff --git a/integration_tests/rust/src/types.rs b/integration_tests/rust/src/types.rs index 0f65d2ae..63151cda 100644 --- a/integration_tests/rust/src/types.rs +++ b/integration_tests/rust/src/types.rs @@ -5,6 +5,7 @@ clippy::let_unit_value, clippy::match_same_arms, clippy::match_single_binding, + clippy::misnamed_getters, clippy::module_inception, clippy::module_name_repetitions, clippy::needless_borrow, diff --git a/src/count.rs b/src/count.rs index 9ee9fc85..ac4b8648 100644 --- a/src/count.rs +++ b/src/count.rs @@ -2,9 +2,9 @@ // multiplicity (pluralizing if necessary). For example, `count(3, "cow")` becomes "3 cows". pub fn count(n: usize, noun: &str) -> String { if n == 1 { - format!("{} {}", n, noun) + format!("{n} {noun}") } else { - format!("{} {}s", n, noun) + format!("{n} {noun}s") } } diff --git a/src/format.rs b/src/format.rs index 59980438..fd6e5d7a 100644 --- a/src/format.rs +++ b/src/format.rs @@ -14,7 +14,7 @@ impl CodeStr for str { if SHOULD_COLORIZE.should_colorize() { self.magenta() } else { - ColoredString::from(&format!("`{}`", self) as &Self) + ColoredString::from(&format!("`{self}`") as &Self) } } } diff --git a/src/generate_rust.rs b/src/generate_rust.rs index 21683fd9..c8935d19 100644 --- a/src/generate_rust.rs +++ b/src/generate_rust.rs @@ -86,7 +86,7 @@ pub fn generate( writeln!( &mut buffer, "\ -// This file was automatically generated by Typical {}. +// This file was automatically generated by Typical {typical_version}. // Visit https://github.com/stepchowfun/typical for more information. use std::{{ @@ -326,7 +326,6 @@ fn finish(reader: &mut T) -> io::Result<()> {{ reader.consume(buffer_size); }} }}", - typical_version, ) .unwrap(); @@ -827,7 +826,7 @@ fn write_schema( writeln!(buffer, "_ => {{")?; write_indentation(buffer, indentation + 5)?; write_supers(buffer, indentation)?; - writeln!(buffer, "skip(&mut sub_reader, payload_size as usize)?;")?; + writeln!(buffer, "skip(&mut sub_reader, payload_size)?;")?; write_indentation(buffer, indentation + 4)?; writeln!(buffer, "}}")?; write_indentation(buffer, indentation + 3)?; @@ -1306,7 +1305,7 @@ fn write_schema( writeln!(buffer, "_ => {{")?; write_indentation(buffer, indentation + 5)?; write_supers(buffer, indentation)?; - writeln!(buffer, "skip(&mut sub_reader, payload_size as usize)?;")?; + writeln!(buffer, "skip(&mut sub_reader, payload_size)?;")?; write_indentation(buffer, indentation + 4)?; writeln!(buffer, "}}")?; write_indentation(buffer, indentation + 3)?; @@ -1694,7 +1693,7 @@ fn write_identifier( write!(buffer, "r#")?; } - write!(buffer, "{}", converted_identifier)?; + write!(buffer, "{converted_identifier}")?; Ok(()) } @@ -1702,7 +1701,7 @@ fn write_identifier( // Write the given level of indentation. fn write_indentation(buffer: &mut T, indentation: usize) -> Result<(), fmt::Error> { for _ in 0..indentation { - write!(buffer, "{}", INDENTATION)?; + write!(buffer, "{INDENTATION}")?; } Ok(()) @@ -1951,7 +1950,7 @@ fn write_serialization_invocation( write_indentation(buffer, indentation)?; writeln!(buffer, "{{")?; write_indentation(buffer, indentation + 1)?; - writeln!(buffer, "let varint = payload.len() as u64 as u64;")?; + writeln!(buffer, "let varint = payload.len() as u64;")?; write_u64_serialization_invocation(buffer, indentation + 1, supers, is_field)?; write_indentation(buffer, indentation)?; writeln!(buffer, "}}") diff --git a/src/generate_typescript.rs b/src/generate_typescript.rs index a058ca8e..0a869c5d 100644 --- a/src/generate_typescript.rs +++ b/src/generate_typescript.rs @@ -150,7 +150,7 @@ pub fn generate( writeln!( &mut buffer, "\ -// This file was automatically generated by Typical {}. +// This file was automatically generated by Typical {typical_version}. // Visit https://github.com/stepchowfun/typical for more information. /* eslint-disable */ @@ -433,7 +433,6 @@ const missingFieldsErrorMessage = 'Struct missing one or more required field(s). const dataView64 = new DataView(new ArrayBuffer(8)); const textEncoder = new TextEncoder(); const textDecoder = new TextDecoder();", - typical_version, ) .unwrap(); @@ -1683,7 +1682,7 @@ fn write_identifier( write!(buffer, "_")?; } - write!(buffer, "{}", converted_identifier)?; + write!(buffer, "{converted_identifier}")?; Ok(()) } @@ -1691,7 +1690,7 @@ fn write_identifier( // Write the given level of indentation. fn write_indentation(buffer: &mut T, indentation: usize) -> Result<(), fmt::Error> { for _ in 0..indentation { - write!(buffer, "{}", INDENTATION)?; + write!(buffer, "{INDENTATION}")?; } Ok(()) diff --git a/src/main.rs b/src/main.rs index d16e0806..78bcb16f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -396,7 +396,7 @@ fn entry() -> Result<(), Error> { fn main() { // Jump to the entrypoint and report any resulting errors. if let Err(e) = entry() { - eprintln!("{}", e); + eprintln!("{e}"); exit(1); } } diff --git a/src/parser.rs b/src/parser.rs index 9ba8a083..f46c30b9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -61,14 +61,14 @@ fn unexpected_token( if tokens.is_empty() { throw::( - &format!("Expected {}, but the file is empty.", expectation), + &format!("Expected {expectation}, but the file is empty."), Some(source_path), Some(&listing(source_contents, source_range)), None, ) } else if position == tokens.len() { throw::( - &format!("Expected {} at the end of the file.", expectation), + &format!("Expected {expectation} at the end of the file."), Some(source_path), Some(&listing(source_contents, source_range)), None, diff --git a/src/schema.rs b/src/schema.rs index a001cc8b..a23bcdb1 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -124,11 +124,11 @@ pub fn relativize_namespace(namespace1: &Namespace, namespace2: &Namespace) -> ( fn write_comment(indentation: &str, paragraphs: &[String], f: &mut W) -> fmt::Result { for (i, paragraph) in paragraphs.iter().enumerate() { if i != 0 { - writeln!(f, "{}#", indentation)?; + writeln!(f, "{indentation}#")?; } for line in textwrap::fill(paragraph, MAX_COLUMNS - indentation.len() - 2).lines() { - writeln!(f, "{}# {}", indentation, line)?; + writeln!(f, "{indentation}# {line}")?; } } @@ -211,10 +211,10 @@ impl Declaration { } if !self.deleted.is_empty() { - write!(f, " {}", DELETED_KEYWORD)?; + write!(f, " {DELETED_KEYWORD}")?; for deleted_index in &self.deleted { - write!(f, " {}", deleted_index)?; + write!(f, " {deleted_index}")?; } writeln!(f)?; @@ -227,8 +227,8 @@ impl Declaration { impl DeclarationVariant { fn write(&self, f: &mut W) -> fmt::Result { match self { - Self::Struct => write!(f, "{}", STRUCT_KEYWORD), - Self::Choice => write!(f, "{}", CHOICE_KEYWORD), + Self::Struct => write!(f, "{STRUCT_KEYWORD}"), + Self::Choice => write!(f, "{CHOICE_KEYWORD}"), } } } @@ -239,10 +239,10 @@ impl Field { match self.rule { Rule::Asymmetric => { - write!(f, " {} ", ASYMMETRIC_KEYWORD)?; + write!(f, " {ASYMMETRIC_KEYWORD} ")?; } Rule::Optional => { - write!(f, " {} ", OPTIONAL_KEYWORD)?; + write!(f, " {OPTIONAL_KEYWORD} ")?; } Rule::Required => { write!(f, " ")?; @@ -271,13 +271,13 @@ impl TypeVariant { fn write(&self, f: &mut W) -> fmt::Result { match self { Self::Array(inner_type) => { - write!(f, "[{}]", inner_type)?; + write!(f, "[{inner_type}]")?; } Self::Bool => { - write!(f, "{}", BOOL_KEYWORD)?; + write!(f, "{BOOL_KEYWORD}")?; } Self::Bytes => { - write!(f, "{}", BYTES_KEYWORD)?; + write!(f, "{BYTES_KEYWORD}")?; } Self::Custom(import, name) => { if let Some(import) = import { @@ -287,19 +287,19 @@ impl TypeVariant { } } Self::F64 => { - write!(f, "{}", F64_KEYWORD)?; + write!(f, "{F64_KEYWORD}")?; } Self::S64 => { - write!(f, "{}", S64_KEYWORD)?; + write!(f, "{S64_KEYWORD}")?; } Self::String => { - write!(f, "{}", STRING_KEYWORD)?; + write!(f, "{STRING_KEYWORD}")?; } Self::U64 => { - write!(f, "{}", U64_KEYWORD)?; + write!(f, "{U64_KEYWORD}")?; } Self::Unit => { - write!(f, "{}", UNIT_KEYWORD)?; + write!(f, "{UNIT_KEYWORD}")?; } } Ok(()) diff --git a/src/schema_loader.rs b/src/schema_loader.rs index a8b2eb65..8152f49d 100644 --- a/src/schema_loader.rs +++ b/src/schema_loader.rs @@ -49,9 +49,7 @@ pub fn load_schemas( let mut errors = vec![]; // The base directory for the schema's dependencies is the directory containing the schema. - let base_path = if let Some(base_path) = schema_path.parent() { - base_path - } else { + let Some(base_path) = schema_path.parent() else { errors.push(throw::( &format!( "{} is not a file.", diff --git a/src/token.rs b/src/token.rs index cfd1fefd..0cc8cb74 100644 --- a/src/token.rs +++ b/src/token.rs @@ -69,11 +69,11 @@ impl Display for Token { impl Display for Variant { fn fmt(&self, f: &mut Formatter) -> Result { match self { - Self::As => write!(f, "{}", AS_KEYWORD), - Self::Asymmetric => write!(f, "{}", ASYMMETRIC_KEYWORD), - Self::Bool => write!(f, "{}", BOOL_KEYWORD), - Self::Bytes => write!(f, "{}", BYTES_KEYWORD), - Self::Choice => write!(f, "{}", CHOICE_KEYWORD), + Self::As => write!(f, "{AS_KEYWORD}"), + Self::Asymmetric => write!(f, "{ASYMMETRIC_KEYWORD}"), + Self::Bool => write!(f, "{BOOL_KEYWORD}"), + Self::Bytes => write!(f, "{BYTES_KEYWORD}"), + Self::Choice => write!(f, "{CHOICE_KEYWORD}"), Self::Colon => write!(f, ":"), Self::Comment(paragraphs) => { for (i, paragraph) in paragraphs.iter().enumerate() { @@ -81,29 +81,29 @@ impl Display for Variant { writeln!(f, "#")?; } - writeln!(f, "# {}", paragraph)?; + writeln!(f, "# {paragraph}")?; } Ok(()) } - Self::Deleted => write!(f, "{}", DELETED_KEYWORD), + Self::Deleted => write!(f, "{DELETED_KEYWORD}"), Self::Dot => write!(f, "."), Self::Equals => write!(f, "="), - Self::F64 => write!(f, "{}", F64_KEYWORD), + Self::F64 => write!(f, "{F64_KEYWORD}"), Self::Identifier(name) => write!(f, "{}", name.original()), - Self::Import => write!(f, "{}", IMPORT_KEYWORD), - Self::Integer(integer) => write!(f, "{}", integer), + Self::Import => write!(f, "{IMPORT_KEYWORD}"), + Self::Integer(integer) => write!(f, "{integer}"), Self::LeftCurly => write!(f, "{{"), Self::LeftSquare => write!(f, "["), - Self::Optional => write!(f, "{}", OPTIONAL_KEYWORD), + Self::Optional => write!(f, "{OPTIONAL_KEYWORD}"), Self::Path(path) => write!(f, "'{}'", path.display()), Self::RightCurly => write!(f, "}}"), Self::RightSquare => write!(f, "]"), - Self::S64 => write!(f, "{}", S64_KEYWORD), - Self::String => write!(f, "{}", STRING_KEYWORD), - Self::Struct => write!(f, "{}", STRUCT_KEYWORD), - Self::U64 => write!(f, "{}", U64_KEYWORD), - Self::Unit => write!(f, "{}", UNIT_KEYWORD), + Self::S64 => write!(f, "{S64_KEYWORD}"), + Self::String => write!(f, "{STRING_KEYWORD}"), + Self::Struct => write!(f, "{STRUCT_KEYWORD}"), + Self::U64 => write!(f, "{U64_KEYWORD}"), + Self::Unit => write!(f, "{UNIT_KEYWORD}"), } } } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index c6504d6c..d02ca213 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -217,7 +217,7 @@ pub fn tokenize(schema_path: &Path, schema_contents: &str) -> Result, let mut end = schema_contents.len(); while let Some((j, d)) = iter.peek() { - if ('0'..='9').contains(d) { + if d.is_ascii_digit() { iter.next(); } else { end = *j; @@ -664,7 +664,7 @@ mod tests { assert_same!( tokenize( Path::new("foo.t"), - &format!("{}{}", RAW_IDENTIFIER_SIGIL, STRUCT_KEYWORD), + &format!("{RAW_IDENTIFIER_SIGIL}{STRUCT_KEYWORD}"), ) .unwrap(), vec![Token { diff --git a/toast.yml b/toast.yml index 74552f7d..55c6cb88 100644 --- a/toast.yml +++ b/toast.yml @@ -17,11 +17,11 @@ command_prefix: | cargo-offline () { cargo --frozen --offline "$@"; } # Use this wrapper for formatting code or checking that code is formatted. We use a nightly Rust - # version for the `trailing_comma` formatting option [tag:rust_fmt_nightly_2022-11-03]. The + # version for the `trailing_comma` formatting option [tag:rust_fmt_nightly_2023-08-24]. The # nightly version was chosen as the latest available release with all components present # according to this page: # https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu.html - cargo-fmt () { cargo +nightly-2022-11-03 --frozen --offline fmt --all -- "$@"; } + cargo-fmt () { cargo +nightly-2023-08-24 --frozen --offline fmt --all -- "$@"; } tasks: install_packages: description: Install system packages. @@ -66,18 +66,18 @@ tasks: - install_packages - create_user command: | - # Install stable Rust [tag:rust_1.65.0]. + # Install stable Rust [tag:rust_1.72.0]. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ -y \ - --default-toolchain 1.65.0 \ + --default-toolchain 1.72.0 \ --profile minimal \ --component clippy # Add Rust tools to `$PATH`. . "$HOME/.cargo/env" - # Install nightly Rust [ref:rust_fmt_nightly_2022-11-03]. - rustup toolchain install nightly-2022-11-03 --profile minimal --component rustfmt + # Install nightly Rust [ref:rust_fmt_nightly_2023-08-24]. + rustup toolchain install nightly-2023-08-24 --profile minimal --component rustfmt install_tools: description: Install the tools needed to build and validate the program.