Skip to content

Commit a532706

Browse files
Rollup merge of #154303 - GuillaumeGomez:migrate-diag2, r=JonathanBrouwer
Remove more `BuiltinLintDiag` variants - part 2 Part of #153099. r? @JonathanBrouwer
2 parents a77ea21 + 5d7f894 commit a532706

10 files changed

Lines changed: 192 additions & 269 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/cfg_select.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ use rustc_ast::token::Token;
22
use rustc_ast::tokenstream::TokenStream;
33
use rustc_ast::{AttrStyle, NodeId, token};
44
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_errors::Diagnostic;
56
use rustc_feature::{AttributeTemplate, Features};
67
use rustc_hir::attrs::CfgEntry;
78
use rustc_hir::{AttrPath, Target};
89
use rustc_parse::exp;
910
use rustc_parse::parser::{Parser, Recovery};
1011
use rustc_session::Session;
11-
use rustc_session::lint::BuiltinLintDiag;
1212
use rustc_session::lint::builtin::UNREACHABLE_CFG_SELECT_PREDICATES;
1313
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
1414

1515
use crate::parser::{AllowExprMetavar, MetaItemOrLitParser};
16-
use crate::{AttributeParser, ParsedDescription, ShouldEmit, parse_cfg_entry};
16+
use crate::{AttributeParser, ParsedDescription, ShouldEmit, errors, parse_cfg_entry};
1717

