Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_abi::ExternAbi;
use rustc_ast::ParamKindOrd;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};

#[derive(Diagnostic)]
Expand Down Expand Up @@ -671,7 +671,7 @@ pub(crate) struct MissingUnsafeOnExtern {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("extern blocks should be unsafe")]
pub(crate) struct MissingUnsafeOnExternLint {
#[suggestion(
Expand Down Expand Up @@ -1027,7 +1027,7 @@ pub(crate) struct MissingAbi {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("`extern` declarations without an explicit ABI are deprecated")]
pub(crate) struct MissingAbiSugg {
#[suggestion(
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ use rustc_errors::{
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
Subdiagnostic, msg,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("avoid using `.intel_syntax`, Intel syntax is the default")]
pub(crate) struct AvoidIntelSyntax;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("avoid using `.att_syntax`, prefer using `options(att_syntax)` instead")]
pub(crate) struct AvoidAttSyntax;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("include macro expected single expression in source")]
pub(crate) struct IncompleteInclude;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("cannot test inner items")]
pub(crate) struct UnnameableTestItems;

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("duplicated attribute")]
pub(crate) struct DuplicateMacroAttribute;

Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_errors/src/decorate_diag.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/// This module provides types and traits for buffering lints until later in compilation.
use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::DynSend;
use rustc_error_messages::MultiSpan;
use rustc_lint_defs::{BuiltinLintDiag, Lint, LintId};

use crate::{DynSend, LintDiagnostic, LintDiagnosticBox};
use crate::{Diag, DiagCtxtHandle, Diagnostic, Level};

/// We can't implement `LintDiagnostic` for `BuiltinLintDiag`, because decorating some of its
/// variants requires types we don't have yet. So, handle that case separately.
pub enum DecorateDiagCompat {
Dynamic(Box<dyn for<'a> LintDiagnosticBox<'a, ()> + DynSend + 'static>),
Dynamic(Box<dyn for<'a> FnOnce(DiagCtxtHandle<'a>, Level) -> Diag<'a, ()> + DynSend + 'static>),
Builtin(BuiltinLintDiag),
}

Expand All @@ -19,12 +20,10 @@ impl std::fmt::Debug for DecorateDiagCompat {
}
}

impl !LintDiagnostic<'_, ()> for BuiltinLintDiag {}

impl<D: for<'a> LintDiagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
impl<D: for<'a> Diagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
#[inline]
fn from(d: D) -> Self {
Self::Dynamic(Box::new(d))
Self::Dynamic(Box::new(|dcx, level| d.into_diag(dcx, level)))
}
}

Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::panic;
use std::path::PathBuf;
use std::thread::panicking;

use rustc_data_structures::sync::DynSend;
use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg};
use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_macros::{Decodable, Encodable};
Expand Down Expand Up @@ -118,6 +119,14 @@ where
}
}

impl<'a> Diagnostic<'a, ()>
for Box<dyn for<'b> FnOnce(DiagCtxtHandle<'b>, Level) -> Diag<'b, ()> + DynSend + 'static>
{
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
self(dcx, level)
}
}

/// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
#[rustc_diagnostic_item = "Subdiagnostic"]
Expand All @@ -137,16 +146,6 @@ pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
}

pub trait LintDiagnosticBox<'a, G: EmissionGuarantee> {
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>);
}

impl<'a, G: EmissionGuarantee, D: LintDiagnostic<'a, G>> LintDiagnosticBox<'a, G> for D {
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>) {
self.decorate_lint(diag);
}
}

