Skip to content

Commit 9a3a3f3

Browse files
committed
Generate lint diagnostic message from BuiltinLintDiag
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
1 parent 19a7d5b commit 9a3a3f3

File tree

27 files changed

+211
-130
lines changed

27 files changed

+211
-130
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ ast_passes_const_without_body =
5555
ast_passes_constraint_on_negative_bound =
5656
associated type constraints not allowed on negative bounds
5757
58-
ast_passes_deprecated_where_clause_location =
59-
where clause not allowed here
60-
6158
ast_passes_equality_in_where = equality constraints are not yet supported in `where` clauses
6259
.label = not supported
6360
.suggestion = if `{$ident}` is an associated type you're trying to set, use the associated type binding syntax
@@ -80,8 +77,6 @@ ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$de
8077
.suggestion = remove the {$remove_descr}
8178
.label = `extern` block begins here
8279
83-
ast_passes_extern_without_abi = extern declarations without an explicit ABI are deprecated
84-
8580
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
8681
.suggestion = remove the attribute
8782
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use std::ops::{Deref, DerefMut};
2727
use thin_vec::thin_vec;
2828

2929
use crate::errors;
30-
use crate::fluent_generated as fluent;
3130

3231
/// Is `self` allowed semantically as the first parameter in an `FnDecl`?
3332
enum SelfSemantic {
@@ -771,7 +770,6 @@ impl<'a> AstValidator<'a> {
771770
MISSING_ABI,
772771
id,
773772
span,
774-
fluent::ast_passes_extern_without_abi,
775773
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
776774
)
777775
}
@@ -1429,16 +1427,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14291427
Self::check_decl_no_pat(&sig.decl, |span, ident, mut_ident| {
14301428
if mut_ident && matches!(ctxt, FnCtxt::Assoc(_)) {
14311429
if let Some(ident) = ident {
1432-
let msg = match ctxt {
1433-
FnCtxt::Foreign => fluent::ast_passes_pattern_in_foreign,
1434-
_ => fluent::ast_passes_pattern_in_bodiless,
1435-
};
1436-
let diag = BuiltinLintDiag::PatternsInFnsWithoutBody(span, ident);
1430+
let is_foreign = matches!(ctxt, FnCtxt::Foreign);
1431+
let diag =
1432+
BuiltinLintDiag::PatternsInFnsWithoutBody { span, ident, is_foreign };
14371433
self.lint_buffer.buffer_lint_with_diagnostic(
14381434
PATTERNS_IN_FNS_WITHOUT_BODY,
14391435
id,
14401436
span,
1441-
msg,
14421437
diag,
14431438
)
14441439
}
@@ -1515,7 +1510,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15151510
DEPRECATED_WHERE_CLAUSE_LOCATION,
15161511
item.id,
15171512
err.span,
1518-
fluent::ast_passes_deprecated_where_clause_location,
15191513
BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg),
15201514
);
15211515
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ pub struct ConstAndCVariadic {
669669

670670
#[derive(Diagnostic)]
671671
#[diag(ast_passes_pattern_in_foreign, code = E0130)]
672+
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
672673
pub struct PatternInForeign {
673674
#[primary_span]
674675
#[label]
@@ -677,6 +678,7 @@ pub struct PatternInForeign {
677678

678679
#[derive(Diagnostic)]
679680
#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
681+
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
680682
pub struct PatternInBodiless {
681683
#[primary_span]
682684
#[label]

compiler/rustc_attr/src/builtin.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,6 @@ pub fn cfg_matches(
532532
UNEXPECTED_CFGS,
533533
cfg.span,
534534
lint_node_id,
535-
if let Some(value) = cfg.value {
536-
format!("unexpected `cfg` condition value: `{value}`")
537-
} else {
538-
format!("unexpected `cfg` condition value: (none)")
539-
},
540535
BuiltinLintDiag::UnexpectedCfgValue(
541536
(cfg.name, cfg.name_span),
542537
cfg.value.map(|v| (v, cfg.value_span.unwrap())),
@@ -548,7 +543,6 @@ pub fn cfg_matches(
548543
UNEXPECTED_CFGS,
549544
cfg.span,
550545
lint_node_id,
551-
format!("unexpected `cfg` condition name: `{}`", cfg.name),
552546
BuiltinLintDiag::UnexpectedCfgName(
553547
(cfg.name, cfg.name_span),
554548
cfg.value.map(|v| (v, cfg.value_span.unwrap())),

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,10 +1629,9 @@ impl<'a> TraitDef<'a> {
16291629
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
16301630
sp,
16311631
ast::CRATE_NODE_ID,
1632-
format!(
1633-
"{ty} slice in a packed struct that derives a built-in trait"
1634-
),
1635-
rustc_lint_defs::BuiltinLintDiag::ByteSliceInPackedStructWithDerive,
1632+
rustc_lint_defs::BuiltinLintDiag::ByteSliceInPackedStructWithDerive {
1633+
ty: ty.to_string(),
1634+
},
16361635
);
16371636
} else {
16381637
// Wrap the expression in `{...}`, causing a copy.

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ fn make_format_args(
558558
let arg_name = args.explicit_args()[index].kind.ident().unwrap();
559559
ecx.buffered_early_lint.push(BufferedEarlyLint {
560560
span: arg_name.span.into(),
561-
msg: format!("named argument `{}` is not used by name", arg_name.name).into(),
562561
node_id: rustc_ast::CRATE_NODE_ID,
563562
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
564563
diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally {

compiler/rustc_expand/src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,6 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
15581558
PROC_MACRO_BACK_COMPAT,
15591559
item.ident.span,
15601560
ast::CRATE_NODE_ID,
1561-
"using an old version of `rental`",
15621561
BuiltinLintDiag::ProcMacroBackCompat(
15631562
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
15641563
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()

compiler/rustc_expand/src/expand.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,6 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
17151715
UNUSED_DOC_COMMENTS,
17161716
current_span,
17171717
self.cx.current_expansion.lint_node_id,
1718-
"unused doc comment",
17191718
BuiltinLintDiag::UnusedDocComment(attr.span),
17201719
);
17211720
} else if rustc_attr::is_builtin_attr(attr) {
@@ -1727,7 +1726,6 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
17271726
UNUSED_ATTRIBUTES,
17281727
attr.span,
17291728
self.cx.current_expansion.lint_node_id,
1730-
format!("unused attribute `{attr_name}`"),
17311729
BuiltinLintDiag::UnusedBuiltinAttribute {
17321730
attr_name,
17331731
macro_name: pprust::path_to_string(&call.path),

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl<'a> ParserAnyMacro<'a> {
8282
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
8383
parser.token.span,
8484
lint_node_id,
85-
"trailing semicolon in macro used in expression position",
8685
BuiltinLintDiag::TrailingMacro(is_trailing_mac, macro_ident),
8786
);
8887
}
@@ -1153,7 +1152,6 @@ fn check_matcher_core<'tt>(
11531152
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
11541153
span,
11551154
ast::CRATE_NODE_ID,
1156-
"the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro",
11571155
BuiltinLintDiag::OrPatternsBackCompat(span, suggestion),
11581156
);
11591157
}

compiler/rustc_interface/src/util.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ pub(crate) fn check_attr_crate_type(
388388
lint::builtin::UNKNOWN_CRATE_TYPES,
389389
ast::CRATE_NODE_ID,
390390
span,
391-
"invalid `crate_type` value",
392391
BuiltinLintDiag::UnknownCrateTypes(
393392
span,
394393
"did you mean".to_string(),

0 commit comments

Comments
 (0)