1818
#[derive(Clone)]
1919
pub enum CfgSelectPredicate {
@@ -153,11 +153,17 @@ fn lint_unreachable(
153153

154154
let branch_is_unreachable = |predicate: CfgSelectPredicate, wildcard_span| {
155155
let span = predicate.span();
156-
p.psess.buffer_lint(
156+
p.psess.dyn_buffer_lint(
157157
UNREACHABLE_CFG_SELECT_PREDICATES,
158158
span,
159159
lint_node_id,
160-
BuiltinLintDiag::UnreachableCfg { span, wildcard_span },
160+
move |dcx, level| match wildcard_span {
161+
Some(wildcard_span) => {
162+
errors::UnreachableCfgSelectPredicateWildcard { span, wildcard_span }
163+
.into_diag(dcx, level)
164+
}
165+
None => errors::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level),
166+
},
161167
);
162168
};
163169

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@ pub(crate) struct ItemFollowingInnerAttr {
2626
pub span: Span,
2727
}
2828

29+
#[derive(Diagnostic)]
30+
#[diag("unreachable configuration predicate")]
31+
pub(crate) struct UnreachableCfgSelectPredicate {
32+
#[label("this configuration predicate is never reached")]
33+
pub span: Span,
34+
}
35+
2936
#[derive(Diagnostic)]
3037
#[diag("most attributes are not supported in `where` clauses")]
3138
#[help("only `#[cfg]` and `#[cfg_attr]` are supported")]
3239
pub(crate) struct UnsupportedAttributesInWhere {
3340
#[primary_span]
3441
pub span: MultiSpan,
3542
}
43+
44+
#[derive(Diagnostic)]
45+
#[diag("unreachable configuration predicate")]
46+
pub(crate) struct UnreachableCfgSelectPredicateWildcard {
47+
#[label("this configuration predicate is never reached")]
48+
pub span: Span,
49+
50+
#[label("always matches")]
51+
pub wildcard_span: Span,
52+
}

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_errors::{
55
elided_lifetime_in_path_suggestion,
66
};
77
use rustc_hir::lints::{AttributeLintKind, FormatWarning};
8-
use rustc_middle::middle::stability;
98
use rustc_middle::ty::TyCtxt;
109
use rustc_session::Session;
1110
use rustc_session::lint::BuiltinLintDiag;
@@ -88,34 +87,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateBuiltinLint<'_, '_> {
8887
}
8988
.into_diag(dcx, level)
9089
}
91-
BuiltinLintDiag::RedundantImport(spans, ident) => {
92-
let subs = spans
93-
.into_iter()
94-
.map(|(span, is_imported)| match (span.is_dummy(), is_imported) {
95-
(false, true) => lints::RedundantImportSub::ImportedHere { span, ident },
96-
(false, false) => lints::RedundantImportSub::DefinedHere { span, ident },
97-
(true, true) => lints::RedundantImportSub::ImportedPrelude { span, ident },
98-
(true, false) => lints::RedundantImportSub::DefinedPrelude { span, ident },
99-
})
100-
.collect();
101-
lints::RedundantImport { subs, ident }.into_diag(dcx, level)
102-
}
103-
BuiltinLintDiag::DeprecatedMacro {
104-
suggestion,
105-
suggestion_span,
106-
note,
107-
path,
108-
since_kind,
109-
} => {
110-
let sub = suggestion.map(|suggestion| stability::DeprecationSuggestion {
111-
span: suggestion_span,
112-
kind: "macro".to_owned(),
113-
suggestion,
114-
});
115-
116-
stability::Deprecated { sub, kind: "macro".to_owned(), path, note, since_kind }
117-
.into_diag(dcx, level)
118-
}
11990
BuiltinLintDiag::SingleUseLifetime {
12091
param_span,
12192
use_span,
@@ -181,56 +152,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateBuiltinLint<'_, '_> {
181152
}
182153
.into_diag(dcx, level)
183154
}
184-
BuiltinLintDiag::AmbiguousGlobReexports {
185-
name,
186-
namespace,
187-
first_reexport_span,
188-
duplicate_reexport_span,
189-
} => lints::AmbiguousGlobReexports {
190-
first_reexport: first_reexport_span,
191-
duplicate_reexport: duplicate_reexport_span,
192-
name,
193-
namespace,
194-
}
195-
.into_diag(dcx, level),
196-
BuiltinLintDiag::HiddenGlobReexports {
197-
name,
198-
namespace,
199-
glob_reexport_span,
200-
private_item_span,
201-
} => lints::HiddenGlobReexports {
202-
glob_reexport: glob_reexport_span,
203-
private_item: private_item_span,
204-
205-
name,
206-
namespace,
207-
}
208-
.into_diag(dcx, level),
209-
BuiltinLintDiag::UnusedQualifications { removal_span } => {
210-
lints::UnusedQualifications { removal_span }.into_diag(dcx, level)
211-
}
212-
BuiltinLintDiag::AssociatedConstElidedLifetime {
213-
elided,
214-
span: lt_span,
215-
lifetimes_in_scope,
216-
} => {
217-
let lt_span = if elided { lt_span.shrink_to_hi() } else { lt_span };
218-
let code = if elided { "'static " } else { "'static" };
219-
lints::AssociatedConstElidedLifetime {
220-
span: lt_span,
221-
code,
222-
elided,
223-
lifetimes_in_scope,
224-
}
225-
.into_diag(dcx, level)
226-
}
227-
BuiltinLintDiag::UnreachableCfg { span, wildcard_span } => match wildcard_span {
228-
Some(wildcard_span) => {
229-
lints::UnreachableCfgSelectPredicateWildcard { span, wildcard_span }
230-
.into_diag(dcx, level)
231-
}
232-
None => lints::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level),
233-
},
234155

235156
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
236157
lints::UnusedCrateDependency { extern_crate, local_crate }.into_diag(dcx, level)

compiler/rustc_lint/src/lints.rs

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use rustc_errors::codes::*;
66
use rustc_errors::formatting::DiagMessageAddArg;
77
use rustc_errors::{
88
Applicability, Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
9-
ElidedLifetimeInPathSubdiag, EmissionGuarantee, Level, MultiSpan, Subdiagnostic,
10-
SuggestionStyle, msg,
9+
ElidedLifetimeInPathSubdiag, EmissionGuarantee, Level, Subdiagnostic, SuggestionStyle, msg,
1110
};
1211
use rustc_hir as hir;
1312
use rustc_hir::def_id::DefId;
@@ -3089,42 +3088,6 @@ pub(crate) enum UnusedImportsSugg {
30893088
},
30903089
}
30913090

