Skip to content

Commit 7437730

Browse files
authored
Unrolled build for #153352
Rollup merge of #153352 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer Migration of `LintDiagnostic` - part 6 Part of #153099. r? @JonathanBrouwer
2 parents d956393 + 56d636a commit 7437730

52 files changed

Lines changed: 270 additions & 265 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_abi::ExternAbi;
44
use rustc_ast::ParamKindOrd;
55
use rustc_errors::codes::*;
66
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
7-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
7+
use rustc_macros::{Diagnostic, Subdiagnostic};
88
use rustc_span::{Ident, Span, Symbol};
99

1010
#[derive(Diagnostic)]
@@ -671,7 +671,7 @@ pub(crate) struct MissingUnsafeOnExtern {
671671
pub span: Span,
672672
}
673673

674-
#[derive(LintDiagnostic)]
674+
#[derive(Diagnostic)]
675675
#[diag("extern blocks should be unsafe")]
676676
pub(crate) struct MissingUnsafeOnExternLint {
677677
#[suggestion(
@@ -1027,7 +1027,7 @@ pub(crate) struct MissingAbi {
10271027
pub span: Span,
10281028
}
10291029

1030-
#[derive(LintDiagnostic)]
1030+
#[derive(Diagnostic)]
10311031
#[diag("`extern` declarations without an explicit ABI are deprecated")]
10321032
pub(crate) struct MissingAbiSugg {
10331033
#[suggestion(

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ use rustc_errors::{
33
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
44
Subdiagnostic, msg,
55
};
6-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
6+
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_span::{Ident, Span, Symbol};
88

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

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

17-
#[derive(LintDiagnostic)]
17+
#[derive(Diagnostic)]
1818
#[diag("include macro expected single expression in source")]
1919
pub(crate) struct IncompleteInclude;
2020

21-
#[derive(LintDiagnostic)]
21+
#[derive(Diagnostic)]
2222
#[diag("cannot test inner items")]
2323
pub(crate) struct UnnameableTestItems;
2424

25-
#[derive(LintDiagnostic)]
25+
#[derive(Diagnostic)]
2626
#[diag("duplicated attribute")]
2727
pub(crate) struct DuplicateMacroAttribute;
2828

compiler/rustc_errors/src/decorate_diag.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/// This module provides types and traits for buffering lints until later in compilation.
22
use rustc_ast::node_id::NodeId;
33
use rustc_data_structures::fx::FxIndexMap;
4+
use rustc_data_structures::sync::DynSend;
45
use rustc_error_messages::MultiSpan;
56
use rustc_lint_defs::{BuiltinLintDiag, Lint, LintId};
67

7-
use crate::{DynSend, LintDiagnostic, LintDiagnosticBox};
8+
use crate::{Diag, DiagCtxtHandle, Diagnostic, Level};
89

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

@@ -19,12 +20,10 @@ impl std::fmt::Debug for DecorateDiagCompat {
1920
}
2021
}
2122

22-
impl !LintDiagnostic<'_, ()> for BuiltinLintDiag {}
23-
24-
impl<D: for<'a> LintDiagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
23+
impl<D: for<'a> Diagnostic<'a, ()> + DynSend + 'static> From<D> for DecorateDiagCompat {
2524
#[inline]
2625
fn from(d: D) -> Self {
27-
Self::Dynamic(Box::new(d))
26+
Self::Dynamic(Box::new(|dcx, level| d.into_diag(dcx, level)))
2827
}
2928
}
3029

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::panic;
77
use std::path::PathBuf;
88
use std::thread::panicking;
99

10+
use rustc_data_structures::sync::DynSend;
1011
use rustc_error_messages::{DiagArgMap, DiagArgName, DiagArgValue, IntoDiagArg};
1112
use rustc_lint_defs::{Applicability, LintExpectationId};
1213
use rustc_macros::{Decodable, Encodable};
@@ -118,6 +119,14 @@ where
118119
}
119120
}
120121

122+
impl<'a> Diagnostic<'a, ()>
123+
for Box<dyn for<'b> FnOnce(DiagCtxtHandle<'b>, Level) -> Diag<'b, ()> + DynSend + 'static>
124+
{
125+
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
126+
self(dcx, level)
127+
}
128+
}
129+
121130
/// Trait implemented by error types. This should not be implemented manually. Instead, use
122131
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
123132
#[rustc_diagnostic_item = "Subdiagnostic"]
@@ -137,16 +146,6 @@ pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
137146
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
138147
}
139148

