Skip to content

Commit 791adf7

Browse files
committed
Auto merge of #124417 - Xiretza:translate-early-lints, r=fmease
Make early lints translatable <del>Requires https://github.com/projectfluent/fluent-rs/pull/353.</del> 5134a04 r? diagnostics
2 parents 39e02f1 + 98dd6c7 commit 791adf7

File tree

80 files changed

+2107
-900
lines changed

Some content is hidden

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

80 files changed

+2107
-900
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: 9 additions & 14 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 {
@@ -766,11 +765,10 @@ impl<'a> AstValidator<'a> {
766765
.span_to_snippet(span)
767766
.is_ok_and(|snippet| !snippet.starts_with("#["))
768767
{
769-
self.lint_buffer.buffer_lint_with_diagnostic(
768+
self.lint_buffer.buffer_lint(
770769
MISSING_ABI,
771770
id,
772771
span,
773-
fluent::ast_passes_extern_without_abi,
774772
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
775773
)
776774
}
@@ -1428,17 +1426,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14281426
Self::check_decl_no_pat(&sig.decl, |span, ident, mut_ident| {
14291427
if mut_ident && matches!(ctxt, FnCtxt::Assoc(_)) {
14301428
if let Some(ident) = ident {
1431-
let msg = match ctxt {
1432-
FnCtxt::Foreign => fluent::ast_passes_pattern_in_foreign,
1433-
_ => fluent::ast_passes_pattern_in_bodiless,
1434-
};
1435-
let diag = BuiltinLintDiag::PatternsInFnsWithoutBody(span, ident);
1436-
self.lint_buffer.buffer_lint_with_diagnostic(
1429+
self.lint_buffer.buffer_lint(
14371430
PATTERNS_IN_FNS_WITHOUT_BODY,
14381431
id,
14391432
span,
1440-
msg,
1441-
diag,
1433+
BuiltinLintDiag::PatternsInFnsWithoutBody {
1434+
span,
1435+
ident,
1436+
is_foreign: matches!(ctxt, FnCtxt::Foreign),
1437+
},
14421438
)
14431439
}
14441440
} else {
@@ -1510,12 +1506,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15101506
Some((right, snippet))
15111507
}
15121508
};
1513-
self.lint_buffer.buffer_lint_with_diagnostic(
1509+
self.lint_buffer.buffer_lint(
15141510
DEPRECATED_WHERE_CLAUSE_LOCATION,
15151511
item.id,
15161512
err.span,
1517-
fluent::ast_passes_deprecated_where_clause_location,
1518-
BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg),
1513+
BuiltinLintDiag::DeprecatedWhereclauseLocation(err.span, sugg),
15191514
);
15201515
}
15211516

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: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,27 +528,21 @@ pub fn cfg_matches(
528528
try_gate_cfg(cfg.name, cfg.span, sess, features);
529529
match sess.psess.check_config.expecteds.get(&cfg.name) {
530530
Some(ExpectedValues::Some(values)) if !values.contains(&cfg.value) => {
531-
sess.psess.buffer_lint_with_diagnostic(
531+
sess.psess.buffer_lint(
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())),
543538
),
544539
);
545540
}
546541
None if sess.psess.check_config.exhaustive_names => {
547-
sess.psess.buffer_lint_with_diagnostic(
542+
sess.psess.buffer_lint(
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/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,3 @@ builtin_macros_unexpected_lit = expected path to a trait, found literal
247247
.label = not a trait
248248
.str_lit = try using `#[derive({$sym})]`
249249
.other = for example, write `#[derive(Debug)]` for `Debug`
250-
251-
builtin_macros_unnameable_test_items = cannot test inner items

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::errors;
22
use crate::util::expr_to_spanned_string;
33
use ast::token::IdentIsRaw;
4+
use lint::BuiltinLintDiag;
45
use rustc_ast as ast;
56
use rustc_ast::ptr::P;
67
use rustc_ast::token::{self, Delimiter};
@@ -513,15 +514,15 @@ fn expand_preparsed_asm(
513514
lint::builtin::BAD_ASM_STYLE,
514515
find_span(".intel_syntax"),
515516
ecx.current_expansion.lint_node_id,
516-
"avoid using `.intel_syntax`, Intel syntax is the default",
517+
BuiltinLintDiag::AvoidUsingIntelSyntax,
517518
);
518519
}
519520
if template_str.contains(".att_syntax") {
520521
ecx.psess().buffer_lint(
521522
lint::builtin::BAD_ASM_STYLE,
522523
find_span(".att_syntax"),
523524
ecx.current_expansion.lint_node_id,
524-
"avoid using `.att_syntax`, prefer using `options(att_syntax)` instead",
525+
BuiltinLintDiag::AvoidUsingAttSyntax,
525526
);
526527
}
527528
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,14 +1621,13 @@ impl<'a> TraitDef<'a> {
16211621
};
16221622

16231623
if let Some(ty) = exception {
1624-
cx.sess.psess.buffer_lint_with_diagnostic(
1624+
cx.sess.psess.buffer_lint(
16251625
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
16261626
sp,
16271627
ast::CRATE_NODE_ID,
1628-
format!(
1629-
"{ty} slice in a packed struct that derives a built-in trait"
1630-
),
1631-
rustc_lint_defs::BuiltinLintDiag::ByteSliceInPackedStructWithDerive,
1628+
rustc_lint_defs::BuiltinLintDiag::ByteSliceInPackedStructWithDerive {
1629+
ty: ty.to_string(),
1630+
},
16321631
);
16331632
} else {
16341633
// 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
@@ -556,7 +556,6 @@ fn make_format_args(
556556
let arg_name = args.explicit_args()[index].kind.ident().unwrap();
557557
ecx.buffered_early_lint.push(BufferedEarlyLint {
558558
span: arg_name.span.into(),
559-
msg: format!("named argument `{}` is not used by name", arg_name.name).into(),
560559
node_id: rustc_ast::CRATE_NODE_ID,
561560
lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
562561
diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally {

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_expand::base::{
1111
resolve_path, DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult,
1212
};
1313
use rustc_expand::module::DirOwnership;
14+
use rustc_lint_defs::BuiltinLintDiag;
1415
use rustc_parse::new_parser_from_file;
1516
use rustc_parse::parser::{ForceCollect, Parser};
1617
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
@@ -147,7 +148,7 @@ pub(crate) fn expand_include<'cx>(
147148
INCOMPLETE_INCLUDE,
148149
self.p.token.span,
149150
self.node_id,
150-
"include macro expected single expression in source",
151+
BuiltinLintDiag::IncompleteInclude,
151152
);
152153
}
153154
Some(expr)

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_ast::{attr, ModKind};
99
use rustc_expand::base::{ExtCtxt, ResolverExpand};
1010
use rustc_expand::expand::{AstFragment, ExpansionConfig};
1111
use rustc_feature::Features;
12+
use rustc_lint_defs::BuiltinLintDiag;
1213
use rustc_session::lint::builtin::UNNAMEABLE_TEST_ITEMS;
1314
use rustc_session::Session;
1415
use rustc_span::hygiene::{AstPass, SyntaxContext, Transparency};
@@ -163,7 +164,7 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> {
163164
UNNAMEABLE_TEST_ITEMS,
164165
attr.span,
165166
i.id,
166-
crate::fluent_generated::builtin_macros_unnameable_test_items,
167+
BuiltinLintDiag::UnnameableTestItems,
167168
);
168169
}
169170
}

0 commit comments

Comments
 (0)