3092-
#[derive(Diagnostic)]
3093-
#[diag("the item `{$ident}` is imported redundantly")]
3094-
pub(crate) struct RedundantImport {
3095-
#[subdiagnostic]
3096-
pub subs: Vec<RedundantImportSub>,
3097-
pub ident: Ident,
3098-
}
3099-
3100-
#[derive(Subdiagnostic)]
3101-
pub(crate) enum RedundantImportSub {
3102-
#[label("the item `{$ident}` is already imported here")]
3103-
ImportedHere {
3104-
#[primary_span]
3105-
span: Span,
3106-
ident: Ident,
3107-
},
3108-
#[label("the item `{$ident}` is already defined here")]
3109-
DefinedHere {
3110-
#[primary_span]
3111-
span: Span,
3112-
ident: Ident,
3113-
},
3114-
#[label("the item `{$ident}` is already imported by the extern prelude")]
3115-
ImportedPrelude {
3116-
#[primary_span]
3117-
span: Span,
3118-
ident: Ident,
3119-
},
3120-
#[label("the item `{$ident}` is already defined by the extern prelude")]
3121-
DefinedPrelude {
3122-
#[primary_span]
3123-
span: Span,
3124-
ident: Ident,
3125-
},
3126-
}
3127-
31283091
#[derive(Diagnostic)]
31293092
#[diag("lifetime parameter `{$ident}` only used once")]
31303093
pub(crate) struct SingleUseLifetime {
@@ -3168,66 +3131,6 @@ pub(crate) struct NamedArgumentUsedPositionally {
31683131
pub named_arg_name: String,
31693132
}
31703133

3171-
#[derive(Diagnostic)]
3172-
#[diag("ambiguous glob re-exports")]
3173-
pub(crate) struct AmbiguousGlobReexports {
3174-
#[label("the name `{$name}` in the {$namespace} namespace is first re-exported here")]
3175-
pub first_reexport: Span,
3176-
#[label("but the name `{$name}` in the {$namespace} namespace is also re-exported here")]
3177-
pub duplicate_reexport: Span,
3178-
3179-
pub name: String,
3180-
pub namespace: String,
3181-
}
3182-
3183-
#[derive(Diagnostic)]
3184-
#[diag("private item shadows public glob re-export")]
3185-
pub(crate) struct HiddenGlobReexports {
3186-
#[note(
3187-
"the name `{$name}` in the {$namespace} namespace is supposed to be publicly re-exported here"
3188-
)]
3189-
pub glob_reexport: Span,
3190-
#[note("but the private item here shadows it")]
3191-
pub private_item: Span,
3192-
3193-
pub name: String,
3194-
pub namespace: String,
3195-
}
3196-
3197-
#[derive(Diagnostic)]
3198-
#[diag("unnecessary qualification")]
3199-
pub(crate) struct UnusedQualifications {
3200-
#[suggestion(
3201-
"remove the unnecessary path segments",
3202-
style = "verbose",
3203-
code = "",
3204-
applicability = "machine-applicable"
3205-
)]
3206-
pub removal_span: Span,
3207-
}
3208-
3209-
#[derive(Diagnostic)]
3210-
#[diag(
3211-
"{$elided ->
3212-
[true] `&` without an explicit lifetime name cannot be used here
3213-
*[false] `'_` cannot be used here
3214-
}"
3215-
)]
3216-
pub(crate) struct AssociatedConstElidedLifetime {
3217-
#[suggestion(
3218-
"use the `'static` lifetime",
3219-
style = "verbose",
3220-
code = "{code}",
3221-
applicability = "machine-applicable"
3222-
)]
3223-
pub span: Span,
3224-
3225-
pub code: &'static str,
3226-
pub elided: bool,
3227-
#[note("cannot automatically infer `'static` because of other lifetimes in scope")]
3228-
pub lifetimes_in_scope: MultiSpan,
3229-
}
3230-
32313134
#[derive(Diagnostic)]
32323135
#[diag("creating a {$shared_label}reference to mutable static")]
32333136
pub(crate) struct RefOfMutStatic<'a> {
@@ -3709,23 +3612,6 @@ pub(crate) struct UnknownCrateTypesSuggestion {
37093612
pub snippet: Symbol,
37103613
}
37113614

