Skip to content

1.97 beta regression: Rust claims import is unused but crate doesn't compile with it removed #157420

Closed

Description

@orlp

I don't have a minimal reproducer, but I do have a reproducer.

  1. Check out polars at commit 133a52633ba7b0dc08c70a2662abf5d7547df06f.

  2. Run make build. Rust will give the following warning (among others):

warning: unused import: `crate::prelude`
 --> crates/polars-core/src/chunked_array/ops/sort/options.rs:5:5
  |
5 | use crate::prelude::*;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

However, if we remove this line, the project will fail to compile.

Meta

rustc --version --verbose:

rustc 1.98.0-nightly (d595fce01 2026-06-02)

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 4, 2026
  2. orlp commented on Jun 4, 2026

    @orlp
    ContributorAuthor

    I have a more minimal reproduction that only touches the polars-core crate without having to do the entire make build setup. It goes as follows (still on pola-rs/polars@133a526):

    cargo check -p polars-core 2>&1 | rg -i 'crate::prelude::\*' -C 4
    

    This will output:

    warning: unused import: `crate::prelude`
     --> crates/polars-core/src/chunked_array/ops/sort/options.rs:5:5
      |
    5 | use crate::prelude::*;
      |     ^^^^^^^^^^^^^^

    (There are a lot more warnings due to polars-core not being meant as a stand-alone crate, we don't bother getting rid of other unused warnings that aren't unused in the larger project / with full features.)

    However, removing that line will cause cargo check -p polars-core to fail to compile, so it's a false-positive warning.

  3. orlp commented on Jun 4, 2026

    @orlp
    ContributorAuthor

    I've added #[deny(unused_imports)] to crates/polars-core/src/chunked_array/ops/sort/options.rs:5:5. This let me use cargo bisect-rustc --start=2026-04-01 --end=2026-06-03 -- check -p polars-core:

    searched toolchains nightly-2026-04-01 through nightly-2026-06-03
    
    ********************************************************************************
    Regression in nightly-2026-05-01
    ********************************************************************************
    
    searched toolchains c935696dd07ca51e6fba2f6579919eea2a50863b through f53b654a8882fd5fc036c4ca7a4ff41ce32497a6
    
    ********************************************************************************
    Regression in a021a7796f66600f46013d6c8d1dfc9e8d7f4a92
    ********************************************************************************
    

    It seems a021a77 is the issue.


    From that roll-up commit I think it's #154149.

    @petrochenkov Assuming the above bisect blame isn't wrong, this would be the second regression introduced to Polars on nightly in that chain of commits. That PR is a revert of #152498 which also broke Polars (#152004). Perhaps it would be possible to try to build Polars with a potential new fix PR and see if it introduces new spurious warnings?

  4. changed the title [-]1.98 nightly regression: Rust claims import is unused but crate doesn't compile with it removed[/-] [+]1.97 beta regression: Rust claims import is unused but crate doesn't compile with it removed[/+] on Jun 4, 2026
  5. orlp commented on Jun 4, 2026

    @orlp
    ContributorAuthor

    I've also confirmed now that cargo +beta check -p polars-core fails with #[deny(unused_imports)] added before crates/polars-core/src/chunked_array/ops/sort/options.rs:5:5 on rustc 1.97.0-beta.2 (0417c2586 2026-05-30), so I've updated the title.

  6. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 4, 2026
  7. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    S-has-bisectionStatus: A bisection has been found for this issue
    and removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Jun 6, 2026
  8. theemathas commented on Jun 7, 2026

    @theemathas
    Contributor

    cc @petrochenkov @mu001999 (author and reviewer of #154149)

  9. self-assigned this
    on Jun 7, 2026
  10. petrochenkov commented on Jun 7, 2026

    @petrochenkov
    Contributor

    I've assigned myself and will look at this in the next few days, but having a minimized reproducer until then would still be nice.

  11. 9 remaining items

  12. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by name
    on Jun 8, 2026
  13. petrochenkov commented on Jun 10, 2026

    @petrochenkov
    Contributor

    I'm still trying to figure out what's going on.

    What is clear:

    • the crate::prelude::* import gets into maybe_unused_trait_imports, that's why it's reported as unused after type checking (compiler\rustc_hir_analysis\src\check_unused.rs), the imported trait is indeed not used
    • import gets into maybe_unused_trait_imports because /// [A::f] forces collection of traits in scope (and imports to them), and their addition to the potentially unused trait import set

    What is not clear:

    • why the crate::prelude::* import is not removed from the maybe_unused_trait_imports set, which is typically happens with imports that are used early, before type checking
      • basically early unused import checking considers the import neither unused (otherwise it'd report it), nor used (otherwise it'd remove it from maybe_unused_trait_imports)
  14. petrochenkov commented on Jun 10, 2026

    @petrochenkov
    Contributor

    Fixed in #157713.

  15. added 6 commits that reference this issue on Jun 11, 2026
  16. added a commit that references this issue on Jun 12, 2026
  17. added a commit that references this issue on Jun 12, 2026
  18. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.L-unused_importsLint: unused_importsS-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions