Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REDUNDANT_IMPORTS lint for new redundant import detection #123813

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Apr 11, 2024

Defaults to Allow for now. Stacked on #123744 to avoid merge conflict, but much easier to review all as one.

r? petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 11, 2024
@compiler-errors compiler-errors added the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Apr 11, 2024
@compiler-errors
Copy link
Member Author

nominating for T-lang to see if we'd like to keep this as allow or make it warn, etc., and perhaps to follow-up on the policy.

for the record, I think this lint is perhaps noisy but also very useful, so I'd like to see it at Warn level eventually. just not curious what the best rollout strategy is for that.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 exporting to docker image format
#16 sending tarball 29.7s done
#16 DONE 33.0s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
  Downloaded boml v0.3.1
   Compiling boml v0.3.1
   Compiling y v0.1.0 (/checkout/compiler/rustc_codegen_gcc/build_system)
    Finished `release` profile [optimized] target(s) in 3.50s
     Running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-codegen/x86_64-unknown-linux-gnu/release/y test --use-system-gcc --use-backend gcc --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc --release --mini-tests --std-tests`
Using system GCC
[BUILD] example
[AOT] mini_core_hello_world
/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc/mini_core_hello_world
abc
---
 finished in 1.465 seconds
##[endgroup]
Generating lint docs (x86_64-unknown-linux-gnu)
##[group]Running stage2 lint-docs (x86_64-unknown-linux-gnu)
error: failed to test example in lint docs for `redundant_imports` in /checkout/compiler/rustc_lint_defs/src/builtin.rs:423: lint docs should start with the text "The `redundant_imports` lint" to introduce the lint
This error was generated by the lint-docs tool.
This tool extracts documentation for lints from the source code and places
This tool extracts documentation for lints from the source code and places
them in the rustc book. See the declare_lint! documentation
https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html


To re-run these tests, run: ./x.py test --keep-stage=0 src/tools/lint-docs
The --keep-stage flag should be used if you have already built the compiler

Build completed unsuccessfully in 0:34:26
  local time: Thu Apr 11 19:16:43 UTC 2024
  network time: Thu, 11 Apr 2024 19:16:44 GMT

@petrochenkov petrochenkov added T-lang Relevant to the language team, which will review and decide on the PR/issue. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2024
@@ -419,6 +420,29 @@ declare_lint! {
"imports that are never used"
}

declare_lint! {
/// The `unused_imports` lint detects imports that are redundant due to being
Copy link
Contributor

Choose a reason for hiding this comment

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

*redundant_imports

@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

We discussed this in the lang meeting today. We came to the consensus that we want to split out into a separate allow-by-default lint (or, alternatively, not lint at all) the case of an import that is redundant due to a glob import.

There are two reasons for this.

One, and most importantly, is that if we were to not do this, a warn-by-default lint here would make adding functions, statics, or consts to a prelude (including the one in the standard library) so disruptive as to have to be treated almost like a breaking change.

Two is that not doing this would make it annoying to migrate away from a glob import incrementally.

Once this case is separated out, we're OK with the remainder of this lint going directly to warn-by-default.

@rustbot rustbot removed the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants