Skip to content

lint: ban glob imports (clippy::wildcard_imports) with explicit opt-out #1873

Closed

Description

@zackees

Question

Google style guides forbid wildcard imports. Should the Rust workspace do the same, and should zackees/ci.yml enforce it across repos with an opt-out?

What Google actually says

  • Java: Google Java Style §3.3.1 says "Wildcard imports, static or otherwise, are not used." This is a hard rule.
  • Python: Google Python Style §2.2 says to import packages and modules only, not individual names, which rules out from x import *.
  • Rust: Google publishes no Rust style rule against globs. Comprehensive Rust itself writes use super::*; in its #[cfg(test)] examples. The Android and Chromium Rust docs defer to rustfmt/Clippy and have no glob ban. The idiomatic Rust norm, which Clippy encodes, is: avoid globs, except use super::* in test modules and preludes.

So "Google bans wildcards" holds for Java and Python. For Rust, the closest standard is Clippy's wildcard_imports, and that lint already carries the two usual exemptions.

Current state (rust/ + dylints/, target dirs excluded)

There are 153 glob use lines:

Category Count Example
proptest::prelude::* 98 Tier 1 property tests. Clippy exempts these (prelude).
use super::* 17 rust/obs-build/src/platform/shared_library.rs:27, rust/obs-media-io/src/ffi/audio_io.rs:130. Exempt when inside #[cfg(test)].
pub use x::* re-exports 11 rust/obs-build/src/platform/mod.rs:295 (pub use qt_sdk::*), rust/obs-util/src/ffi/threading.rs:11,14 (posix::*/windows::*), rust/obs-util/src/ffi/platform_{windows,cocoa}.rs (shims::*), rust/obs-media-io/src/audio_io.rs:245
Enum-variant globs ~11 rust/obs-util/tests/config/cf_tokenizer.rs:62 (use CfTokenType::*), BaseTokenType::*, Op::*, Access::*
Crate/FFI-module globs in tests ~14 rust/obs-gpu-status/tests/gpu_status/classify.rs:7 (use obs_gpu_status::*, 6 files), obs_c_oracle::array_serializer::*, obs_media_io::ffi::{audio,video}_io::*
Macro-generated 2 rust/obs-properties/tests/properties/parity.rs:387,774 (use $api::*, selects C vs Rust API for differential tests)

About 115 of the 153 are already exempt under Clippy's defaults. Roughly 35-40 sites would need either a fix or an opt-out. None are bindgen output. The pub use platform::* re-exports are the deliberate cfg_select! platform boundary facade (testing-policy "Platform boundary").

Tooling

  • clippy::wildcard_imports (pedantic) covers use/pub use globs. By default it skips use super::* in test modules and any *::prelude::*. clippy.toml settings: warn-on-all-wildcard-imports (default false, keep it that way) and allowed-wildcard-imports = [...] to allow-list specific crates or modules.
  • clippy::enum_glob_use (pedantic) covers use Enum::*.
  • No Dylint is needed. Clippy already handles this, including the exemptions.
  • Current workspace config: there is no [workspace.lints] in Cargo.toml and no clippy.toml. ./lint and ci/local_gate.py:366 run soldr cargo clippy --workspace --all-targets --locked -- -D warnings, so both lints are currently off.
  • Enabling: add to the root Cargo.toml
    [workspace.lints.clippy]
    wildcard_imports = "deny"
    enum_glob_use = "deny"
    plus [lints] workspace = true in each member crate. Because clippy runs with --all-targets, tests are covered too.
  • Opt-out syntax: put #[expect(clippy::wildcard_imports, reason = "...")] on the use item or the enclosing module. Prefer #[expect] over #[allow], because a stale expect becomes an error once the glob is gone. If many sites share one reason (e.g. obs_c_oracle), list it in allowed-wildcard-imports in clippy.toml instead.

Recommendation

Ban globs, with exemptions:

  1. Turn on wildcard_imports and enum_glob_use as deny in [workspace.lints.clippy].
  2. Keep Clippy's built-in exemptions: use super::* in #[cfg(test)] modules and *::prelude::* (proptest).
  3. Use #[expect(..., reason)] opt-outs for:
    • the platform facade re-exports (platform/mod.rs, ffi/threading.rs, shims::*), where the glob is the design;
    • the $api::* macro in the differential parity tests.
  4. Fix the rest with explicit imports. This includes the enum-variant globs in test code (CfTokenType::* becomes CfTokenType::{Word, ...} or CfTokenType::Word written out) and the crate globs in tests/ integration files.

