Skip to content

fix(desktop): scope webview builder mutability - #2583

Open
1688mengdie wants to merge 1 commit into
GCWing:mainfrom
BitFun-SIG:fix/ci-warning-browser-api-mut
Open

fix(desktop): scope webview builder mutability#2583
1688mengdie wants to merge 1 commit into
GCWing:mainfrom
BitFun-SIG:fix/ci-warning-browser-api-mut

Conversation

@1688mengdie

Copy link
Copy Markdown

Summary

browser_webview_create declares its WebviewBuilder as mut unconditionally, but the only mutating call (builder.devtools(true)) is compiled solely under #[cfg(any(debug_assertions, feature = "devtools"))]. In release builds without the devtools feature the mutation is compiled out and the compiler flags the binding as unused_mut. This PR moves the mutation into the cfg block by shadowing: the outer binding becomes immutable, and the devtools block rebinds a local mut copy, applies the flag, and returns it.

Fixes #2581

Type and Areas

Type: Bug fix

Areas: Rust core (desktop, built-in browser API)

Motivation / Impact

Release-mode builds of the desktop crate currently emit an unused_mut warning from the browser webview creation path, which pollutes build output for anyone building without dev tooling. After this change the mutability exactly matches the consumer surface on every build configuration; builder construction and the final add_child consumer are unchanged, so behavior is identical everywhere. No direct user-facing change beyond cleaner build output.

Verification

  • cargo check --release -p bitfun-desktop --jobs 4 on Windows: 0 errors, 0 warnings; the browser_api.rs:145 unused_mut warning present on main is gone.
  • cargo check -p bitfun-desktop --jobs 4 (dev profile, cfg block active): 0 errors, 0 warnings.
  • Reproduce: check out this branch on Windows and run the two commands above; the warning present on main disappears. The unix/macOS compilation surface is n/a locally — no Linux/macOS machine available — and the platform matrix in CI is exactly the place this gets verified.

AI-assisted change, lightly tested.

Reviewer Notes

  • The shadowing form (immutable outer binding + let mut rebind inside the cfg block) is deliberate: it removes the mut requirement from the release/devtools-less compilation unit without changing any builder call or the add_child consumer.
  • No test surface is affected: browser_api.rs contains no tests, and the diff touches no assertions.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (Not applicable: no user-facing change.)

The browser_webview_create helper declared its WebviewBuilder as mut
unconditionally, but the only mutating call (enabling devtools) is
compiled solely under #[cfg(any(debug_assertions, feature =
"devtools"))]. In release builds without the devtools feature the mut
requirement disappears and the compiler flags the binding as
unused_mut.

Move the mutation into the cfg block by shadowing: the outer binding
is immutable, and the devtools block rebinds a local mut copy, applies
the devtools flag, and returns it. Builder construction and the final
add_child consumer are unchanged, so behavior is identical on every
build configuration while the mutability now exactly matches the
consumer surface.

Test: cargo check --release -p bitfun-desktop --jobs 4 (browser_api unused_mut gone; lib compiles 0 warnings)
Test: cargo check -p bitfun-desktop (dev profile, cfg block active, 0 errors 0 warnings)

AI: This commit was authored with AI assistance; checks were run locally on Windows (release + dev profiles) and non-Windows compilation surfaces are to be confirmed by the upstream multi-OS CI matrix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: unused_mut warning for the browser webview builder in release builds

1 participant