From 7ad52cd2fa474ace4e7fe427133bc216528cfc83 Mon Sep 17 00:00:00 2001 From: jerrykingxyz Date: Mon, 14 Oct 2024 19:54:18 +0800 Subject: [PATCH 1/2] chore: upgrade rust to 1.81.0 nightly --- .github/workflows/ci.yml | 2 +- crates/rspack_core/src/diagnostics.rs | 1 + crates/rspack_core/src/options/filename.rs | 7 ++--- crates/rspack_regex/src/algo.rs | 35 +++++++++++----------- crates/rspack_util/src/infallible.rs | 6 ++-- rust-toolchain.toml | 2 +- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a0896d8234..c95b17da266 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -267,7 +267,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --workspace --all-targets -- -D warnings + args: --workspace --all-targets --tests -- -D warnings - name: Run rustfmt uses: actions-rs/cargo@v1 diff --git a/crates/rspack_core/src/diagnostics.rs b/crates/rspack_core/src/diagnostics.rs index 7e6ad787d78..b4588ec6c61 100644 --- a/crates/rspack_core/src/diagnostics.rs +++ b/crates/rspack_core/src/diagnostics.rs @@ -78,6 +78,7 @@ impl miette::Diagnostic for ModuleBuildError { } /// Represent any errors or warnings during module parse +/// /// This does NOT aligned with webpack as webpack does not have parse warning. /// However, rspack may create warning during parsing stage, taking CSS as an example. #[derive(Debug, Error)] diff --git a/crates/rspack_core/src/options/filename.rs b/crates/rspack_core/src/options/filename.rs index 3435d43f66f..002ffb3c6d8 100644 --- a/crates/rspack_core/src/options/filename.rs +++ b/crates/rspack_core/src/options/filename.rs @@ -127,10 +127,9 @@ impl LocalFilenameFn for NoFilenameFn { impl From for Filename { fn from(value: FilenameTemplate) -> Self { - Self(match value.0 { - FilenameKind::Template(template) => FilenameKind::Template(template), - FilenameKind::Fn(no_fn) => match no_fn.0 {}, - }) + let FilenameKind::Template(template) = value.0; + + Self(FilenameKind::Template(template)) } } diff --git a/crates/rspack_regex/src/algo.rs b/crates/rspack_regex/src/algo.rs index f3fc9c1f25c..62107985119 100644 --- a/crates/rspack_regex/src/algo.rs +++ b/crates/rspack_regex/src/algo.rs @@ -112,24 +112,6 @@ impl Algo { } } -#[cfg(test)] -impl Algo { - fn end_with_pats(&self) -> std::collections::HashSet<&str> { - match self { - Algo::EndWith { pats } => pats.iter().map(|s| s.as_str()).collect(), - Algo::Regress(_) => panic!("expect EndWith"), - } - } - - fn is_end_with(&self) -> bool { - matches!(self, Self::EndWith { .. }) - } - - fn is_regress(&self) -> bool { - matches!(self, Self::Regress(..)) - } -} - fn is_ends_with_regex(hir: &Hir) -> bool { if let HirKind::Concat(list) = hir.kind() { list[0].kind() != &HirKind::Look(Look::Start) @@ -143,6 +125,23 @@ fn is_ends_with_regex(hir: &Hir) -> bool { mod test_algo { use super::*; + impl Algo { + fn end_with_pats(&self) -> std::collections::HashSet<&str> { + match self { + Algo::EndWith { pats } => pats.iter().map(|s| s.as_str()).collect(), + Algo::Regress(_) => panic!("expect EndWith"), + } + } + + fn is_end_with(&self) -> bool { + matches!(self, Self::EndWith { .. }) + } + + fn is_regress(&self) -> bool { + matches!(self, Self::Regress(..)) + } + } + #[test] fn should_use_end_with_algo_with_i_flag() { assert!(Algo::new("\\.js$", "").unwrap().is_end_with()); diff --git a/crates/rspack_util/src/infallible.rs b/crates/rspack_util/src/infallible.rs index 4589fe7896f..3224b1f0b8d 100644 --- a/crates/rspack_util/src/infallible.rs +++ b/crates/rspack_util/src/infallible.rs @@ -8,9 +8,7 @@ pub trait ResultInfallibleExt { impl ResultInfallibleExt for Result { type Ok = T; fn always_ok(self) -> T { - match self { - Ok(ok) => ok, - Err(infallible) => match infallible {}, - } + let Ok(ok) = self; + ok } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a9f7244565d..0ce1d9a0180 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,4 +2,4 @@ profile = "default" # Use nightly for better access to the latest Rust features. # This date is aligned to stable release dates. -channel = "nightly-2024-06-07" # v1.80.0 +channel = "nightly-2024-09-05" # v1.81.0 From cb6b72d8a85166f3b5a32bd2a05472c1c304f2be Mon Sep 17 00:00:00 2001 From: jerrykingxyz Date: Tue, 15 Oct 2024 15:28:43 +0800 Subject: [PATCH 2/2] fix: update asset size to usize --- crates/rspack_binding_values/src/stats.rs | 6 +++--- crates/rspack_core/src/stats/struct.rs | 6 +++--- crates/rspack_core/src/stats/utils.rs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/rspack_binding_values/src/stats.rs b/crates/rspack_binding_values/src/stats.rs index 51bd6dec6a8..3a21766a6c5 100644 --- a/crates/rspack_binding_values/src/stats.rs +++ b/crates/rspack_binding_values/src/stats.rs @@ -991,7 +991,7 @@ impl From for JsStatsChunkGroupAsset { fn from(stats: rspack_core::StatsChunkGroupAsset) -> Self { Self { name: stats.name, - size: stats.size, + size: stats.size as f64, } } } @@ -1024,11 +1024,11 @@ impl From for JsStatsChunkGroup { name: stats.name, chunks: stats.chunks, assets: stats.assets.into_iter().map(Into::into).collect(), - assets_size: stats.assets_size, + assets_size: stats.assets_size as f64, auxiliary_assets: stats .auxiliary_assets .map(|assets| assets.into_iter().map(Into::into).collect()), - auxiliary_assets_size: stats.auxiliary_assets_size, + auxiliary_assets_size: stats.auxiliary_assets_size.map(|inner| inner as f64), children: stats.children.map(|i| i.into()), child_assets: stats.child_assets.map(|i| i.into()), is_over_size_limit: stats.is_over_size_limit, diff --git a/crates/rspack_core/src/stats/struct.rs b/crates/rspack_core/src/stats/struct.rs index 17ec9b53558..12621d72f21 100644 --- a/crates/rspack_core/src/stats/struct.rs +++ b/crates/rspack_core/src/stats/struct.rs @@ -220,7 +220,7 @@ pub struct StatsChunk<'a> { #[derive(Debug)] pub struct StatsChunkGroupAsset { pub name: String, - pub size: f64, + pub size: usize, } #[derive(Debug)] @@ -228,9 +228,9 @@ pub struct StatsChunkGroup { pub name: String, pub chunks: Vec, pub assets: Vec, - pub assets_size: f64, + pub assets_size: usize, pub auxiliary_assets: Option>, - pub auxiliary_assets_size: Option, + pub auxiliary_assets_size: Option, pub children: Option, pub is_over_size_limit: Option, pub child_assets: Option, diff --git a/crates/rspack_core/src/stats/utils.rs b/crates/rspack_core/src/stats/utils.rs index 5df661cd218..34c862654c6 100644 --- a/crates/rspack_core/src/stats/utils.rs +++ b/crates/rspack_core/src/stats/utils.rs @@ -11,12 +11,12 @@ use crate::{ ChunkGroupByUkey, ChunkGroupOrderKey, ChunkGroupUkey, Compilation, CompilerOptions, ModuleGraph, }; -pub fn get_asset_size(file: &str, compilation: &Compilation) -> f64 { +pub fn get_asset_size(file: &str, compilation: &Compilation) -> usize { compilation .assets() .get(file) - .and_then(|asset| asset.get_source().map(|s| s.size() as f64)) - .unwrap_or(-1f64) + .and_then(|asset| asset.get_source().map(|s| s.size())) + .unwrap_or(0) } pub fn sort_modules(modules: &mut [StatsModule]) {