about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-01 17:51:29 +0100
committerGitHub <noreply@github.com>2024-03-01 17:51:29 +0100
commit58825b4ea9354ab4e78ae96a1b0942d33c9db4ab (patch)
tree202471ec72342f7724ad9b63345f49071d9d2e4d
parentdcde08f21c151989cb5fb10ad60c25f4dbe36212 (diff)
parent748c6151be9906c8bc201fa79b8d1d49715968b2 (diff)
downloadrust-58825b4ea9354ab4e78ae96a1b0942d33c9db4ab.tar.gz
rust-58825b4ea9354ab4e78ae96a1b0942d33c9db4ab.zip
Rollup merge of #121580 - Suyashtnt:issue-121502-fix, r=michaelwoerister
make unused_imports less assertive in test modules

closes #121502

This is a fairly small change and I used the fix suggested in the example expected error message.
Not sure if I should've rather used the alternatives but this one seems the most descriptive.

Some alternatives:
- if this is meant to be a test module, add `#[cfg(test)]` to the containing module
- try adding #[cfg(test)] to this test module
- consider adding #[allow(unused_imports)] if you want to silent the lint on the unused import
- consider removing the unused import
-rw-r--r--compiler/rustc_lint/src/context/diagnostics.rs2
-rw-r--r--tests/ui/imports/unused-imports-in-test-module.stderr12
2 files changed, 7 insertions, 7 deletions
diff --git a/compiler/rustc_lint/src/context/diagnostics.rs b/compiler/rustc_lint/src/context/diagnostics.rs
index 14e4c79563b..728996f0741 100644
--- a/compiler/rustc_lint/src/context/diagnostics.rs
+++ b/compiler/rustc_lint/src/context/diagnostics.rs
@@ -104,7 +104,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag:
             if let Some(span) = in_test_module {
                 diag.span_help(
                     sess.source_map().guess_head_span(span),
-                    "consider adding a `#[cfg(test)]` to the containing module",
+                    "if this is a test module, consider adding a `#[cfg(test)]` to the containing module",
                 );
             }
         }
diff --git a/tests/ui/imports/unused-imports-in-test-module.stderr b/tests/ui/imports/unused-imports-in-test-module.stderr
index 1598368eb32..2d885efc099 100644
--- a/tests/ui/imports/unused-imports-in-test-module.stderr
+++ b/tests/ui/imports/unused-imports-in-test-module.stderr
@@ -16,7 +16,7 @@ error: unused import: `super::a`
 LL |     use super::a;
    |         ^^^^^^^^
    |
-help: consider adding a `#[cfg(test)]` to the containing module
+help: if this is a test module, consider adding a `#[cfg(test)]` to the containing module
   --> $DIR/unused-imports-in-test-module.rs:8:1
    |
 LL | mod test {
@@ -28,7 +28,7 @@ error: unused import: `super::a`
 LL |     use super::a;
    |         ^^^^^^^^
    |
-help: consider adding a `#[cfg(test)]` to the containing module
+help: if this is a test module, consider adding a `#[cfg(test)]` to the containing module
   --> $DIR/unused-imports-in-test-module.rs:18:1
    |
 LL | mod tests {
@@ -40,7 +40,7 @@ error: unused import: `super::a`
 LL |     use super::a;
    |         ^^^^^^^^
    |
-help: consider adding a `#[cfg(test)]` to the containing module
+help: if this is a test module, consider adding a `#[cfg(test)]` to the containing module
   --> $DIR/unused-imports-in-test-module.rs:28:1
    |
 LL | mod test_a {
@@ -52,7 +52,7 @@ error: unused import: `super::a`
 LL |     use super::a;
    |         ^^^^^^^^
    |
-help: consider adding a `#[cfg(test)]` to the containing module
+help: if this is a test module, consider adding a `#[cfg(test)]` to the containing module
   --> $DIR/unused-imports-in-test-module.rs:38:1
    |
 LL | mod a_test {
@@ -64,7 +64,7 @@ error: unused import: `super::a`
 LL |     use super::a;
    |         ^^^^^^^^
    |
-help: consider adding a `#[cfg(test)]` to the containing module
+help: if this is a test module, consider adding a `#[cfg(test)]` to the containing module
   --> $DIR/unused-imports-in-test-module.rs:48:1
    |
 LL | mod tests_a {
@@ -76,7 +76,7 @@ error: unused import: `super::a`
 LL |     use super::a;
    |         ^^^^^^^^
    |
-help: consider adding a `#[cfg(test)]` to the containing module
+help: if this is a test module, consider adding a `#[cfg(test)]` to the containing module
   --> $DIR/unused-imports-in-test-module.rs:58:1
    |
 LL | mod a_tests {