Skip to content

Commit e7d1e2d

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 c3864d7 commit e7d1e2d

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 {
@@ -767,7 +766,6 @@ impl<'a> AstValidator<'a> {
767766
MISSING_ABI,
768767
id,
769768
span,
770-
fluent::ast_passes_extern_without_abi,
771769
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
772770
)
773771
}
@@ -1425,16 +1423,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14251423
Self::check_decl_no_pat(&sig.decl, |span, ident, mut_ident| {
14261424
if mut_ident && matches!(ctxt, FnCtxt::Assoc(_)) {
14271425
if let Some(ident) = ident {
1428-
let msg = match ctxt {
1429-
FnCtxt::Foreign => fluent::ast_passes_pattern_in_foreign,
1430-
_ => fluent::ast_passes_pattern_in_bodiless,
1431-
};
1432-
let diag = BuiltinLintDiag::PatternsInFnsWithoutBody(span, ident);
1426+
let is_foreign = matches!(ctxt, FnCtxt::Foreign);
1427+
let diag =
1428+
BuiltinLintDiag::PatternsInFnsWithoutBody { span, ident, is_foreign };
14331429
self.lint_buffer.buffer_lint_with_diagnostic(
14341430
PATTERNS_IN_FNS_WITHOUT_BODY,
14351431
id,
14361432
span,
1437-
msg,
14381433
diag,
14391434
)
14401435
}
@@ -1511,7 +1506,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15111506
DEPRECATED_WHERE_CLAUSE_LOCATION,
15121507
item.id,
15131508
err.span,
1514-
fluent::ast_passes_deprecated_where_clause_location,
15151509
BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg),
15161510
);
15171511
}

compiler/rustc_ast_passes/src/errors.rs

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

664664
#[derive(Diagnostic)]
665665
#[diag(ast_passes_pattern_in_foreign, code = E0130)]
666+
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
666667
pub struct PatternInForeign {
667668
#[primary_span]
668669
#[label]
@@ -671,6 +672,7 @@ pub struct PatternInForeign {
671672

672673
#[derive(Diagnostic)]
673674
#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
675+
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
674676
pub struct PatternInBodiless {
675677
#[primary_span]
676678
#[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
@@ -382,7 +382,6 @@ pub(crate) fn check_attr_crate_type(
382382
lint::builtin::UNKNOWN_CRATE_TYPES,
383383
ast::CRATE_NODE_ID,
384384
span,
385-
"invalid `crate_type` value",
386385
BuiltinLintDiag::UnknownCrateTypes(
387386
span,
388387
"did you mean".to_string(),

0 commit comments

Comments
 (0)