#[derive(Clone, Debug, Encodable, Decodable)]
pub(crate) struct DiagLocation {
file: Cow<'static, str>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use codes::*;
pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
pub use diagnostic::{
BugAbort, Diag, DiagInner, DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort,
LintDiagnostic, LintDiagnosticBox, StringPart, Subdiag, Subdiagnostic,
LintDiagnostic, StringPart, Subdiag, Subdiagnostic,
};
pub use diagnostic_impls::{
DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter,
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::borrow::Cow;
use rustc_ast::ast;
use rustc_errors::codes::*;
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("`#[cfg_attr]` does not expand to any attributes")]
pub(crate) struct CfgAttrNoAttributes;

Expand Down Expand Up @@ -94,15 +94,15 @@ pub(crate) struct MacroVarStillRepeating {
pub ident: MacroRulesNormalizedIdent,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("variable `{$ident}` is still repeating at this depth")]
pub(crate) struct MetaVarStillRepeatingLint {
#[label("expected repetition")]
pub label: Span,
pub ident: MacroRulesNormalizedIdent,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("meta-variable repeats with different Kleene operator")]
pub(crate) struct MetaVariableWrongOperator {
#[label("expected repetition")]
Expand All @@ -119,7 +119,7 @@ pub(crate) struct MetaVarsDifSeqMatchers {
pub msg: String,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unknown macro variable `{$name}`")]
pub(crate) struct UnknownMacroVariable {
pub name: MacroRulesNormalizedIdent,
Expand Down Expand Up @@ -391,7 +391,7 @@ pub(crate) struct DuplicateMatcherBinding {
pub prev: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("duplicate matcher binding")]
pub(crate) struct DuplicateMatcherBindingLint {
#[label("duplicate binding")]
Expand Down Expand Up @@ -569,7 +569,7 @@ pub(crate) struct MacroArgsBadDelimSugg {
pub close: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unused doc comment")]
#[help(
"to document an item produced by a macro, the macro must produce the documentation as part of its expansion"
Expand All @@ -579,7 +579,7 @@ pub(crate) struct MacroCallUnusedDocComment {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag(
"the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro"
)]
Expand All @@ -593,7 +593,7 @@ pub(crate) struct OrPatternsBackCompat {
pub suggestion: String,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("trailing semicolon in macro used in expression position")]
pub(crate) struct TrailingMacro {
#[note("macro invocations at the end of a block are treated as expressions")]
Expand All @@ -604,7 +604,7 @@ pub(crate) struct TrailingMacro {
pub name: Ident,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unused attribute `{$attr_name}`")]
pub(crate) struct UnusedBuiltinAttribute {
#[note(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
);
}
DecorateDiagCompat::Dynamic(d) => {
self.context
.opt_span_lint(lint_id.lint, span, |diag| d.decorate_lint_box(diag));
self.context.opt_span_diag_lint(lint_id.lint, span, d);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg,
Level, Subdiagnostic, SuggestionStyle, msg,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
use rustc_span::{Ident, Span, Symbol};
Expand Down Expand Up @@ -4305,7 +4305,7 @@ pub(crate) struct ExpectedRegisterClassOrExplicitRegister {
pub(crate) span: Span,
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("unicode codepoint changing visible direction of text present in {$label}")]
#[note(
"these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen"
Expand Down Expand Up @@ -4388,7 +4388,7 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
}
}

#[derive(LintDiagnostic)]
#[derive(Diagnostic)]
#[diag("missing pattern for `...` argument")]
pub(crate) struct VarargsWithoutPattern {
#[suggestion(
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

for ambiguity_error in &self.ambiguity_errors {
let diag = self.ambiguity_diagnostic(ambiguity_error);
let mut diag = self.ambiguity_diagnostic(ambiguity_error);

if let Some(ambiguity_warning) = ambiguity_error.warning {
let node_id = match ambiguity_error.b1.0.kind {
Expand All @@ -152,6 +152,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

self.lint_buffer.buffer_lint(lint, node_id, diag.ident.span, diag);
} else {
diag.is_error = true;
self.dcx().emit_err(diag);
}
}
Expand Down Expand Up @@ -2093,6 +2094,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
b1_help_msgs,
b2_note,
b2_help_msgs,
is_error: false,
}
}

Expand Down
Loading
Loading