From b37dda8854d63b9a9869624cfb6db31d504a04ff Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Tue, 25 Oct 2022 05:44:17 -1000 Subject: [PATCH] build: move to the Rust 2021 edition (#2085) * build: move to the Rust 2021 edition Since the MSRV of `naga` [is currently 1.56][msrv], I don't think there's a strong reason to stay with the 2018 edition, and there _are_ a [few good reasons][edition-guide] to move to the 2021 edition. I did this migration mostly automatically, per [official Rust guidelines]: ```sh $ cargo fix --edition --all-targets $ sed -i Cargo.toml 's/2018/2021' $ cargo fix --edition-idioms --allow-dirty # doesn't change anything ``` The only manual edit needed to stymie a new warning introduced was the removal of the `TryFrom` import in several modules, since it's now in the 2021 prelude. [msrv]: https://github.com/gfx-rs/naga/blob/a7193d652e49180661a6ca047889e0685667acdb/.github/workflows/pipeline.yml#L14 [edition-guide]: https://doc.rust-lang.org/edition-guide/rust-2021/index.html [official Rust guidelines]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html#edition-migration * refactor(wgsl-in): use `pat` instead of `pat_param` again How we were using `pat` in the Rust 2018 edition is actually the use case that Rust 2021's `pat` fragment specifier is intended to satisfy. So, let's just use that! --- Cargo.toml | 2 +- cli/Cargo.toml | 2 +- src/arena.rs | 2 -- src/front/wgsl/number.rs | 17 +++++++---------- src/proc/mod.rs | 1 - 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c951456a3b..80a4915b53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "naga" version = "0.10.0" authors = ["Naga Developers"] -edition = "2018" +edition = "2021" description = "Shader translation infrastructure" homepage = "https://github.com/gfx-rs/naga" repository = "https://github.com/gfx-rs/naga" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 02e563772f..6cc017e35b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -2,7 +2,7 @@ name = "naga-cli" version = "0.10.0" authors = ["Naga Developers"] -edition = "2018" +edition = "2021" description = "Shader translation command line tool" homepage = "https://github.com/gfx-rs/naga" repository = "https://github.com/gfx-rs/naga" diff --git a/src/arena.rs b/src/arena.rs index d21a786cb5..5d5cf37935 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -96,8 +96,6 @@ impl Handle { /// Convert a `usize` index into a `Handle`. fn from_usize(index: usize) -> Self { - use std::convert::TryFrom; - let handle_index = u32::try_from(index + 1) .ok() .and_then(Index::new) diff --git a/src/front/wgsl/number.rs b/src/front/wgsl/number.rs index d7e8801b09..fafe1d2270 100644 --- a/src/front/wgsl/number.rs +++ b/src/front/wgsl/number.rs @@ -24,12 +24,9 @@ impl Number { /// lossy, return an error. fn abstract_to_concrete(self) -> Result { match self { - Number::AbstractInt(num) => { - use std::convert::TryFrom; - i32::try_from(num) - .map(Number::I32) - .map_err(|_| NumberError::NotRepresentable) - } + Number::AbstractInt(num) => i32::try_from(num) + .map(Number::I32) + .map_err(|_| NumberError::NotRepresentable), Number::AbstractFloat(num) => { let num = num as f32; if num.is_finite() { @@ -94,9 +91,9 @@ fn parse(input: &str) -> (Result, &str) { /// returns `true` and consumes `X` bytes from the given byte buffer /// if the given `X` nr of patterns are found at the start of the buffer macro_rules! consume { - ($bytes:ident, $($($pattern:pat)|*),*) => { + ($bytes:ident, $($pattern:pat),*) => { match $bytes { - &[$($($pattern)|*),*, ref rest @ ..] => { $bytes = rest; true }, + &[$($pattern),*, ref rest @ ..] => { $bytes = rest; true }, _ => false, } }; @@ -106,9 +103,9 @@ fn parse(input: &str) -> (Result, &str) { /// if one of the given patterns are found at the start of the buffer /// returning the corresponding expr for the matched pattern macro_rules! consume_map { - ($bytes:ident, [$($($pattern:pat)|* => $to:expr),*]) => { + ($bytes:ident, [$($pattern:pat_param => $to:expr),*]) => { match $bytes { - $( &[$($pattern)|*, ref rest @ ..] => { $bytes = rest; Some($to) }, )* + $( &[$pattern, ref rest @ ..] => { $bytes = rest; Some($to) }, )* _ => None, } }; diff --git a/src/proc/mod.rs b/src/proc/mod.rs index 0b9f406af4..a5731de896 100644 --- a/src/proc/mod.rs +++ b/src/proc/mod.rs @@ -389,7 +389,6 @@ impl crate::Constant { /// `OpArrayType` referring to an inappropriate `OpConstant`). So we return /// `Option` and let the caller sort things out. pub(crate) fn to_array_length(&self) -> Option { - use std::convert::TryInto; match self.inner { crate::ConstantInner::Scalar { value, width: _ } => match value { crate::ScalarValue::Uint(value) => value.try_into().ok(),