Skip to content

Conversation

@stormslowly
Copy link
Contributor

Why

Change DerefOption to default to Some(T) when T implements the Default trait.

Currently, Artifacts implements Default and is initialized by calling Default::default(). If Artifacts is changed to DerefOption, the existing behavior changes subtly: all fields are initialized to None instead of using Artifacts::default().

This difference in default initialization is easy to miss and can lead to subtle bugs. Defaulting DerefOption to Some(T::default()) when T: Default preserves the original behavior and makes the change safer and more intuitive.

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 10, 2025 06:42
@netlify
Copy link

netlify bot commented Dec 10, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit f279601
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6939165b4deb49000818225b
😎 Deploy Preview https://deploy-preview-12406--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: refactor labels Dec 10, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the DerefOption<T> type to default to Some(T::default()) instead of None when T implements the Default trait. This change makes it safer to wrap types in DerefOption without changing their default initialization behavior, which helps prevent subtle bugs. The PR also removes an unnecessary T: Debug constraint from the DerefMut implementation.

Key changes:

  • Implements a custom Default trait for DerefOption<T> that creates Some(T::default()) when T: Default
  • Removes the derived Default implementation that would have created None
  • Removes unnecessary T: Debug bound from DerefMut implementation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +16
impl<T> Default for DerefOption<T>
where
T: Default,
{
fn default() -> Self {
Self(Some(T::default()))
}
}
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Default implementation that returns Some(T::default()) should have test coverage to ensure it behaves as expected. Consider adding a test module similar to other utility files in this directory (e.g., fs_trim.rs, incremental_info.rs). Example test:

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn test_default_creates_some() {
    #[derive(Default, Debug, PartialEq)]
    struct TestStruct {
      value: i32,
    }

    let deref_option: DerefOption<TestStruct> = Default::default();
    assert_eq!(*deref_option, TestStruct::default());
  }
}

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +12
impl<T> Default for DerefOption<T>
where
T: Default,
{
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding documentation to clarify the behavior of the Default implementation. For example:

/// Creates a `DerefOption<T>` with `Some(T::default())`.
/// This preserves the default behavior when wrapping types that implement `Default`.
impl<T> Default for DerefOption<T>

This helps users understand that the default is Some(T::default()) rather than None, which is non-obvious for an Option wrapper.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

📦 Binary Size-limit

Comparing f279601 to fix: relative-resource-path should handle output.filename (#12398) by Cong-Cong Pan

❌ Size increased by 128bytes from 47.72MB to 47.72MB (⬆️0.00%)

@github-actions
Copy link
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 project(s) in monorepo.

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

📌 Baseline Commit: 4b73bc2ee7 | PR: #12403

Metric Current Baseline Change
📊 Total Size 5.7 MB 5.7 MB 0 B (0.0%)
📄 JavaScript 5.7 MB 5.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-10k Bundle Diff

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

📌 Baseline Commit: 4b73bc2ee7 | PR: #12403

Metric Current Baseline Change
📊 Total Size 823.6 KB 823.6 KB 0 B (0.0%)
📄 JavaScript 823.6 KB 823.6 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-1k Bundle Diff

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

📌 Baseline Commit: 4b73bc2ee7 | PR: #12403

Metric Current Baseline Change
📊 Total Size 2.7 MB 2.7 MB 0 B (0.0%)
📄 JavaScript 2.7 MB 2.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-5k Bundle Diff

📁 rome

Path: ../build-tools-performance/cases/rome/dist/rsdoctor-data.json

📌 Baseline Commit: 4b73bc2ee7 | PR: #12403

Metric Current Baseline Change
📊 Total Size 984.3 KB 984.3 KB 0 B (0.0%)
📄 JavaScript 984.3 KB 984.3 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: rome Bundle Diff

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

📌 Baseline Commit: 4b73bc2ee7 | PR: #12403

Metric Current Baseline Change
📊 Total Size 2.1 MB 2.1 MB 0 B (0.0%)
📄 JavaScript 2.0 MB 2.0 MB 0 B (0.0%)
🎨 CSS 83.0 KB 83.0 KB 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: ui-components Bundle Diff

Generated by Rsdoctor GitHub Action

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 10, 2025

CodSpeed Performance Report

Merging #12406 will not alter performance

Comparing refactor/deref_option_default (f279601) with main (4b73bc2)

Summary

✅ 17 untouched

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants