Skip to content

Commit 791adf7

Browse files
committed
Auto merge of rust-lang#124417 - Xiretza:translate-early-lints, r=fmease
Make early lints translatable <del>Requires https://github.com/projectfluent/fluent-rs/pull/353.</del> rust-lang@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

-5
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

+9-14
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

+2
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

+2-8
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

-2
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

+3-2
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

+4-5
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

-1
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

+2-1
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

+2-1
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
}

compiler/rustc_builtin_macros/src/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
55
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt};
66
use rustc_expand::expand::AstFragment;
77
use rustc_feature::AttributeTemplate;
8-
use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES;
8+
use rustc_lint_defs::{builtin::DUPLICATE_MACRO_ATTRIBUTES, BuiltinLintDiag};
99
use rustc_parse::{parser, validate_attr};
1010
use rustc_session::errors::report_lit_error;
1111
use rustc_span::{BytePos, Span, Symbol};
@@ -46,7 +46,7 @@ pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable,
4646
DUPLICATE_MACRO_ATTRIBUTES,
4747
attr.span,
4848
ecx.current_expansion.lint_node_id,
49-
"duplicated attribute",
49+
BuiltinLintDiag::DuplicateMacroAttribute,
5050
);
5151
}
5252
}

compiler/rustc_errors/src/diagnostic_impls.rs

+6
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ impl IntoDiagArg for ClosureKind {
282282
}
283283
}
284284

285+
impl IntoDiagArg for hir::def::Namespace {
286+
fn into_diag_arg(self) -> DiagArgValue {
287+
DiagArgValue::Str(Cow::Borrowed(self.descr()))
288+
}
289+
}
290+
285291
#[derive(Clone)]
286292
pub struct DiagSymbolList(Vec<Symbol>);
287293

compiler/rustc_expand/src/base.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1364,18 +1364,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
13641364
};
13651365

13661366
if crate_matches {
1367-
// FIXME: make this translatable
1368-
#[allow(rustc::untranslatable_diagnostic)]
1369-
sess.psess.buffer_lint_with_diagnostic(
1370-
PROC_MACRO_BACK_COMPAT,
1371-
item.ident.span,
1372-
ast::CRATE_NODE_ID,
1373-
"using an old version of `rental`",
1374-
BuiltinLintDiag::ProcMacroBackCompat(
1375-
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
1376-
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
1377-
)
1378-
);
1367+
sess.psess.buffer_lint(
1368+
PROC_MACRO_BACK_COMPAT,
1369+
item.ident.span,
1370+
ast::CRATE_NODE_ID,
1371+
BuiltinLintDiag::ProcMacroBackCompat {
1372+
crate_name: "rental".to_string(),
1373+
fixed_version: "0.5.6".to_string(),
1374+
},
1375+
);
13791376
return true;
13801377
}
13811378
}

compiler/rustc_expand/src/config.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_attr as attr;
1414
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1515
use rustc_feature::Features;
1616
use rustc_feature::{ACCEPTED_FEATURES, REMOVED_FEATURES, UNSTABLE_FEATURES};
17+
use rustc_lint_defs::BuiltinLintDiag;
1718
use rustc_parse::validate_attr;
1819
use rustc_session::parse::feature_err;
1920
use rustc_session::Session;
@@ -248,7 +249,6 @@ impl<'a> StripUnconfigured<'a> {
248249
/// Gives a compiler warning when the `cfg_attr` contains no attributes and
249250
/// is in the original source file. Gives a compiler error if the syntax of
250251
/// the attribute is incorrect.
251-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
252252
pub(crate) fn expand_cfg_attr(&self, attr: &Attribute, recursive: bool) -> Vec<Attribute> {
253253
let Some((cfg_predicate, expanded_attrs)) =
254254
rustc_parse::parse_cfg_attr(attr, &self.sess.psess)
@@ -262,7 +262,7 @@ impl<'a> StripUnconfigured<'a> {
262262
rustc_lint_defs::builtin::UNUSED_ATTRIBUTES,
263263
attr.span,
264264
ast::CRATE_NODE_ID,
265-
"`#[cfg_attr]` does not expand to any attributes",
265+
BuiltinLintDiag::CfgAttrNoAttributes,
266266
);
267267
}
268268

@@ -283,7 +283,6 @@ impl<'a> StripUnconfigured<'a> {
283283
}
284284
}
285285

286-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
287286
fn expand_cfg_attr_item(
288287
&self,
289288
attr: &Attribute,
@@ -346,15 +345,15 @@ impl<'a> StripUnconfigured<'a> {
346345
rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
347346
attr.span,
348347
ast::CRATE_NODE_ID,
349-
"`crate_type` within an `#![cfg_attr] attribute is deprecated`",
348+
BuiltinLintDiag::CrateTypeInCfgAttr,
350349
);
351350
}
352351
if attr.has_name(sym::crate_name) {
353352
self.sess.psess.buffer_lint(
354353
rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
355354
attr.span,
356355
ast::CRATE_NODE_ID,
357-
"`crate_name` within an `#![cfg_attr] attribute is deprecated`",
356+
BuiltinLintDiag::CrateNameInCfgAttr,
358357
);
359358
}
360359
attr

compiler/rustc_expand/src/expand.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1799,23 +1799,21 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
17991799
}
18001800

18011801
if attr.is_doc_comment() {
1802-
self.cx.sess.psess.buffer_lint_with_diagnostic(
1802+
self.cx.sess.psess.buffer_lint(
18031803
UNUSED_DOC_COMMENTS,
18041804
current_span,
18051805
self.cx.current_expansion.lint_node_id,
1806-
"unused doc comment",
18071806
BuiltinLintDiag::UnusedDocComment(attr.span),
18081807
);
18091808
} else if rustc_attr::is_builtin_attr(attr) {
18101809
let attr_name = attr.ident().unwrap().name;
18111810
// `#[cfg]` and `#[cfg_attr]` are special - they are
18121811
// eagerly evaluated.
18131812
if attr_name != sym::cfg && attr_name != sym::cfg_attr {
1814-
self.cx.sess.psess.buffer_lint_with_diagnostic(
1813+
self.cx.sess.psess.buffer_lint(
18151814
UNUSED_ATTRIBUTES,
18161815
attr.span,
18171816
self.cx.current_expansion.lint_node_id,
1818-
format!("unused attribute `{attr_name}`"),
18191817
BuiltinLintDiag::UnusedBuiltinAttribute {
18201818
attr_name,
18211819
macro_name: pprust::path_to_string(&call.path),

0 commit comments

Comments
 (0)