140-
pub trait LintDiagnosticBox<'a, G: EmissionGuarantee> {
141-
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>);
142-
}
143-
144-
impl<'a, G: EmissionGuarantee, D: LintDiagnostic<'a, G>> LintDiagnosticBox<'a, G> for D {
145-
fn decorate_lint_box<'b>(self: Box<Self>, diag: &'b mut Diag<'a, G>) {
146-
self.decorate_lint(diag);
147-
}
148-
}
149-
150149
#[derive(Clone, Debug, Encodable, Decodable)]
151150
pub(crate) struct DiagLocation {
152151
file: Cow<'static, str>,

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use codes::*;
4040
pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
4141
pub use diagnostic::{
4242
BugAbort, Diag, DiagInner, DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort,
43-
LintDiagnostic, LintDiagnosticBox, StringPart, Subdiag, Subdiagnostic,
43+
LintDiagnostic, StringPart, Subdiag, Subdiagnostic,
4444
};
4545
pub use diagnostic_impls::{
4646
DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter,

compiler/rustc_expand/src/errors.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::borrow::Cow;
33
use rustc_ast::ast;
44
use rustc_errors::codes::*;
55
use rustc_hir::limit::Limit;
6-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
6+
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};
88

9-
#[derive(LintDiagnostic)]
9+
#[derive(Diagnostic)]
1010
#[diag("`#[cfg_attr]` does not expand to any attributes")]
1111
pub(crate) struct CfgAttrNoAttributes;
1212

@@ -94,15 +94,15 @@ pub(crate) struct MacroVarStillRepeating {
9494
pub ident: MacroRulesNormalizedIdent,
9595
}
9696

97-
#[derive(LintDiagnostic)]
97+
#[derive(Diagnostic)]
9898
#[diag("variable `{$ident}` is still repeating at this depth")]
9999
pub(crate) struct MetaVarStillRepeatingLint {
100100
#[label("expected repetition")]
101101
pub label: Span,
102102
pub ident: MacroRulesNormalizedIdent,
103103
}
104104

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

122-
#[derive(LintDiagnostic)]
122+
#[derive(Diagnostic)]
123123
#[diag("unknown macro variable `{$name}`")]
124124
pub(crate) struct UnknownMacroVariable {
125125
pub name: MacroRulesNormalizedIdent,
@@ -391,7 +391,7 @@ pub(crate) struct DuplicateMatcherBinding {
391391
pub prev: Span,
392392
}
393393

394-
#[derive(LintDiagnostic)]
394+
#[derive(Diagnostic)]
395395
#[diag("duplicate matcher binding")]
396396
pub(crate) struct DuplicateMatcherBindingLint {
397397
#[label("duplicate binding")]
@@ -569,7 +569,7 @@ pub(crate) struct MacroArgsBadDelimSugg {
569569
pub close: Span,
570570
}
571571

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

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

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

607-
#[derive(LintDiagnostic)]
607+
#[derive(Diagnostic)]
608608
#[diag("unused attribute `{$attr_name}`")]
609609
pub(crate) struct UnusedBuiltinAttribute {
610610
#[note(

compiler/rustc_lint/src/early.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
5050
);
5151
}
5252
DecorateDiagCompat::Dynamic(d) => {
53-
self.context
54-
.opt_span_lint(lint_id.lint, span, |diag| d.decorate_lint_box(diag));
53+
self.context.opt_span_diag_lint(lint_id.lint, span, d);
5554
}
5655
}
5756
}

compiler/rustc_parse/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_errors::{
1111
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg,
1212
Level, Subdiagnostic, SuggestionStyle, msg,
1313
};
14-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
14+
use rustc_macros::{Diagnostic, Subdiagnostic};
1515
use rustc_session::errors::ExprParenthesesNeeded;
1616
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
1717
use rustc_span::{Ident, Span, Symbol};
@@ -4305,7 +4305,7 @@ pub(crate) struct ExpectedRegisterClassOrExplicitRegister {
43054305
pub(crate) span: Span,
43064306
}
43074307

4308-
#[derive(LintDiagnostic)]
4308+
#[derive(Diagnostic)]
43094309
#[diag("unicode codepoint changing visible direction of text present in {$label}")]
43104310
#[note(
43114311
"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"
@@ -4388,7 +4388,7 @@ impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
43884388
}
43894389
}
43904390

4391-
#[derive(LintDiagnostic)]
4391+
#[derive(Diagnostic)]
43924392
#[diag("missing pattern for `...` argument")]
43934393
pub(crate) struct VarargsWithoutPattern {
43944394
#[suggestion(

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
136136
}
137137

138138
for ambiguity_error in &self.ambiguity_errors {
139-
let diag = self.ambiguity_diagnostic(ambiguity_error);
139+
let mut diag = self.ambiguity_diagnostic(ambiguity_error);
140140

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

153153
self.lint_buffer.buffer_lint(lint, node_id, diag.ident.span, diag);
154154
} else {
155+
diag.is_error = true;
155156
self.dcx().emit_err(diag);
156157
}
157158
}
@@ -2093,6 +2094,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20932094
b1_help_msgs,
20942095
b2_note,
20952096
b2_help_msgs,
2097+
is_error: false,
20962098
}
20972099
}
20982100

0 commit comments

Comments
 (0)