Reduce capabilities of `Diagnostic`.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)
`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.
The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)
All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.
There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.
There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-06 16:44:30 +11:00
|
|
|
#![allow(rustc::diagnostic_outside_of_impl)]
|
|
|
|
|
#![allow(rustc::untranslatable_diagnostic)]
|
|
|
|
|
|
2024-04-15 18:07:22 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
2023-12-30 16:13:23 +01:00
|
|
|
use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
|
2024-04-15 18:07:22 +00:00
|
|
|
use rustc_errors::Applicability;
|
|
|
|
|
use rustc_errors::{elided_lifetime_in_path_suggestion, DiagArgValue, MultiSpan};
|
2023-12-30 16:13:23 +01:00
|
|
|
use rustc_middle::middle::stability;
|
2024-04-15 18:07:22 +00:00
|
|
|
use rustc_session::lint::{BuiltinLintDiag, Lint};
|
2023-12-30 16:13:23 +01:00
|
|
|
use rustc_span::BytePos;
|
|
|
|
|
|
2024-04-15 18:07:22 +00:00
|
|
|
use crate::{lints, EarlyContext, LintContext as _};
|
2024-04-14 20:11:14 +00:00
|
|
|
|
2024-03-16 23:33:54 +01:00
|
|
|
mod check_cfg;
|
2024-02-16 21:32:53 +01:00
|
|
|
|
2024-04-15 18:07:22 +00:00
|
|
|
pub(super) fn emit_buffered_lint(
|
|
|
|
|
ctx: &EarlyContext<'_>,
|
|
|
|
|
lint: &'static Lint,
|
|
|
|
|
span: MultiSpan,
|
|
|
|
|
diagnostic: BuiltinLintDiag,
|
|
|
|
|
) {
|
|
|
|
|
let sess = ctx.sess();
|
2023-12-30 16:13:23 +01:00
|
|
|
match diagnostic {
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::UnicodeTextFlow(comment_span, content) => {
|
2023-12-30 16:13:23 +01:00
|
|
|
let spans: Vec<_> = content
|
|
|
|
|
.char_indices()
|
|
|
|
|
.filter_map(|(i, c)| {
|
|
|
|
|
TEXT_FLOW_CONTROL_CHARS.contains(&c).then(|| {
|
2024-04-15 18:07:22 +00:00
|
|
|
let lo = comment_span.lo() + BytePos(2 + i as u32);
|
|
|
|
|
(c, comment_span.with_lo(lo).with_hi(lo + BytePos(c.len_utf8() as u32)))
|
2023-12-30 16:13:23 +01:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
2024-04-15 18:07:22 +00:00
|
|
|
let characters = spans
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|&(c, span)| lints::UnicodeCharNoteSub { span, c_debug: format!("{c:?}") })
|
|
|
|
|
.collect();
|
|
|
|
|
let suggestions = (!spans.is_empty()).then_some(lints::UnicodeTextFlowSuggestion {
|
|
|
|
|
spans: spans.iter().map(|(_c, span)| *span).collect(),
|
|
|
|
|
});
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
2023-12-30 16:13:23 +01:00
|
|
|
span,
|
2024-04-15 18:07:22 +00:00
|
|
|
lints::UnicodeTextFlow {
|
|
|
|
|
comment_span,
|
|
|
|
|
characters,
|
|
|
|
|
suggestions,
|
|
|
|
|
num_codepoints: spans.len(),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::AbsPathWithModule(mod_span) => {
|
|
|
|
|
let (replacement, applicability) = match sess.source_map().span_to_snippet(mod_span) {
|
2023-12-30 16:13:23 +01:00
|
|
|
Ok(ref s) => {
|
|
|
|
|
// FIXME(Manishearth) ideally the emitting code
|
|
|
|
|
// can tell us whether or not this is global
|
|
|
|
|
let opt_colon = if s.trim_start().starts_with("::") { "" } else { "::" };
|
|
|
|
|
|
|
|
|
|
(format!("crate{opt_colon}{s}"), Applicability::MachineApplicable)
|
|
|
|
|
}
|
|
|
|
|
Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
|
|
|
|
|
};
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
2023-12-30 16:13:23 +01:00
|
|
|
span,
|
2024-04-15 18:07:22 +00:00
|
|
|
lints::AbsPathWithModule {
|
|
|
|
|
sugg: lints::AbsPathWithModuleSugg {
|
|
|
|
|
span: mod_span,
|
|
|
|
|
applicability,
|
|
|
|
|
replacement,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::ProcMacroDeriveResolutionFallback { span: macro_span, ns, ident } => ctx
|
|
|
|
|
.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::ProcMacroDeriveResolutionFallback { span: macro_span, ns, ident },
|
|
|
|
|
),
|
|
|
|
|
BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => ctx
|
|
|
|
|
.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::MacroExpandedMacroExportsAccessedByAbsolutePaths { definition: span_def },
|
|
|
|
|
),
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::ElidedLifetimesInPaths(n, path_span, incl_angl_brckt, insertion_span) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::ElidedLifetimesInPaths {
|
|
|
|
|
subdiag: elided_lifetime_in_path_suggestion(
|
|
|
|
|
sess.source_map(),
|
|
|
|
|
n,
|
|
|
|
|
path_span,
|
|
|
|
|
incl_angl_brckt,
|
|
|
|
|
insertion_span,
|
|
|
|
|
),
|
|
|
|
|
},
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-04-14 20:11:14 +00:00
|
|
|
BuiltinLintDiag::UnknownCrateTypes { span, candidate } => {
|
2024-04-15 18:07:22 +00:00
|
|
|
let sugg = candidate.map(|candidate| lints::UnknownCrateTypesSub { span, candidate });
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::UnknownCrateTypes { sugg });
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::UnusedImports {
|
|
|
|
|
remove_whole_use,
|
|
|
|
|
num_to_remove,
|
|
|
|
|
remove_spans,
|
|
|
|
|
test_module_span,
|
|
|
|
|
span_snippets,
|
|
|
|
|
} => {
|
|
|
|
|
let sugg = if remove_whole_use {
|
|
|
|
|
lints::UnusedImportsSugg::RemoveWholeUse { span: remove_spans[0] }
|
|
|
|
|
} else {
|
|
|
|
|
lints::UnusedImportsSugg::RemoveImports { remove_spans, num_to_remove }
|
|
|
|
|
};
|
|
|
|
|
let test_module_span =
|
|
|
|
|
test_module_span.map(|span| sess.source_map().guess_head_span(span));
|
2023-12-30 16:13:23 +01:00
|
|
|
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::UnusedImports {
|
|
|
|
|
sugg,
|
|
|
|
|
test_module_span,
|
|
|
|
|
num_snippets: span_snippets.len(),
|
|
|
|
|
span_snippets: DiagArgValue::StrListSepByAnd(
|
|
|
|
|
span_snippets.into_iter().map(Cow::Owned).collect(),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::RedundantImport(spans, ident) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
let subs = spans
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|(span, is_imported)| {
|
|
|
|
|
(match (span.is_dummy(), is_imported) {
|
|
|
|
|
(false, true) => lints::RedundantImportSub::ImportedHere,
|
|
|
|
|
(false, false) => lints::RedundantImportSub::DefinedHere,
|
|
|
|
|
(true, true) => lints::RedundantImportSub::ImportedPrelude,
|
|
|
|
|
(true, false) => lints::RedundantImportSub::DefinedPrelude,
|
|
|
|
|
})(span)
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::RedundantImport { subs, ident });
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-21 13:24:25 +00:00
|
|
|
BuiltinLintDiag::DeprecatedMacro {
|
|
|
|
|
suggestion,
|
|
|
|
|
suggestion_span,
|
|
|
|
|
note,
|
|
|
|
|
path,
|
|
|
|
|
since_kind,
|
|
|
|
|
} => {
|
|
|
|
|
let sub = suggestion.map(|suggestion| stability::DeprecationSuggestion {
|
|
|
|
|
span: suggestion_span,
|
|
|
|
|
kind: "macro".to_owned(),
|
|
|
|
|
suggestion,
|
|
|
|
|
});
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
stability::Deprecated { sub, kind: "macro".to_owned(), path, note, since_kind },
|
|
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::UnusedDocComment(attr_span) => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::UnusedDocComment { span: attr_span });
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::PatternsInFnsWithoutBody { span: remove_span, ident, is_foreign } => {
|
|
|
|
|
let sub = lints::PatternsInFnsWithoutBodySub { ident, span: remove_span };
|
|
|
|
|
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
2023-12-30 16:13:23 +01:00
|
|
|
span,
|
2024-04-15 18:07:22 +00:00
|
|
|
if is_foreign {
|
|
|
|
|
lints::PatternsInFnsWithoutBody::Foreign { sub }
|
|
|
|
|
} else {
|
|
|
|
|
lints::PatternsInFnsWithoutBody::Bodiless { sub }
|
|
|
|
|
},
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::MissingAbi(label_span, default_abi) => {
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::MissingAbi { span: label_span, default_abi: default_abi.name() },
|
|
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::LegacyDeriveHelpers { span: label_span });
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::ProcMacroBackCompat { crate_name, fixed_version } => {
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::ProcMacroBackCompat { crate_name, fixed_version },
|
|
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::OrPatternsBackCompat(suggestion_span, suggestion) => {
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
2023-12-30 16:13:23 +01:00
|
|
|
span,
|
2024-04-15 18:07:22 +00:00
|
|
|
lints::OrPatternsBackCompat { span: suggestion_span, suggestion },
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::ReservedPrefix(label_span, prefix) => {
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::ReservedPrefix {
|
|
|
|
|
label: label_span,
|
|
|
|
|
suggestion: label_span.shrink_to_hi(),
|
|
|
|
|
prefix,
|
|
|
|
|
},
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name },
|
|
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::TrailingMacro(is_trailing, name) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::TrailingMacro { is_trailing, name });
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::BreakWithLabelAndLoop(sugg_span) => {
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::BreakWithLabelAndLoop {
|
|
|
|
|
sub: lints::BreakWithLabelAndLoopSub {
|
|
|
|
|
left: sugg_span.shrink_to_lo(),
|
|
|
|
|
right: sugg_span.shrink_to_hi(),
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-03-16 23:33:54 +01:00
|
|
|
BuiltinLintDiag::UnexpectedCfgName(name, value) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, check_cfg::unexpected_cfg_name(sess, name, value));
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-03-16 23:33:54 +01:00
|
|
|
BuiltinLintDiag::UnexpectedCfgValue(name, value) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, check_cfg::unexpected_cfg_value(sess, name, value));
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::DeprecatedWhereclauseLocation(left_sp, sugg) => {
|
|
|
|
|
let suggestion = match sugg {
|
|
|
|
|
Some((right_sp, sugg)) => lints::DeprecatedWhereClauseLocationSugg::MoveToEnd {
|
|
|
|
|
left: left_sp,
|
|
|
|
|
right: right_sp,
|
|
|
|
|
sugg,
|
|
|
|
|
},
|
|
|
|
|
None => lints::DeprecatedWhereClauseLocationSugg::RemoveWhere { span: left_sp },
|
2024-02-20 04:41:01 +01:00
|
|
|
};
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::DeprecatedWhereClauseLocation { suggestion });
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::SingleUseLifetime {
|
2023-12-30 16:13:23 +01:00
|
|
|
param_span,
|
|
|
|
|
use_span: Some((use_span, elide)),
|
|
|
|
|
deletion_span,
|
2024-04-15 18:07:22 +00:00
|
|
|
ident,
|
2023-12-30 16:13:23 +01:00
|
|
|
} => {
|
|
|
|
|
debug!(?param_span, ?use_span, ?deletion_span);
|
2024-04-15 18:07:22 +00:00
|
|
|
let suggestion = if let Some(deletion_span) = deletion_span {
|
2023-12-30 16:13:23 +01:00
|
|
|
let (use_span, replace_lt) = if elide {
|
2024-04-07 19:38:05 -04:00
|
|
|
let use_span = sess.source_map().span_extend_while_whitespace(use_span);
|
2023-12-30 16:13:23 +01:00
|
|
|
(use_span, String::new())
|
|
|
|
|
} else {
|
|
|
|
|
(use_span, "'_".to_owned())
|
|
|
|
|
};
|
|
|
|
|
debug!(?deletion_span, ?use_span);
|
|
|
|
|
|
|
|
|
|
// issue 107998 for the case such as a wrong function pointer type
|
|
|
|
|
// `deletion_span` is empty and there is no need to report lifetime uses here
|
2024-04-15 18:07:22 +00:00
|
|
|
let deletion_span =
|
|
|
|
|
if deletion_span.is_empty() { None } else { Some(deletion_span) };
|
|
|
|
|
Some(lints::SingleUseLifetimeSugg { deletion_span, use_span, replace_lt })
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::SingleUseLifetime { suggestion, param_span, use_span, ident },
|
|
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::SingleUseLifetime { use_span: None, deletion_span, ident, .. } => {
|
2023-12-30 16:13:23 +01:00
|
|
|
debug!(?deletion_span);
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::UnusedLifetime { deletion_span, ident });
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::NamedArgumentUsedPositionally {
|
2023-12-30 16:13:23 +01:00
|
|
|
position_sp_to_replace,
|
|
|
|
|
position_sp_for_msg,
|
|
|
|
|
named_arg_sp,
|
|
|
|
|
named_arg_name,
|
|
|
|
|
is_formatting_arg,
|
|
|
|
|
} => {
|
2024-04-15 18:07:22 +00:00
|
|
|
let (suggestion, name) = if let Some(positional_arg_to_replace) = position_sp_to_replace
|
|
|
|
|
{
|
|
|
|
|
let mut name = named_arg_name.clone();
|
|
|
|
|
if is_formatting_arg {
|
|
|
|
|
name.push('$')
|
|
|
|
|
};
|
2023-12-30 16:13:23 +01:00
|
|
|
let span_to_replace = if let Ok(positional_arg_content) =
|
|
|
|
|
sess.source_map().span_to_snippet(positional_arg_to_replace)
|
|
|
|
|
&& positional_arg_content.starts_with(':')
|
|
|
|
|
{
|
|
|
|
|
positional_arg_to_replace.shrink_to_lo()
|
|
|
|
|
} else {
|
|
|
|
|
positional_arg_to_replace
|
|
|
|
|
};
|
2024-04-15 18:07:22 +00:00
|
|
|
(Some(span_to_replace), name)
|
|
|
|
|
} else {
|
|
|
|
|
(None, String::new())
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::NamedArgumentUsedPositionally {
|
|
|
|
|
named_arg_sp,
|
|
|
|
|
position_label_sp: position_sp_for_msg,
|
|
|
|
|
suggestion,
|
2023-12-30 16:13:23 +01:00
|
|
|
name,
|
2024-04-15 18:07:22 +00:00
|
|
|
named_arg_name,
|
|
|
|
|
},
|
|
|
|
|
)
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::ByteSliceInPackedStructWithDerive { ty } => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::ByteSliceInPackedStructWithDerive { ty })
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::UnusedExternCrate { removal_span } => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::UnusedExternCrate { removal_span })
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span } => {
|
2023-12-30 16:13:23 +01:00
|
|
|
let suggestion_span = vis_span.between(ident_span);
|
2024-04-15 18:07:22 +00:00
|
|
|
let code = if vis_span.is_empty() { "use " } else { " use " };
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::ExternCrateNotIdiomatic { span: suggestion_span, code },
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::AmbiguousGlobImports { diag: ambiguity } => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::AmbiguousGlobImports { ambiguity });
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::AmbiguousGlobReexports {
|
2023-12-30 16:13:23 +01:00
|
|
|
name,
|
|
|
|
|
namespace,
|
|
|
|
|
first_reexport_span,
|
|
|
|
|
duplicate_reexport_span,
|
|
|
|
|
} => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::AmbiguousGlobReexports {
|
|
|
|
|
first_reexport: first_reexport_span,
|
|
|
|
|
duplicate_reexport: duplicate_reexport_span,
|
|
|
|
|
name,
|
|
|
|
|
namespace,
|
|
|
|
|
},
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::HiddenGlobReexports {
|
2023-12-30 16:13:23 +01:00
|
|
|
name,
|
|
|
|
|
namespace,
|
|
|
|
|
glob_reexport_span,
|
|
|
|
|
private_item_span,
|
|
|
|
|
} => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::HiddenGlobReexports {
|
|
|
|
|
glob_reexport: glob_reexport_span,
|
|
|
|
|
private_item: private_item_span,
|
|
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
namespace,
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-02-29 16:40:44 +11:00
|
|
|
BuiltinLintDiag::UnusedQualifications { removal_span } => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::UnusedQualifications { removal_span });
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::AssociatedConstElidedLifetime { elided, span: lt_span } => {
|
|
|
|
|
let lt_span = if elided { lt_span.shrink_to_hi() } else { lt_span };
|
|
|
|
|
let code = if elided { "'static " } else { "'static" };
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::AssociatedConstElidedLifetime { span: lt_span, code, elided },
|
2023-12-30 16:13:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::RedundantImportVisibility { max_vis, span: vis_span, import_vis } => {
|
|
|
|
|
ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::RedundantImportVisibility { span: vis_span, help: (), max_vis, import_vis },
|
2024-02-23 10:20:45 +11:00
|
|
|
);
|
2023-12-30 16:13:23 +01:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::UnknownDiagnosticAttribute { span: typo_span, typo_name } => {
|
|
|
|
|
let typo = typo_name.map(|typo_name| lints::UnknownDiagnosticAttributeTypoSugg {
|
|
|
|
|
span: typo_span,
|
|
|
|
|
typo_name,
|
|
|
|
|
});
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::UnknownDiagnosticAttribute { typo });
|
2024-04-14 17:59:54 +00:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::MacroUseDeprecated => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::MacroUseDeprecated)
|
2024-04-14 17:59:54 +00:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::UnusedMacroUse => ctx.emit_span_lint(lint, span, lints::UnusedMacroUse),
|
|
|
|
|
BuiltinLintDiag::PrivateExternCrateReexport(ident) => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::PrivateExternCrateReexport { ident })
|
2024-04-14 17:59:54 +00:00
|
|
|
}
|
2024-04-15 18:07:22 +00:00
|
|
|
BuiltinLintDiag::UnusedLabel => ctx.emit_span_lint(lint, span, lints::UnusedLabel),
|
|
|
|
|
BuiltinLintDiag::MacroIsPrivate(ident) => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::MacroIsPrivate { ident })
|
2024-04-14 17:59:54 +00:00
|
|
|
}
|
2024-04-14 20:11:14 +00:00
|
|
|
BuiltinLintDiag::UnusedMacroDefinition(name) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::UnusedMacroDefinition { name })
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::MacroRuleNeverUsed(n, name) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::MacroRuleNeverUsed { n: n + 1, name })
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::UnstableFeature(msg) => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::UnstableFeature { msg })
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::AvoidUsingIntelSyntax => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::AvoidIntelSyntax)
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::AvoidUsingAttSyntax => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::AvoidAttSyntax)
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::IncompleteInclude => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::IncompleteInclude)
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::UnnameableTestItems => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::UnnameableTestItems)
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::DuplicateMacroAttribute => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::DuplicateMacroAttribute)
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::CfgAttrNoAttributes => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::CfgAttrNoAttributes)
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::CrateTypeInCfgAttr => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::CrateTypeInCfgAttr)
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::CrateNameInCfgAttr => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::CrateNameInCfgAttr)
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::MissingFragmentSpecifier => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::MissingFragmentSpecifier)
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::MetaVariableStillRepeating(name) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::MetaVariableStillRepeating { name })
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::MetaVariableWrongOperator => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::MetaVariableWrongOperator)
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::DuplicateMatcherBinding => {
|
|
|
|
|
ctx.emit_span_lint(lint, span, lints::DuplicateMatcherBinding)
|
2024-04-14 20:11:14 +00:00
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::UnknownMacroVariable(name) => {
|
2024-04-15 18:07:22 +00:00
|
|
|
ctx.emit_span_lint(lint, span, lints::UnknownMacroVariable { name })
|
|
|
|
|
}
|
|
|
|
|
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::UnusedCrateDependency { extern_crate, local_crate },
|
|
|
|
|
),
|
|
|
|
|
BuiltinLintDiag::WasmCAbi => ctx.emit_span_lint(lint, span, lints::WasmCAbi),
|
|
|
|
|
BuiltinLintDiag::IllFormedAttributeInput { suggestions } => ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
lints::IllFormedAttributeInput {
|
|
|
|
|
num_suggestions: suggestions.len(),
|
|
|
|
|
suggestions: DiagArgValue::StrListSepByAnd(
|
|
|
|
|
suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
BuiltinLintDiag::InnerAttributeUnstable { is_macro } => ctx.emit_span_lint(
|
|
|
|
|
lint,
|
|
|
|
|
span,
|
|
|
|
|
if is_macro {
|
|
|
|
|
lints::InnerAttributeUnstable::InnerMacroAttribute
|
|
|
|
|
} else {
|
|
|
|
|
lints::InnerAttributeUnstable::CustomInnerAttribute
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-04-14 17:59:54 +00:00
|
|
|
}
|
|
|
|
|
}
|