Rename inline_fluent! to msg!

This commit is contained in:
Jonathan Brouwer 2026-02-14 13:47:52 +01:00
parent 3f808f29e6
commit 018a5efcf7
No known key found for this signature in database
GPG key ID: 13619B051B673C52
64 changed files with 647 additions and 840 deletions

View file

@ -22,7 +22,7 @@ use rustc_ast::visit::{FnCtxt, FnKind};
use rustc_ast::{self as ast, *};
use rustc_ast_pretty::pprust::expr_to_string;
use rustc_attr_parsing::AttributeParser;
use rustc_errors::{Applicability, LintDiagnostic, inline_fluent};
use rustc_errors::{Applicability, LintDiagnostic, msg};
use rustc_feature::GateIssue;
use rustc_hir as hir;
use rustc_hir::attrs::{AttributeKind, DocAttribute};
@ -2653,10 +2653,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
if let Some(err) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty, init)) {
let msg = match init {
InitKind::Zeroed => {
inline_fluent!("the type `{$ty}` does not permit zero-initialization")
msg!("the type `{$ty}` does not permit zero-initialization")
}
InitKind::Uninit => {
inline_fluent!("the type `{$ty}` does not permit being left uninitialized")
msg!("the type `{$ty}` does not permit being left uninitialized")
}
};
let sub = BuiltinUnpermittedTypeInitSub { err };

View file

@ -1,5 +1,5 @@
use rustc_errors::codes::*;
use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic, inline_fluent};
use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic, msg};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::lint::Level;
use rustc_span::{Span, Symbol};
@ -27,17 +27,17 @@ impl Subdiagnostic for OverruledAttributeSub {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
match self {
OverruledAttributeSub::DefaultSource { id } => {
diag.note(inline_fluent!("`forbid` lint level is the default for {$id}"));
diag.note(msg!("`forbid` lint level is the default for {$id}"));
diag.arg("id", id);
}
OverruledAttributeSub::NodeSource { span, reason } => {
diag.span_label(span, inline_fluent!("`forbid` level set here"));
diag.span_label(span, msg!("`forbid` level set here"));
if let Some(rationale) = reason {
diag.note(rationale.to_string());
}
}
OverruledAttributeSub::CommandLineSource => {
diag.note(inline_fluent!("`forbid` lint level was set on command line"));
diag.note(msg!("`forbid` lint level was set on command line"));
}
}
}

View file

