Skip to content

resolve: Remove exported imports from maybe_unused_trait_imports#157713

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
petrochenkov:regr197unused
Jun 12, 2026
Merged

resolve: Remove exported imports from maybe_unused_trait_imports#157713
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
petrochenkov:regr197unused

Conversation

@petrochenkov

Copy link
Copy Markdown
Contributor

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes #157420.

@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Failed to set assignee to oli-obk: req=https://api.github.com/repos/rust-lang/rust/issues/157713/assignees (x-github-request-id: 5097:A6A96:89536D3:8ABE783:6A2988E1): {
"message": "Requires authentication",
"documentation_url": "https://docs.github.com/rest",
"status": "401"
}

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot

rustbot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 16 candidates

@petrochenkov

petrochenkov commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

I'm not yet sure why the issue doesn't happen in simpler cases like

pub use module::Trait; // exported, but not used locally

mod module {
    pub trait Trait {}
}

/// [S::assoc]
pub struct S {}

, such imports are probably marked as "used" in some other way, but in any case the change in this PR should be correct, and it fixes the regression.

@petrochenkov

Copy link
Copy Markdown
Contributor Author

why the issue doesn't happen in simpler cases

This is why:
https://github.com/rust-lang/rust/blob/main/compiler/rustc_hir_analysis/src/check_unused.rs#L41-L43

@petrochenkov petrochenkov added beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 10, 2026

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b4a1fc7 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 11, 2026
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 11, 2026
resolve: Remove exported imports from `maybe_unused_trait_imports`

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes rust-lang#157420.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 11, 2026
resolve: Remove exported imports from `maybe_unused_trait_imports`

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes rust-lang#157420.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 11, 2026
resolve: Remove exported imports from `maybe_unused_trait_imports`

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes rust-lang#157420.
@rustbot

rustbot commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

beta backport approved as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels are handled by them.

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jun 11, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 11, 2026
resolve: Remove exported imports from `maybe_unused_trait_imports`

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes rust-lang#157420.
@mu001999

Copy link
Copy Markdown
Member

So why does #154149 break this?

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 11, 2026
resolve: Remove exported imports from `maybe_unused_trait_imports`

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes rust-lang#157420.
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #157716 (update Enzyme, June'26)
 - #149793 (Add inline asm support for amdgpu)
 - #152852 (Remove driver_lint_caps)
 - #155299 (make repr_transparent_non_zst_fields a hard error)
 - #155439 (Enable Cargo's new build-dir layout)
 - #157612 (Add a test where subtyping inhibits coercion.)
 - #157626 (Autogenerate unstable compiler flag stubs for unstable-book)
 - #157667 (Rename typing modes to better describe real usage)
 - #156212 (Additionally gate negative bounds behind new `-Zinternal-testing-features`)
 - #157342 (Reduce verbosity of cycle errors when possible)
 - #157366 (Add a regression test for an unconstrained TransmuteFrom ICE)
 - #157459 (rustc_target: callconv: powerpc64: Remove unreachable fallback code path)
 - #157658 (UnsafeCell: mention shared-ref-to-interior case, fix aliasing model inaccuracy)
 - #157698 (Remove an unnecessary cloning)
 - #157699 (Arg splat experiment - hir FnDecl impl)
 - #157713 (resolve: Remove exported imports from `maybe_unused_trait_imports`)
 - #157722 (Move create_scope_map to rustc_codegen_ssa.)
 - #157725 (Keep generic suggestion for macro-expanded missing-type items)
 - #157733 (Remove old FIXMEs about nocapture attribute)
 - #157737 (Reorganize `tests/ui/issues` [7/N])
 - #157746 (supports_c_variadic_definitions: extend checklist for new targets)
 - #157763 (Move unused target expression error to appropriate place and rename it)
 - #157768 (codegen_ssa: peel trans. wrappers on scalable vecs)
@cuviper cuviper mentioned this pull request Jun 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #157716 (update Enzyme, June'26)
 - #149793 (Add inline asm support for amdgpu)
 - #152852 (Remove driver_lint_caps)
 - #155299 (make repr_transparent_non_zst_fields a hard error)
 - #155439 (Enable Cargo's new build-dir layout)
 - #157612 (Add a test where subtyping inhibits coercion.)
 - #157626 (Autogenerate unstable compiler flag stubs for unstable-book)
 - #157667 (Rename typing modes to better describe real usage)
 - #156212 (Additionally gate negative bounds behind new `-Zinternal-testing-features`)
 - #157342 (Reduce verbosity of cycle errors when possible)
 - #157366 (Add a regression test for an unconstrained TransmuteFrom ICE)
 - #157459 (rustc_target: callconv: powerpc64: Remove unreachable fallback code path)
 - #157658 (UnsafeCell: mention shared-ref-to-interior case, fix aliasing model inaccuracy)
 - #157698 (Remove an unnecessary cloning)
 - #157699 (Arg splat experiment - hir FnDecl impl)
 - #157713 (resolve: Remove exported imports from `maybe_unused_trait_imports`)
 - #157722 (Move create_scope_map to rustc_codegen_ssa.)
 - #157725 (Keep generic suggestion for macro-expanded missing-type items)
 - #157733 (Remove old FIXMEs about nocapture attribute)
 - #157737 (Reorganize `tests/ui/issues` [7/N])
 - #157746 (supports_c_variadic_definitions: extend checklist for new targets)
 - #157763 (Move unused target expression error to appropriate place and rename it)
 - #157768 (codegen_ssa: peel trans. wrappers on scalable vecs)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 11, 2026