Rollout: fix everything in one PR rather than ratcheting. About 35-40 sites is small, mechanical work (cargo clippy --fix does not rewrite globs, but rust-analyzer's "expand glob import" does). A ratchet would cost more to maintain than the fix. Order: land the RED commit (lints enabled, clippy fails), then the GREEN commit (explicit imports and #[expect]s). Under coordination.md this is a focused lint/config change, so local RED evidence is enough.

Cost:

  • About an hour of mechanical edits.
  • New code pays slightly longer import lists.
  • Benefits: no name shadowing or ambiguity when C-API symbol modules grow; grep-able provenance of FFI names (useful when tracking which obs_* symbol a Rust module provides); and new upstream symbols can't silently change which item resolves.

Cross-repo default (zackees/ci.yml)

This belongs in zackees/ci.yml's docs/policy-rust.md as a candidate rule (next free ID after RUST-018). A follow-up issue there could read:

RUST-019 (candidate): glob imports denied via Clippy, with explicit opt-out. A Rust repo declares [workspace.lints.clippy] wildcard_imports = "deny" and enum_glob_use = "deny", or the same flags on its clippy invocation. Clippy's default exemptions stay on: use super::* in #[cfg(test)] and *::prelude::*, with warn-on-all-wildcard-imports left false. Opt-outs are #[expect(clippy::wildcard_imports, reason = "...")] at the site, or allowed-wildcard-imports in clippy.toml. A repo-wide allow counts as an exception and goes in ci.toml [[exceptions]]. ci_lint precheck can check this statically: parse Cargo.toml [workspace.lints.clippy] and flag allow/missing. Needs RED/GREEN fixtures under ci_lint/tests/fixtures/RUST-019/. Rationale: Google Java Style §3.3.1 / Python §2.2 forbid wildcard imports, and Clippy encodes the Rust-idiomatic version.

obs-studio should not wait for that. Enable the workspace lints here first, then adopt the ci.yml rule once it exists.

Activity

  1. vpacher commented on Oct 23, 2026

    @vpacher
    Member

    +1 for the glob ban as proposed. The Clippy defaults and the #[expect(..., reason)] opt-outs are a good fit.

    One related point. I suggest a separate issue for it, because the scope and the tooling are different.

    In Rust, a glob import cannot silently change behaviour: rustc reports ambiguous names, and explicit items shadow glob items. The higher risk in this workspace is Cargo feature unification. Some features mirror C build options (for example gio = GIO_FOUND). Cargo unifies features across one build, so the CI lanes do not build the feature sets that CMake ships.

    Example on master (dc5b192):

    • libobs-rust has default = ["gio"] → obs-util/gio.
    • CMake does it correctly: NO_DEFAULT_FEATURES, then gio only if Gio is found (libobs/cmake/os-linux.cmake:82-84, os-freebsd.cmake:77-79).
    • CI runs cargo test --workspace and cargo clippy --workspace --all-targets. In these runs, cargo tree --workspace -e features -i obs-util shows gio always on.
    • Result: the #[cfg(not(feature = "gio"))] code in rust/obs-util/src/ffi/platform_nix_inhibit.rs is not compiled, linted or tested by the Rust lanes. A libobs built without GIO ships that code.

    The opt-in features (libobs-integration, bundled-native) have the opposite gap: they are off in the --workspace lanes.

    Second, smaller point: [workspace.dependencies] has only libloading. Other third-party dependencies are declared per crate, with different pins and features (cc, pkg-config, serde, serde_json).

    If you agree, I will open a separate issue: "CI: build and test the Cargo feature sets that CMake uses" (feature matrix lane with cargo hack, third-party dependencies in [workspace.dependencies] with default-features = false). A ci_lint rule for zackees/ci.yml could go next to the RUST-019 proposal.

  2. zackees commented on Oct 23, 2026

    @zackees
    MemberAuthor

    i agree

  3. zackees commented on Oct 23, 2026

    @zackees
    MemberAuthor

    Claiming: #1873 workspace glob-import ban.

    Plan (one PR):

    1. RED: [workspace.lints.clippy] wildcard_imports/enum_glob_use = "deny" + [lints] workspace = true in members; record the local clippy failure.
    2. GREEN: explicit imports; #[expect(..., reason)] only for the platform facade re-exports and the $api::* parity macro.

    First PR expected today.

  4. added
    claimed
    on Oct 23, 2026
  5. zackees commented on Oct 23, 2026

    @zackees
    MemberAuthor

    Fixed by #1956: wildcard_imports and enum_glob_use are deny in [workspace.lints.clippy], and every rust/* crate uses them.

    Clippy's default exemptions (integration test crates, #[cfg(test)] modules, preludes, pub use re-exports) covered most of the sites this issue counted. Only six non-test use super::* sites needed explicit imports, and no #[expect] opt-outs were needed.

    Left: the cross-repo RUST-019 rule in zackees/ci.yml, and the Cargo feature-matrix issue proposed above. Neither is filed yet.

  6. vpacher commented on Oct 24, 2026

    @vpacher
    Member

    Filed the Cargo feature-matrix part as #2056.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions