|
3 | 3 |
|
4 | 4 | use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
|
5 | 5 | use rustc_errors::{
|
6 |
| - elided_lifetime_in_path_suggestion, pluralize, Diag, DiagMessage, LintDiagnostic, |
| 6 | + elided_lifetime_in_path_suggestion, pluralize, Diag, DiagMessage, LintDiagnostic, MultiSpan, |
7 | 7 | };
|
8 | 8 | use rustc_errors::{Applicability, SuggestionStyle};
|
9 | 9 | use rustc_middle::middle::stability;
|
10 |
| -use rustc_session::lint::BuiltinLintDiag; |
| 10 | +use rustc_session::lint::{BuiltinLintDiag, Lint}; |
11 | 11 | use rustc_session::Session;
|
12 | 12 | use rustc_span::BytePos;
|
13 | 13 |
|
14 | 14 | use std::fmt::Write;
|
15 | 15 |
|
16 |
| -use crate::fluent_generated as fluent; |
| 16 | +use crate::{fluent_generated as fluent, LintContext}; |
17 | 17 |
|
18 | 18 | mod check_cfg;
|
19 | 19 |
|
20 | 20 | #[cfg(test)]
|
21 | 21 | mod tests;
|
22 | 22 |
|
23 |
| -pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) { |
| 23 | +fn buffered_decorate(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) { |
24 | 24 | match diagnostic {
|
25 | 25 | BuiltinLintDiag::UnicodeTextFlow(span, content) => {
|
26 | 26 | let spans: Vec<_> = content
|
@@ -403,7 +403,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
|
403 | 403 | }
|
404 | 404 | }
|
405 | 405 |
|
406 |
| -pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage { |
| 406 | +fn buffered_message(diagnostic: &BuiltinLintDiag) -> DiagMessage { |
407 | 407 | match diagnostic {
|
408 | 408 | BuiltinLintDiag::AbsPathWithModule(_) => fluent::lint_abs_path_with_module,
|
409 | 409 | BuiltinLintDiag::ProcMacroDeriveResolutionFallback { ns, ident, .. } => {
|
@@ -561,6 +561,80 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
|
561 | 561 | }
|
562 | 562 | }
|
563 | 563 |
|
| 564 | +pub(super) fn emit_buffered_lint<C: LintContext + ?Sized>( |
| 565 | + ctx: &C, |
| 566 | + lint: &'static Lint, |
| 567 | + span: MultiSpan, |
| 568 | + diagnostic: BuiltinLintDiag, |
| 569 | +) { |
| 570 | + match diagnostic { |
| 571 | + BuiltinLintDiag::AbsPathWithModule(_) |
| 572 | + | BuiltinLintDiag::ProcMacroDeriveResolutionFallback { .. } |
| 573 | + | BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(_) |
| 574 | + | BuiltinLintDiag::ElidedLifetimesInPaths(_, _, _, _) |
| 575 | + | BuiltinLintDiag::UnknownCrateTypes { .. } |
| 576 | + | BuiltinLintDiag::UnusedImports { .. } |
| 577 | + | BuiltinLintDiag::RedundantImport(_, _) |
| 578 | + | BuiltinLintDiag::DeprecatedMacro { .. } |
| 579 | + | BuiltinLintDiag::MissingAbi(_, _) |
| 580 | + | BuiltinLintDiag::UnusedDocComment(_) |
| 581 | + | BuiltinLintDiag::UnusedBuiltinAttribute { .. } |
| 582 | + | BuiltinLintDiag::PatternsInFnsWithoutBody { .. } |
| 583 | + | BuiltinLintDiag::LegacyDeriveHelpers(_) |
| 584 | + | BuiltinLintDiag::ProcMacroBackCompat(_) |
| 585 | + | BuiltinLintDiag::OrPatternsBackCompat(_, _) |
| 586 | + | BuiltinLintDiag::ReservedPrefix(_, _) |
| 587 | + | BuiltinLintDiag::TrailingMacro(_, _) |
| 588 | + | BuiltinLintDiag::BreakWithLabelAndLoop(_) |
| 589 | + | BuiltinLintDiag::UnicodeTextFlow(_, _) |
| 590 | + | BuiltinLintDiag::UnexpectedCfgName(_, _) |
| 591 | + | BuiltinLintDiag::UnexpectedCfgValue(_, _) |
| 592 | + | BuiltinLintDiag::DeprecatedWhereclauseLocation(_) |
| 593 | + | BuiltinLintDiag::SingleUseLifetime { .. } |
| 594 | + | BuiltinLintDiag::NamedArgumentUsedPositionally { .. } |
| 595 | + | BuiltinLintDiag::ByteSliceInPackedStructWithDerive { .. } |
| 596 | + | BuiltinLintDiag::UnusedExternCrate { .. } |
| 597 | + | BuiltinLintDiag::ExternCrateNotIdiomatic { .. } |
| 598 | + | BuiltinLintDiag::AmbiguousGlobImports { .. } |
| 599 | + | BuiltinLintDiag::AmbiguousGlobReexports { .. } |
| 600 | + | BuiltinLintDiag::HiddenGlobReexports { .. } |
| 601 | + | BuiltinLintDiag::UnusedQualifications { .. } |
| 602 | + | BuiltinLintDiag::AssociatedConstElidedLifetime { .. } |
| 603 | + | BuiltinLintDiag::RedundantImportVisibility { .. } |
| 604 | + | BuiltinLintDiag::MacroUseDeprecated |
| 605 | + | BuiltinLintDiag::UnusedMacroUse |
| 606 | + | BuiltinLintDiag::PrivateExternCrateReexport(_) |
| 607 | + | BuiltinLintDiag::UnusedLabel |
| 608 | + | BuiltinLintDiag::MacroIsPrivate(_) |
| 609 | + | BuiltinLintDiag::UnusedMacroDefinition(_) |
| 610 | + | BuiltinLintDiag::MacroRuleNeverUsed(_, _) |
| 611 | + | BuiltinLintDiag::UnstableFeature(_) |
| 612 | + | BuiltinLintDiag::AvoidUsingIntelSyntax |
| 613 | + | BuiltinLintDiag::AvoidUsingAttSyntax |
| 614 | + | BuiltinLintDiag::IncompleteInclude |
| 615 | + | BuiltinLintDiag::UnnameableTestItems |
| 616 | + | BuiltinLintDiag::DuplicateMacroAttribute |
| 617 | + | BuiltinLintDiag::CfgAttrNoAttributes |
| 618 | + | BuiltinLintDiag::CrateTypeInCfgAttr |
| 619 | + | BuiltinLintDiag::CrateNameInCfgAttr |
| 620 | + | BuiltinLintDiag::MissingFragmentSpecifier |
| 621 | + | BuiltinLintDiag::MetaVariableStillRepeating(_) |
| 622 | + | BuiltinLintDiag::MetaVariableWrongOperator |
| 623 | + | BuiltinLintDiag::DuplicateMatcherBinding |
| 624 | + | BuiltinLintDiag::UnknownMacroVariable(_) |
| 625 | + | BuiltinLintDiag::UnusedExternCrate2 { .. } |
| 626 | + | BuiltinLintDiag::WasmCAbi |
| 627 | + | BuiltinLintDiag::IllFormedAttributeInput { .. } |
| 628 | + | BuiltinLintDiag::InnerAttributeUnstable { .. } |
| 629 | + | BuiltinLintDiag::UnknownDiagnosticAttribute => { |
| 630 | + ctx.span_lint(lint, span, buffered_message(&diagnostic), |db| { |
| 631 | + // Now, set up surrounding context. |
| 632 | + buffered_decorate(ctx.sess(), diagnostic, db); |
| 633 | + }) |
| 634 | + } |
| 635 | + } |
| 636 | +} |
| 637 | + |
564 | 638 | /// Convert the given number into the corresponding ordinal
|
565 | 639 | pub(crate) fn ordinalize(v: usize) -> String {
|
566 | 640 | let suffix = match ((11..=13).contains(&(v % 100)), v % 10) {
|
|
0 commit comments