resolve: Remove exported imports from `maybe_unused_trait_imports`

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes rust-lang#157420.
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
…uwer

Rollup of 23 pull requests

Successful merges:

 - #157716 (update Enzyme, June'26)
 - #149793 (Add inline asm support for amdgpu)
 - #155299 (make repr_transparent_non_zst_fields a hard error)
 - #155439 (Enable Cargo's new build-dir layout)
 - #157612 (Add a test where subtyping inhibits coercion.)
 - #157626 (Autogenerate unstable compiler flag stubs for unstable-book)
 - #157667 (Rename typing modes to better describe real usage)
 - #149749 (Make `BorrowedBuf` and `BorrowedCursor` generic over the data)
 - #156212 (Additionally gate negative bounds behind new `-Zinternal-testing-features`)
 - #157342 (Reduce verbosity of cycle errors when possible)
 - #157366 (Add a regression test for an unconstrained TransmuteFrom ICE)
 - #157459 (rustc_target: callconv: powerpc64: Remove unreachable fallback code path)
 - #157658 (UnsafeCell: mention shared-ref-to-interior case, fix aliasing model inaccuracy)
 - #157698 (Remove an unnecessary cloning)
 - #157699 (Arg splat experiment - hir FnDecl impl)
 - #157713 (resolve: Remove exported imports from `maybe_unused_trait_imports`)
 - #157722 (Move create_scope_map to rustc_codegen_ssa.)
 - #157725 (Keep generic suggestion for macro-expanded missing-type items)
 - #157733 (Remove old FIXMEs about nocapture attribute)
 - #157737 (Reorganize `tests/ui/issues` [7/N])
 - #157746 (supports_c_variadic_definitions: extend checklist for new targets)
 - #157763 (Move unused target expression error to appropriate place and rename it)
 - #157768 (codegen_ssa: peel trans. wrappers on scalable vecs)
rust-bors Bot pushed a commit that referenced this pull request Jun 12, 2026
Rollup of 24 pull requests

Successful merges:

 - #157716 (update Enzyme, June'26)
 - #149793 (Add inline asm support for amdgpu)
 - #155299 (make repr_transparent_non_zst_fields a hard error)
 - #157612 (Add a test where subtyping inhibits coercion.)
 - #157626 (Autogenerate unstable compiler flag stubs for unstable-book)
 - #157667 (Rename typing modes to better describe real usage)
 - #149749 (Make `BorrowedBuf` and `BorrowedCursor` generic over the data)
 - #155113 (Ensure Send/Sync impl for std::process::CommandArgs)
 - #156212 (Additionally gate negative bounds behind new `-Zinternal-testing-features`)
 - #157342 (Reduce verbosity of cycle errors when possible)
 - #157366 (Add a regression test for an unconstrained TransmuteFrom ICE)
 - #157459 (rustc_target: callconv: powerpc64: Remove unreachable fallback code path)
 - #157658 (UnsafeCell: mention shared-ref-to-interior case, fix aliasing model inaccuracy)
 - #157698 (Remove an unnecessary cloning)
 - #157699 (Arg splat experiment - hir FnDecl impl)
 - #157713 (resolve: Remove exported imports from `maybe_unused_trait_imports`)
 - #157722 (Move create_scope_map to rustc_codegen_ssa.)
 - #157723 (Move uninhabited unreachable code lint to rustc_mir_transform)
 - #157725 (Keep generic suggestion for macro-expanded missing-type items)
 - #157733 (Remove old FIXMEs about nocapture attribute)
 - #157737 (Reorganize `tests/ui/issues` [7/N])
 - #157746 (supports_c_variadic_definitions: extend checklist for new targets)
 - #157763 (Move unused target expression error to appropriate place and rename it)
 - #157768 (codegen_ssa: peel trans. wrappers on scalable vecs)
@rust-bors rust-bors Bot merged commit 0950899 into rust-lang:main Jun 12, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 12, 2026
rust-timer added a commit that referenced this pull request Jun 12, 2026
Rollup merge of #157713 - petrochenkov:regr197unused, r=oli-obk

resolve: Remove exported imports from `maybe_unused_trait_imports`

If an import is visible from outside of the crate, then it's effectively used and shouldn't be reported by any kinds of unused import lints.

Fixes #157420.
@cuviper cuviper modified the milestones: 1.98.0, 1.97.0 Jun 12, 2026
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jun 12, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 12, 2026
[beta] backports

- Revert "Build shared LLVM lib for windows-gnullvm" #156962
- Allow building the source tarballs while offline #157014
- resolve: Partially revert "Remove a special case for dummy imports" #157719
- resolve: Remove exported imports from `maybe_unused_trait_imports` #157713
- [beta-1.97] Update cargo submodule #157792

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

Labels

beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants