Skip to content

Commit 3e43de4

Browse files
committed
use contains("test")
1 parent c10028f commit 3e43de4

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ pub trait LintContext: Sized {
681681
let def_span = self.sess().source_map().guess_head_span(span);
682682
db.span_help(
683683
span.shrink_to_lo().to(def_span),
684-
"consider adding a `#[cfg(test)]` to the module named `test` in which this import is",
684+
"consider adding a `#[cfg(test)]` to the parent module",
685685
);
686686
}
687687
}

compiler/rustc_resolve/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl Resolver<'_> {
320320
visitor.r.local_def_id(unused.use_tree_id).to_def_id(),
321321
);
322322
let test_module_span = match module_to_string(parent_module) {
323-
Some(module) if module == "test" => Some(parent_module.span),
323+
Some(module) if module.contains("test") => Some(parent_module.span),
324324
_ => None,
325325
};
326326

src/test/ui/imports/unused-imports-in-test-module.rs

+8
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ mod test {
1313
}
1414
}
1515

16+
mod test_a {
17+
use super::a; //~ ERROR unused import: `super::a`
18+
19+
fn foo() {
20+
use crate::b; //~ ERROR unused import: `crate::b`
21+
}
22+
}
23+
1624
fn main() {}

src/test/ui/imports/unused-imports-in-test-module.stderr

+27-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error: unused import: `super::a`
1616
LL | use super::a;
1717
| ^^^^^^^^
1818
|
19-
help: consider adding a `#[cfg(test)]` to the module named `test` in which this import is
19+
help: consider adding a `#[cfg(test)]` to the parent module
2020
--> $DIR/unused-imports-in-test-module.rs:8:1
2121
|
2222
LL | mod test {
@@ -28,11 +28,35 @@ error: unused import: `crate::b`
2828
LL | use crate::b;
2929
| ^^^^^^^^
3030
|
31-
help: consider adding a `#[cfg(test)]` to the module named `test` in which this import is
31+
help: consider adding a `#[cfg(test)]` to the parent module
3232
--> $DIR/unused-imports-in-test-module.rs:8:1
3333
|
3434
LL | mod test {
3535
| ^^^^^^^^
3636

37-
error: aborting due to 3 previous errors
37+
error: unused import: `super::a`
38+
--> $DIR/unused-imports-in-test-module.rs:17:9
39+
|
40+
LL | use super::a;
41+
| ^^^^^^^^
42+
|
43+
help: consider adding a `#[cfg(test)]` to the parent module
44+
--> $DIR/unused-imports-in-test-module.rs:16:1
45+
|
46+
LL | mod test_a {
47+
| ^^^^^^^^^^
48+
49+
error: unused import: `crate::b`
50+
--> $DIR/unused-imports-in-test-module.rs:20:13
51+
|
52+
LL | use crate::b;
53+
| ^^^^^^^^
54+
|
55+
help: consider adding a `#[cfg(test)]` to the parent module
56+
--> $DIR/unused-imports-in-test-module.rs:16:1
57+
|
58+
LL | mod test_a {
59+
| ^^^^^^^^^^
60+
61+
error: aborting due to 5 previous errors
3862

0 commit comments

Comments
 (0)