|
2 | 2 | #![allow(rustc::untranslatable_diagnostic)]
|
3 | 3 |
|
4 | 4 | use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
|
5 |
| -use rustc_errors::{add_elided_lifetime_in_path_suggestion, pluralize, Diag, DiagMessage}; |
| 5 | +use rustc_errors::{ |
| 6 | + add_elided_lifetime_in_path_suggestion, pluralize, Diag, DiagMessage, MultiSpan, |
| 7 | +}; |
6 | 8 | use rustc_errors::{Applicability, SuggestionStyle};
|
7 | 9 | use rustc_middle::middle::stability;
|
8 |
| -use rustc_session::lint::BuiltinLintDiag; |
| 10 | +use rustc_session::lint::{BuiltinLintDiag, Lint}; |
9 | 11 | use rustc_session::Session;
|
10 | 12 | use rustc_span::BytePos;
|
11 | 13 |
|
12 | 14 | use std::fmt::Write;
|
13 | 15 |
|
14 |
| -use crate::fluent_generated as fluent; |
| 16 | +use crate::{fluent_generated as fluent, LintContext}; |
15 | 17 |
|
16 | 18 | mod check_cfg;
|
17 | 19 |
|
18 | 20 | #[cfg(test)]
|
19 | 21 | mod tests;
|
20 | 22 |
|
21 |
| -pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) { |
| 23 | +fn buffered_decorate(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) { |
22 | 24 | match diagnostic {
|
23 | 25 | BuiltinLintDiag::UnicodeTextFlow(span, content) => {
|
24 | 26 | let spans: Vec<_> = content
|
@@ -380,7 +382,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
|
380 | 382 | }
|
381 | 383 | }
|
382 | 384 |
|
383 |
| -pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage { |
| 385 | +fn buffered_message(diagnostic: &BuiltinLintDiag) -> DiagMessage { |
384 | 386 | match diagnostic {
|
385 | 387 | BuiltinLintDiag::AbsPathWithModule(_) => fluent::lint_abs_path_with_module,
|
386 | 388 | BuiltinLintDiag::ProcMacroDeriveResolutionFallback { ns, ident, .. } => {
|
@@ -537,6 +539,81 @@ pub(super) fn builtin_message(diagnostic: &BuiltinLintDiag) -> DiagMessage {
|
537 | 539 | }
|
538 | 540 | }
|
539 | 541 |
|
| 542 | +pub(super) fn emit_buffered_lint<C: LintContext + ?Sized>( |
| 543 | + ctx: &C, |
| 544 | + lint: &'static Lint, |
| 545 | + span: Option<impl Into<MultiSpan>>, |
| 546 | + diagnostic: BuiltinLintDiag, |
| 547 | +) { |
| 548 | + match diagnostic { |
| 549 | + BuiltinLintDiag::AbsPathWithModule(_) |
| 550 | + | BuiltinLintDiag::ProcMacroDeriveResolutionFallback { .. } |
| 551 | + | BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(_) |
| 552 | + | BuiltinLintDiag::ElidedLifetimesInPaths(_, _, _, _) |
| 553 | + | BuiltinLintDiag::UnknownCrateTypes(_, _, _) |
| 554 | + | BuiltinLintDiag::UnusedImports { .. } |
| 555 | + | BuiltinLintDiag::RedundantImport(_, _) |
| 556 | + | BuiltinLintDiag::DeprecatedMacro { .. } |
| 557 | + | BuiltinLintDiag::MissingAbi(_, _) |
| 558 | + | BuiltinLintDiag::UnusedDocComment(_) |
| 559 | + | BuiltinLintDiag::UnusedBuiltinAttribute { .. } |
| 560 | + | BuiltinLintDiag::PatternsInFnsWithoutBody { .. } |
| 561 | + | BuiltinLintDiag::LegacyDeriveHelpers(_) |
| 562 | + | BuiltinLintDiag::ProcMacroBackCompat(_) |
| 563 | + | BuiltinLintDiag::OrPatternsBackCompat(_, _) |
| 564 | + | BuiltinLintDiag::ReservedPrefix(_, _) |
| 565 | + | BuiltinLintDiag::TrailingMacro(_, _) |
| 566 | + | BuiltinLintDiag::BreakWithLabelAndLoop(_) |
| 567 | + | BuiltinLintDiag::UnicodeTextFlow(_, _) |
| 568 | + | BuiltinLintDiag::UnexpectedCfgName(_, _) |
| 569 | + | BuiltinLintDiag::UnexpectedCfgValue(_, _) |
| 570 | + | BuiltinLintDiag::DeprecatedWhereclauseLocation(_) |
| 571 | + | BuiltinLintDiag::SingleUseLifetime { .. } |
| 572 | + | BuiltinLintDiag::NamedArgumentUsedPositionally { .. } |
| 573 | + | BuiltinLintDiag::ByteSliceInPackedStructWithDerive { .. } |
| 574 | + | BuiltinLintDiag::UnusedExternCrate { .. } |
| 575 | + | BuiltinLintDiag::ExternCrateNotIdiomatic { .. } |
| 576 | + | BuiltinLintDiag::AmbiguousGlobImports { .. } |
| 577 | + | BuiltinLintDiag::AmbiguousGlobReexports { .. } |
| 578 | + | BuiltinLintDiag::HiddenGlobReexports { .. } |
| 579 | + | BuiltinLintDiag::UnusedQualifications { .. } |
| 580 | + | BuiltinLintDiag::AssociatedConstElidedLifetime { .. } |
| 581 | + | BuiltinLintDiag::RedundantImportVisibility { .. } |
| 582 | + | BuiltinLintDiag::InvalidCrateTypeValue |
| 583 | + | BuiltinLintDiag::MacroUseDeprecated |
| 584 | + | BuiltinLintDiag::UnusedMacroUse |
| 585 | + | BuiltinLintDiag::PrivateExternCrateReexport(_) |
| 586 | + | BuiltinLintDiag::UnusedLabel |
| 587 | + | BuiltinLintDiag::MacroIsPrivate(_) |
| 588 | + | BuiltinLintDiag::UnusedMacroDefinition(_) |
| 589 | + | BuiltinLintDiag::MacroRuleNeverUsed(_, _) |
| 590 | + | BuiltinLintDiag::UnstableFeature(_) |
| 591 | + | BuiltinLintDiag::AvoidUsingIntelSyntax |
| 592 | + | BuiltinLintDiag::AvoidUsingAttSyntax |
| 593 | + | BuiltinLintDiag::IncompleteInclude |
| 594 | + | BuiltinLintDiag::UnnameableTestItems |
| 595 | + | BuiltinLintDiag::DuplicateMacroAttribute |
| 596 | + | BuiltinLintDiag::CfgAttrNoAttributes |
| 597 | + | BuiltinLintDiag::CrateTypeInCfgAttr |
| 598 | + | BuiltinLintDiag::CrateNameInCfgAttr |
| 599 | + | BuiltinLintDiag::MissingFragmentSpecifier |
| 600 | + | BuiltinLintDiag::MetaVariableStillRepeating(_) |
| 601 | + | BuiltinLintDiag::MetaVariableWrongOperator |
| 602 | + | BuiltinLintDiag::DuplicateMatcherBinding |
| 603 | + | BuiltinLintDiag::UnknownMacroVariable(_) |
| 604 | + | BuiltinLintDiag::UnusedExternCrate2 { .. } |
| 605 | + | BuiltinLintDiag::WasmCAbi |
| 606 | + | BuiltinLintDiag::IllFormedAttributeInput { .. } |
| 607 | + | BuiltinLintDiag::InnerAttributeUnstable { .. } |
| 608 | + | BuiltinLintDiag::UnknownDiagnosticAttribute => { |
| 609 | + ctx.opt_span_lint(lint, span, buffered_message(&diagnostic), |db| { |
| 610 | + // Now, set up surrounding context. |
| 611 | + buffered_decorate(ctx.sess(), diagnostic, db); |
| 612 | + }) |
| 613 | + } |
| 614 | + } |
| 615 | +} |
| 616 | + |
540 | 617 | /// Convert the given number into the corresponding ordinal
|
541 | 618 | pub(crate) fn ordinalize(v: usize) -> String {
|
542 | 619 | let suffix = match ((11..=13).contains(&(v % 100)), v % 10) {
|
|
0 commit comments