@ -3,9 +3,7 @@ use std::ops::ControlFlow;
use hir::intravisit::{self, Visitor};
use rustc_ast::Recovered;
use rustc_errors::{
Applicability, Diag, EmissionGuarantee, Subdiagnostic, SuggestionStyle, inline_fluent,
};
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, SuggestionStyle, msg};
use rustc_hir::{self as hir, HirIdSet};
use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::adjustment::Adjust;
@ -356,7 +354,7 @@ impl Subdiagnostic for IfLetRescopeRewrite {
.chain(repeat_n('}', closing_brackets.count))
.collect(),
));
let msg = diag.eagerly_translate(inline_fluent!(
let msg = diag.eagerly_translate(msg!(
"a `match` with a single arm can preserve the drop order up to Edition 2021"
));
diag.multipart_suggestion_with_style(

View file

@ -3,7 +3,7 @@ use std::cell::LazyCell;
use rustc_data_structures::debug_assert_matches;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::unord::UnordSet;
use rustc_errors::{LintDiagnostic, Subdiagnostic, inline_fluent};
use rustc_errors::{LintDiagnostic, Subdiagnostic, msg};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
@ -435,23 +435,21 @@ struct ImplTraitOvercapturesLint<'tcx> {
impl<'a> LintDiagnostic<'a, ()> for ImplTraitOvercapturesLint<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
diag.primary_message(inline_fluent!(
diag.primary_message(msg!(
"`{$self_ty}` will capture more lifetimes than possibly intended in edition 2024"
));
diag.arg("self_ty", self.self_ty.to_string())
.arg("num_captured", self.num_captured)
.span_note(
self.uncaptured_spans,
inline_fluent!(
msg!(
"specifically, {$num_captured ->
[one] this lifetime is
*[other] these lifetimes are
} in scope but not mentioned in the type's bounds"
),
)
.note(inline_fluent!(
"all lifetimes in scope will be captured by `impl Trait`s in edition 2024"
));
.note(msg!("all lifetimes in scope will be captured by `impl Trait`s in edition 2024"));
if let Some(suggestion) = self.suggestion {
suggestion.add_to_diag(diag);
}

View file

@ -2,7 +2,7 @@ use rustc_ast::attr::AttributeExt;
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::unord::UnordSet;
use rustc_errors::{Diag, LintDiagnostic, MultiSpan, inline_fluent};
use rustc_errors::{Diag, LintDiagnostic, MultiSpan, msg};
use rustc_feature::{Features, GateIssue};
use rustc_hir::HirId;
use rustc_hir::intravisit::{self, Visitor};
@ -941,9 +941,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
let lint = builtin::UNKNOWN_LINTS;
let level = self.lint_level(builtin::UNKNOWN_LINTS);
lint_level(self.sess, lint, level, Some(span.into()), |lint| {
lint.primary_message(inline_fluent!("unknown lint: `{$name}`"));
lint.primary_message(msg!("unknown lint: `{$name}`"));
lint.arg("name", lint_id.lint.name_lower());
lint.note(inline_fluent!("the `{$name}` lint is unstable"));
lint.note(msg!("the `{$name}` lint is unstable"));
rustc_session::parse::add_feature_diagnostics_for_issue(
lint,
&self.sess,

View file

@ -5,7 +5,7 @@ use std::num::NonZero;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag,
EmissionGuarantee, LintDiagnostic, MultiSpan, Subdiagnostic, SuggestionStyle, inline_fluent,
EmissionGuarantee, LintDiagnostic, MultiSpan, Subdiagnostic, SuggestionStyle, msg,
};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
@ -228,7 +228,7 @@ pub(crate) struct BuiltinMissingDebugImpl<'a> {
// Needed for def_path_str
impl<'a> LintDiagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
diag.primary_message(inline_fluent!("type does not implement `{$debug}`; consider adding `#[derive(Debug)]` or a manual implementation"));
diag.primary_message(msg!("type does not implement `{$debug}`; consider adding `#[derive(Debug)]` or a manual implementation"));
diag.arg("debug", self.tcx.def_path_str(self.def_id));
}
}
@ -298,11 +298,8 @@ pub(crate) struct BuiltinUngatedAsyncFnTrackCaller<'a> {
impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(inline_fluent!("`#[track_caller]` on async functions is a no-op"));
diag.span_label(
self.label,
inline_fluent!("this function will not propagate the caller location"),
);
diag.primary_message(msg!("`#[track_caller]` on async functions is a no-op"));
diag.span_label(self.label, msg!("this function will not propagate the caller location"));
rustc_session::parse::add_feature_diagnostics(
diag,
self.session,
@ -345,20 +342,17 @@ pub(crate) struct BuiltinTypeAliasBounds<'hir> {
impl<'a> LintDiagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(if self.in_where_clause {
inline_fluent!("where clauses on type aliases are not enforced")
msg!("where clauses on type aliases are not enforced")
} else {
inline_fluent!("bounds on generic parameters in type aliases are not enforced")
msg!("bounds on generic parameters in type aliases are not enforced")
});
diag.span_label(
self.label,
inline_fluent!("will not be checked at usage sites of the type alias"),
);
diag.note(inline_fluent!(
diag.span_label(self.label, msg!("will not be checked at usage sites of the type alias"));
diag.note(msg!(
"this is a known limitation of the type checker that may be lifted in a future edition.
see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information"
));
if self.enable_feat_help {
diag.help(inline_fluent!("add `#![feature(lazy_type_alias)]` to the crate attributes to enable the desired semantics"));
diag.help(msg!("add `#![feature(lazy_type_alias)]` to the crate attributes to enable the desired semantics"));
}
// We perform the walk in here instead of in `<TypeAliasBounds as LateLintPass>` to
@ -385,9 +379,9 @@ impl<'a> LintDiagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> {
diag.arg("count", self.suggestions.len());
diag.multipart_suggestion(
if self.in_where_clause {
inline_fluent!("remove this where clause")
msg!("remove this where clause")
} else {
inline_fluent!(
msg!(
"remove {$count ->
[one] this bound
*[other] these bounds
@ -410,7 +404,7 @@ impl<'a> LintDiagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> {
// (We could employ some simple heuristics but that's likely not worth it).
for qself in collector.qselves {
diag.multipart_suggestion(
inline_fluent!("fully qualify this associated type"),
msg!("fully qualify this associated type"),
vec![
(qself.shrink_to_lo(), "<".into()),
(qself.shrink_to_hi(), " as /* Trait */>".into()),
@ -551,15 +545,12 @@ impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(self.msg);
diag.arg("ty", self.ty);
diag.span_label(
self.label,
inline_fluent!("this code causes undefined behavior when executed"),
);
diag.span_label(self.label, msg!("this code causes undefined behavior when executed"));
if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
// Only suggest late `MaybeUninit::assume_init` initialization if the type is inhabited.
diag.span_label(
self.label,
inline_fluent!("help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done"),
msg!("help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done"),
);
}
self.sub.add_to_diag(diag);
@ -1183,7 +1174,7 @@ impl Subdiagnostic for NonBindingLetSub {
let prefix = if self.is_assign_desugar { "let " } else { "" };
diag.span_suggestion_verbose(
self.suggestion,
inline_fluent!(
msg!(
"consider binding to an unused variable to avoid immediately dropping the value"
),
format!("{prefix}_unused"),
@ -1192,14 +1183,14 @@ impl Subdiagnostic for NonBindingLetSub {
} else {
diag.span_help(
self.suggestion,
inline_fluent!(
msg!(
"consider binding to an unused variable to avoid immediately dropping the value"
),
);
}
if let Some(drop_fn_start_end) = self.drop_fn_start_end {
diag.multipart_suggestion(
inline_fluent!("consider immediately dropping the value"),
msg!("consider immediately dropping the value"),
vec![
(drop_fn_start_end.0, "drop(".to_string()),
(drop_fn_start_end.1, ")".to_string()),
@ -1207,7 +1198,7 @@ impl Subdiagnostic for NonBindingLetSub {
Applicability::MachineApplicable,
);
} else {
diag.help(inline_fluent!(
diag.help(msg!(
"consider immediately dropping the value using `drop(..)` after the `let` statement"
));
}
@ -1454,7 +1445,7 @@ pub(crate) struct NonFmtPanicUnused {
// Used because of two suggestions based on one Option<Span>
impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(inline_fluent!(
diag.primary_message(msg!(
"panic message contains {$count ->
[one] an unused
*[other] unused
@ -1464,11 +1455,11 @@ impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
}"
));
diag.arg("count", self.count);
diag.note(inline_fluent!("this message is not used as a format string when given without arguments, but will be in Rust 2021"));
diag.note(msg!("this message is not used as a format string when given without arguments, but will be in Rust 2021"));
if let Some(span) = self.suggestion {
diag.span_suggestion(
span.shrink_to_hi(),
inline_fluent!(
msg!(
"add the missing {$count ->
[one] argument
*[other] arguments
@ -1479,9 +1470,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
);
diag.span_suggestion(
span.shrink_to_lo(),
inline_fluent!(
r#"or add a "{"{"}{"}"}" format string to use the message literally"#
),
msg!(r#"or add a "{"{"}{"}"}" format string to use the message literally"#),
"\"{}\", ",
Applicability::MachineApplicable,
);
@ -1558,15 +1547,15 @@ impl Subdiagnostic for NonSnakeCaseDiagSub {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
match self {
NonSnakeCaseDiagSub::Label { span } => {
diag.span_label(span, inline_fluent!("should have a snake_case name"));
diag.span_label(span, msg!("should have a snake_case name"));
}
NonSnakeCaseDiagSub::Help => {
diag.help(inline_fluent!("convert the identifier to snake case: `{$sc}`"));
diag.help(msg!("convert the identifier to snake case: `{$sc}`"));
}
NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
diag.span_suggestion(
span,
inline_fluent!("convert the identifier to snake case"),
msg!("convert the identifier to snake case"),
suggestion,
Applicability::MaybeIncorrect,
);
@ -1574,18 +1563,16 @@ impl Subdiagnostic for NonSnakeCaseDiagSub {
NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
diag.span_suggestion(
span,
inline_fluent!(
"rename the identifier or convert it to a snake case raw identifier"
),
msg!("rename the identifier or convert it to a snake case raw identifier"),
suggestion,
Applicability::MaybeIncorrect,
);
}
NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
diag.note(inline_fluent!("`{$sc}` cannot be used as a raw identifier"));
diag.note(msg!("`{$sc}` cannot be used as a raw identifier"));
diag.span_suggestion(
span,
inline_fluent!("rename the identifier"),
msg!("rename the identifier"),
"",
Applicability::MaybeIncorrect,
);
@ -1703,7 +1690,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
doctest,
macro_to_change,
} => {
diag.primary_message(inline_fluent!("non-local `impl` definition, `impl` blocks should be written at the same level as their item"));
diag.primary_message(msg!("non-local `impl` definition, `impl` blocks should be written at the same level as their item"));
diag.arg("depth", depth);
diag.arg("body_kind_descr", body_kind_descr);
diag.arg("body_name", body_name);
@ -1711,24 +1698,24 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
if let Some((macro_to_change, macro_kind)) = macro_to_change {
diag.arg("macro_to_change", macro_to_change);
diag.arg("macro_kind", macro_kind);
diag.note(inline_fluent!("the {$macro_kind} `{$macro_to_change}` defines the non-local `impl`, and may need to be changed"));
diag.note(msg!("the {$macro_kind} `{$macro_to_change}` defines the non-local `impl`, and may need to be changed"));
}
if let Some(cargo_update) = cargo_update {
diag.subdiagnostic(cargo_update);
}
diag.note(inline_fluent!("an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`"));
diag.note(msg!("an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`"));
if doctest {
diag.help(inline_fluent!("make this doc-test a standalone test with its own `fn main() {\"{\"} ... {\"}\"}`"));
diag.help(msg!("make this doc-test a standalone test with its own `fn main() {\"{\"} ... {\"}\"}`"));
}
if let Some(const_anon) = const_anon {
diag.note(inline_fluent!("items in an anonymous const item (`const _: () = {\"{\"} ... {\"}\"}`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint"));
diag.note(msg!("items in an anonymous const item (`const _: () = {\"{\"} ... {\"}\"}`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint"));
if let Some(const_anon) = const_anon {
diag.span_suggestion(
const_anon,
inline_fluent!("use a const-anon item to suppress this lint"),
msg!("use a const-anon item to suppress this lint"),
"_",
Applicability::MachineApplicable,
);
@ -1742,15 +1729,15 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
doctest,
cargo_update,
} => {
diag.primary_message(inline_fluent!("non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module"));
diag.primary_message(msg!("non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module"));
diag.arg("depth", depth);
diag.arg("body_kind_descr", body_kind_descr);
diag.arg("body_name", body_name);
if doctest {
diag.help(inline_fluent!(r#"remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}`"#));
diag.help(msg!(r#"remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}`"#));
} else {
diag.help(inline_fluent!(
diag.help(msg!(
"remove the `#[macro_export]` or move this `macro_rules!` outside the of the current {$body_kind_descr} {$depth ->
[one] `{$body_name}`
*[other] `{$body_name}` and up {$depth} bodies
@ -1758,7 +1745,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
));
}
diag.note(inline_fluent!("a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute"));
diag.note(msg!("a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute"));
if let Some(cargo_update) = cargo_update {
diag.subdiagnostic(cargo_update);
@ -1861,7 +1848,7 @@ pub(crate) struct DropTraitConstraintsDiag<'a> {
// Needed for def_path_str
impl<'a> LintDiagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(inline_fluent!("bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped"));
diag.primary_message(msg!("bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped"));
diag.arg("predicate", self.predicate);
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
}
@ -1875,7 +1862,7 @@ pub(crate) struct DropGlue<'a> {
// Needed for def_path_str
impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(inline_fluent!("types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped"));
diag.primary_message(msg!("types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped"));
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
}
}
@ -2317,18 +2304,16 @@ pub(crate) struct ImproperCTypes<'a> {
// Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span>
impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(inline_fluent!(
"`extern` {$desc} uses type `{$ty}`, which is not FFI-safe"
));
diag.primary_message(msg!("`extern` {$desc} uses type `{$ty}`, which is not FFI-safe"));
diag.arg("ty", self.ty);
diag.arg("desc", self.desc);
diag.span_label(self.label, inline_fluent!("not FFI-safe"));
diag.span_label(self.label, msg!("not FFI-safe"));
if let Some(help) = self.help {
diag.help(help);
}
diag.note(self.note);
if let Some(note) = self.span_note {
diag.span_note(note, inline_fluent!("the type is defined here"));
diag.span_note(note, msg!("the type is defined here"));
}
}
}
@ -2491,7 +2476,7 @@ pub(crate) enum UnusedDefSuggestion {
// Needed because of def_path_str
impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(inline_fluent!("unused {$pre}`{$def}`{$post} that must be used"));
diag.primary_message(msg!("unused {$pre}`{$def}`{$post} that must be used"));
diag.arg("pre", self.pre);
diag.arg("post", self.post);
diag.arg("def", self.cx.tcx.def_path_str(self.def_id));
@ -2575,10 +2560,10 @@ pub(crate) struct AsyncFnInTraitDiag {
impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.primary_message(inline_fluent!("use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified"));
diag.note(inline_fluent!("you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`"));
diag.primary_message(msg!("use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified"));
diag.note(msg!("you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`"));
if let Some(sugg) = self.sugg {
diag.multipart_suggestion(inline_fluent!("you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change"), sugg, Applicability::MaybeIncorrect);
diag.multipart_suggestion(msg!("you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change"), sugg, Applicability::MaybeIncorrect);
}
}
}
@ -3450,44 +3435,44 @@ impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSynta
}
LifetimeSyntaxCategories { hidden: _, elided: _, named: 0 } => {
inline_fluent!("hiding a lifetime that's elided elsewhere is confusing")
msg!("hiding a lifetime that's elided elsewhere is confusing")
}
LifetimeSyntaxCategories { hidden: _, elided: 0, named: _ } => {
inline_fluent!("hiding a lifetime that's named elsewhere is confusing")
msg!("hiding a lifetime that's named elsewhere is confusing")
}
LifetimeSyntaxCategories { hidden: 0, elided: _, named: _ } => {
inline_fluent!("eliding a lifetime that's named elsewhere is confusing")
msg!("eliding a lifetime that's named elsewhere is confusing")
}
LifetimeSyntaxCategories { hidden: _, elided: _, named: _ } => {
inline_fluent!("hiding or eliding a lifetime that's named elsewhere is confusing")
msg!("hiding or eliding a lifetime that's named elsewhere is confusing")
}
};
diag.primary_message(message);
for s in self.inputs.hidden {
diag.span_label(s, inline_fluent!("the lifetime is hidden here"));
diag.span_label(s, msg!("the lifetime is hidden here"));
}
for s in self.inputs.elided {
diag.span_label(s, inline_fluent!("the lifetime is elided here"));
diag.span_label(s, msg!("the lifetime is elided here"));
}
for s in self.inputs.named {
diag.span_label(s, inline_fluent!("the lifetime is named here"));
diag.span_label(s, msg!("the lifetime is named here"));
}
for s in self.outputs.hidden {
diag.span_label(s, inline_fluent!("the same lifetime is hidden here"));
diag.span_label(s, msg!("the same lifetime is hidden here"));
}
for s in self.outputs.elided {
diag.span_label(s, inline_fluent!("the same lifetime is elided here"));
diag.span_label(s, msg!("the same lifetime is elided here"));
}
for s in self.outputs.named {
diag.span_label(s, inline_fluent!("the same lifetime is named here"));
diag.span_label(s, msg!("the same lifetime is named here"));
}
diag.help(inline_fluent!(
diag.help(msg!(
"the same lifetime is referred to in inconsistent ways, making the signature confusing"
));
@ -3563,7 +3548,7 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
Implicit { suggestions, optional_alternative } => {
let suggestions = suggestions.into_iter().map(|s| (s, String::new())).collect();
diag.multipart_suggestion_with_style(
inline_fluent!("remove the lifetime name from references"),
msg!("remove the lifetime name from references"),
suggestions,
applicability(optional_alternative),
style(optional_alternative),
@ -3576,11 +3561,9 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
optional_alternative,
} => {
let message = if implicit_suggestions.is_empty() {
inline_fluent!("use `'_` for type paths")
msg!("use `'_` for type paths")
} else {
inline_fluent!(
"remove the lifetime name from references and use `'_` for type paths"
)
msg!("remove the lifetime name from references and use `'_` for type paths")
};
let implicit_suggestions =
@ -3599,8 +3582,7 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
Explicit { lifetime_name, suggestions, optional_alternative } => {
diag.arg("lifetime_name", lifetime_name);
let msg =
diag.eagerly_translate(inline_fluent!("consistently use `{$lifetime_name}`"));
let msg = diag.eagerly_translate(msg!("consistently use `{$lifetime_name}`"));
diag.remove_arg("lifetime_name");
diag.multipart_suggestion_with_style(
msg,

View file

@ -1,5 +1,5 @@
use rustc_ast as ast;
use rustc_errors::{Applicability, inline_fluent};
use rustc_errors::{Applicability, msg};
use rustc_hir::{self as hir, LangItem};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::{bug, ty};
@ -121,20 +121,20 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
}
cx.span_lint(NON_FMT_PANICS, arg_span, |lint| {
lint.primary_message(inline_fluent!("panic message is not a string literal"));
lint.primary_message(msg!("panic message is not a string literal"));
lint.arg("name", symbol);
lint.note(inline_fluent!("this usage of `{$name}!()` is deprecated; it will be a hard error in Rust 2021"));
lint.note(inline_fluent!("for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/panic-macro-consistency.html>"));
lint.note(msg!("this usage of `{$name}!()` is deprecated; it will be a hard error in Rust 2021"));
lint.note(msg!("for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/panic-macro-consistency.html>"));
if !is_arg_inside_call(arg_span, span) {
// No clue where this argument is coming from.
return;
}
if arg_macro.is_some_and(|id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) {
// A case of `panic!(format!(..))`.
lint.note(inline_fluent!("the `{$name}!()` macro supports formatting, so there's no need for the `format!()` macro here"));
lint.note(msg!("the `{$name}!()` macro supports formatting, so there's no need for the `format!()` macro here"));
if let Some((open, close, _)) = find_delimiters(cx, arg_span) {
lint.multipart_suggestion(
inline_fluent!("remove the `format!(..)` macro call"),
msg!("remove the `format!(..)` macro call"),
vec![
(arg_span.until(open.shrink_to_hi()), "".into()),
(close.until(arg_span.shrink_to_hi()), "".into()),
@ -178,7 +178,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
if suggest_display {
lint.span_suggestion_verbose(
arg_span.shrink_to_lo(),
inline_fluent!(r#"add a "{"{"}{"}"}" format string to `Display` the message"#),
msg!(r#"add a "{"{"}{"}"}" format string to `Display` the message"#),
"\"{}\", ",
fmt_applicability,
);
@ -186,7 +186,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
lint.arg("ty", ty);
lint.span_suggestion_verbose(
arg_span.shrink_to_lo(),
inline_fluent!(r#"add a "{"{"}:?{"}"}" format string to use the `Debug` implementation of `{$ty}`"#),
msg!(r#"add a "{"{"}:?{"}"}" format string to use the `Debug` implementation of `{$ty}`"#),
"\"{:?}\", ",
fmt_applicability,
);
@ -196,7 +196,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
if let Some((open, close, del)) = find_delimiters(cx, span) {
lint.arg("already_suggested", suggest_display || suggest_debug);
lint.multipart_suggestion(
inline_fluent!(
msg!(
"{$already_suggested ->
[true] or use
*[false] use

View file

@ -1,4 +1,4 @@
use rustc_errors::{MultiSpan, inline_fluent};
use rustc_errors::{MultiSpan, msg};
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{self, Visitor, VisitorExt};
@ -210,7 +210,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
if !doctest {
ms.push_span_label(
cx.tcx.def_span(parent),
inline_fluent!(
msg!(
"move the `impl` block outside of this {$body_kind_descr} {$depth ->
[one] `{$body_name}`
*[other] `{$body_name}` and up {$depth} bodies

View file

@ -4,7 +4,7 @@ use std::ops::ControlFlow;
use bitflags::bitflags;
use rustc_abi::VariantIdx;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{DiagMessage, inline_fluent};
use rustc_errors::{DiagMessage, msg};
use rustc_hir::def::CtorKind;
use rustc_hir::intravisit::VisitorExt;
use rustc_hir::{self as hir, AmbigArg};
@ -158,12 +158,12 @@ pub(crate) fn check_non_exhaustive_variant(
// with an enum like `#[repr(u8)] enum Enum { A(DataA), B(DataB), }`
// but exempt enums with unit ctors like C's (e.g. from rust-bindgen)
if variant_has_complex_ctor(variant) {
return ControlFlow::Break(inline_fluent!("this enum is non-exhaustive"));
return ControlFlow::Break(msg!("this enum is non-exhaustive"));
}
}
if variant.field_list_has_applicable_non_exhaustive() {
return ControlFlow::Break(inline_fluent!("this enum has non-exhaustive variants"));
return ControlFlow::Break(msg!("this enum has non-exhaustive variants"));
}
ControlFlow::Continue(())
@ -426,7 +426,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
} else if transparent_with_all_zst_fields {
FfiUnsafe {
ty,
reason: inline_fluent!("this struct contains only zero-sized fields"),
reason: msg!("this struct contains only zero-sized fields"),
help: None,
}
} else {
@ -464,7 +464,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
} else {
return FfiUnsafe {
ty,
reason: inline_fluent!("box cannot be represented as a single pointer"),
reason: msg!("box cannot be represented as a single pointer"),
help: None,
};
}
@ -480,10 +480,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
{
return FfiUnsafe {
ty,
reason: inline_fluent!(
"`CStr`/`CString` do not have a guaranteed layout"
),
help: Some(inline_fluent!(
reason: msg!("`CStr`/`CString` do not have a guaranteed layout"),
help: Some(msg!(
"consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()`"
)),
};
@ -493,16 +491,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
return FfiUnsafe {
ty,
reason: if def.is_struct() {
inline_fluent!("this struct has unspecified layout")
msg!("this struct has unspecified layout")
} else {
inline_fluent!("this union has unspecified layout")
msg!("this union has unspecified layout")
},
help: if def.is_struct() {
Some(inline_fluent!(
Some(msg!(
"consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct"
))
} else {
Some(inline_fluent!(
Some(msg!(
"consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this union"
))
},
@ -513,9 +511,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
return FfiUnsafe {
ty,
reason: if def.is_struct() {
inline_fluent!("this struct is non-exhaustive")
msg!("this struct is non-exhaustive")
} else {
inline_fluent!("this union is non-exhaustive")
msg!("this union is non-exhaustive")
},
help: None,
};
@ -525,14 +523,14 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
return FfiUnsafe {
ty,
reason: if def.is_struct() {
inline_fluent!("this struct has no fields")
msg!("this struct has no fields")
} else {
inline_fluent!("this union has no fields")
msg!("this union has no fields")
},
help: if def.is_struct() {
Some(inline_fluent!("consider adding a member to this struct"))
Some(msg!("consider adding a member to this struct"))
} else {
Some(inline_fluent!("consider adding a member to this union"))
Some(msg!("consider adding a member to this union"))
},
};
}
@ -557,8 +555,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
return FfiUnsafe {
ty,
reason: inline_fluent!("enum has no representation hint"),
help: Some(inline_fluent!(
reason: msg!("enum has no representation hint"),
help: Some(msg!(
"consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum"
)),
};
@ -586,8 +584,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
ty::Char => FfiUnsafe {
ty,
reason: inline_fluent!("the `char` type has no C equivalent"),
help: Some(inline_fluent!("consider using `u32` or `libc::wchar_t` instead")),
reason: msg!("the `char` type has no C equivalent"),
help: Some(msg!("consider using `u32` or `libc::wchar_t` instead")),
},
// It's just extra invariants on the type that you need to uphold,
@ -599,26 +597,24 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
ty::Slice(_) => FfiUnsafe {
ty,
reason: inline_fluent!("slices have no C equivalent"),
help: Some(inline_fluent!("consider using a raw pointer instead")),
reason: msg!("slices have no C equivalent"),
help: Some(msg!("consider using a raw pointer instead")),
},
ty::Dynamic(..) => FfiUnsafe {
ty,
reason: inline_fluent!("trait objects have no C equivalent"),
help: None,
},
ty::Dynamic(..) => {
FfiUnsafe { ty, reason: msg!("trait objects have no C equivalent"), help: None }
}
ty::Str => FfiUnsafe {
ty,
reason: inline_fluent!("string slices have no C equivalent"),
help: Some(inline_fluent!("consider using `*const u8` and a length instead")),
reason: msg!("string slices have no C equivalent"),
help: Some(msg!("consider using `*const u8` and a length instead")),
},
ty::Tuple(..) => FfiUnsafe {
ty,
reason: inline_fluent!("tuples have unspecified layout"),
help: Some(inline_fluent!("consider using a struct instead")),
reason: msg!("tuples have unspecified layout"),
help: Some(msg!("consider using a struct instead")),
},
ty::RawPtr(ty, _) | ty::Ref(_, ty, _)
@ -648,10 +644,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
if sig.abi().is_rustic_abi() {
return FfiUnsafe {
ty,
reason: inline_fluent!(
"this function pointer has Rust-specific calling convention"
),
help: Some(inline_fluent!(
reason: msg!("this function pointer has Rust-specific calling convention"),
help: Some(msg!(
"consider using an `extern fn(...) -> ...` function pointer instead"
)),
};
@ -677,11 +671,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
// While opaque types are checked for earlier, if a projection in a struct field
// normalizes to an opaque type, then it will reach this branch.
ty::Alias(ty::Opaque, ..) => FfiUnsafe {
ty,
reason: inline_fluent!("opaque types have no C equivalent"),
help: None,
},
ty::Alias(ty::Opaque, ..) => {
FfiUnsafe { ty, reason: msg!("opaque types have no C equivalent"), help: None }
}
// `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe,
// so they are currently ignored for the purposes of this lint.
@ -693,9 +685,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
ty::UnsafeBinder(_) => FfiUnsafe {
ty,
reason: inline_fluent!(
"unsafe binders are incompatible with foreign function interfaces"
),
reason: msg!("unsafe binders are incompatible with foreign function interfaces"),
help: None,
},
@ -741,7 +731,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
{
Some(FfiResult::FfiUnsafe {
ty,
reason: inline_fluent!("opaque types have no C equivalent"),
reason: msg!("opaque types have no C equivalent"),
help: None,
})
} else {
@ -754,8 +744,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
if let ty::Array(..) = ty.kind() {
Some(FfiResult::FfiUnsafe {
ty,
reason: inline_fluent!("passing raw arrays by value is not FFI-safe"),
help: Some(inline_fluent!("consider passing a pointer to the array")),
reason: msg!("passing raw arrays by value is not FFI-safe"),
help: Some(msg!("consider passing a pointer to the array")),
})
} else {
None
@ -934,7 +924,7 @@ impl<'tcx> ImproperCTypesLint {
cx,
ty,
sp,
inline_fluent!("composed only of `PhantomData`"),
msg!("composed only of `PhantomData`"),
None,
fn_mode,
);