3712-
#[derive(Diagnostic)]
3713-
#[diag("unreachable configuration predicate")]
3714-
pub(crate) struct UnreachableCfgSelectPredicate {
3715-
#[label("this configuration predicate is never reached")]
3716-
pub span: Span,
3717-
}
3718-
3719-
#[derive(Diagnostic)]
3720-
#[diag("unreachable configuration predicate")]
3721-
pub(crate) struct UnreachableCfgSelectPredicateWildcard {
3722-
#[label("this configuration predicate is never reached")]
3723-
pub span: Span,
3724-
3725-
#[label("always matches")]
3726-
pub wildcard_span: Span,
3727-
}
3728-
37293615
#[derive(Diagnostic)]
37303616
#[diag("positional format arguments are not allowed here")]
37313617
#[help(

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxIndexSet;
77
use rustc_data_structures::stable_hasher::{
88
HashStable, StableCompare, StableHasher, ToStableHashKey,
99
};
10-
use rustc_error_messages::{DiagArgValue, IntoDiagArg, MultiSpan};
10+
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
1111
use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
1212
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1313
use rustc_span::def_id::DefPathHash;
@@ -665,14 +665,6 @@ pub enum BuiltinLintDiag {
665665
test_module_span: Option<Span>,
666666
span_snippets: Vec<String>,
667667
},
668-
RedundantImport(Vec<(Span, bool)>, Ident),
669-
DeprecatedMacro {
670-
suggestion: Option<Symbol>,
671-
suggestion_span: Span,
672-
note: Option<Symbol>,
673-
path: String,
674-
since_kind: DeprecatedSinceKind,
675-
},
676668
SingleUseLifetime {
677669
/// Span of the parameter which declares this lifetime.
678670
param_span: Span,
@@ -698,44 +690,11 @@ pub enum BuiltinLintDiag {
698690
/// Indicates if the named argument is used as a width/precision for formatting
699691
is_formatting_arg: bool,
700692
},
701-
AmbiguousGlobReexports {
702-
/// The name for which collision(s) have occurred.
703-
name: String,
704-
/// The name space for which the collision(s) occurred in.
705-
namespace: String,
706-
/// Span where the name is first re-exported.
707-
first_reexport_span: Span,
708-
/// Span where the same name is also re-exported.
709-
duplicate_reexport_span: Span,
710-
},
711-
HiddenGlobReexports {
712-
/// The name of the local binding which shadows the glob re-export.
713-
name: String,
714-
/// The namespace for which the shadowing occurred in.
715-
namespace: String,
716-
/// The glob reexport that is shadowed by the local binding.
717-
glob_reexport_span: Span,
718-
/// The local binding that shadows the glob reexport.
719-
private_item_span: Span,
720-
},
721-
UnusedQualifications {
722-
/// The span of the unnecessarily-qualified path to remove.
723-
removal_span: Span,
724-
},
725-
AssociatedConstElidedLifetime {
726-
elided: bool,
727-
span: Span,
728-
lifetimes_in_scope: MultiSpan,
729-
},
730693
UnusedCrateDependency {
731694
extern_crate: Symbol,
732695
local_crate: Symbol,
733696
},
734697
AttributeLint(AttributeLintKind),
735-
UnreachableCfg {
736-
span: Span,
737-
wildcard_span: Option<Span>,
738-
},
739698
}
740699

741700
#[derive(Debug, HashStable_Generic)]

0 commit comments

Comments
 (0)