1
Fork 0

Rollup merge of #91770 - TaKO8Ki:suggest-adding-cfg-test, r=joshtriplett

Suggest adding a `#[cfg(test)]` to to a test module

closes #88138
This commit is contained in:
Matthias Krüger 2021-12-21 08:33:39 +01:00 committed by GitHub
commit 790950a530
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 264 additions and 4 deletions

View file

@ -661,7 +661,7 @@ pub trait LintContext: Sized {
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
db.span_suggestion(span, &note, sugg, Applicability::MaybeIncorrect);
}
BuiltinLintDiagnostics::UnusedImports(message, replaces) => {
BuiltinLintDiagnostics::UnusedImports(message, replaces, in_test_module) => {
if !replaces.is_empty() {
db.tool_only_multipart_suggestion(
&message,
@ -669,6 +669,14 @@ pub trait LintContext: Sized {
Applicability::MachineApplicable,
);
}
if let Some(span) = in_test_module {
let def_span = self.sess().source_map().guess_head_span(span);
db.span_help(
span.shrink_to_lo().to(def_span),
"consider adding a `#[cfg(test)]` to the containing module",
);
}
}
BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
for (span, is_imported) in spans {