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

@ -2,7 +2,7 @@
use hir::{ConstContext, LangItem};
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, MultiSpan, inline_fluent};
use rustc_errors::{Applicability, Diag, MultiSpan, msg};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::TyCtxtInferExt;
@ -181,7 +181,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
);
if let ConstContext::Static(_) = ccx.const_kind() {
err.note(inline_fluent!(
err.note(msg!(
"consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`"
));
}

View file

@ -43,40 +43,36 @@ pub enum ConstEvalErrKind {
impl MachineStopType for ConstEvalErrKind {
fn diagnostic_message(&self) -> DiagMessage {
use ConstEvalErrKind::*;
use rustc_errors::inline_fluent;
use rustc_errors::msg;
match self {
ConstAccessesMutGlobal => "constant accesses mutable global memory".into(),
ModifiedGlobal => {
"modifying a static's initial value from another static's initializer".into()
}
Panic { .. } => inline_fluent!("evaluation panicked: {$msg}"),
Panic { .. } => msg!("evaluation panicked: {$msg}"),
RecursiveStatic => {
"encountered static that tried to access itself during initialization".into()
}
AssertFailure(x) => x.diagnostic_message(),
WriteThroughImmutablePointer => {
inline_fluent!(
msg!(
"writing through a pointer that was derived from a shared (immutable) reference"
)
}
ConstMakeGlobalPtrAlreadyMadeGlobal { .. } => {
inline_fluent!(
"attempting to call `const_make_global` twice on the same allocation {$alloc}"
)
msg!("attempting to call `const_make_global` twice on the same allocation {$alloc}")
}
ConstMakeGlobalPtrIsNonHeap(_) => {
inline_fluent!(
msg!(
"pointer passed to `const_make_global` does not point to a heap allocation: {$ptr}"
)
}
ConstMakeGlobalWithDanglingPtr(_) => {
inline_fluent!("pointer passed to `const_make_global` is dangling: {$ptr}")
msg!("pointer passed to `const_make_global` is dangling: {$ptr}")
}
ConstMakeGlobalWithOffset(_) => {
inline_fluent!(
"making {$ptr} global which does not point to the beginning of an object"
)
msg!("making {$ptr} global which does not point to the beginning of an object")
}
}
}

View file

@ -2,7 +2,7 @@ use std::sync::atomic::Ordering::Relaxed;
use either::{Left, Right};
use rustc_abi::{self as abi, BackendRepr};
use rustc_errors::{E0080, inline_fluent};
use rustc_errors::{E0080, msg};
use rustc_hir::def::DefKind;
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo};
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
@ -469,7 +469,7 @@ fn report_eval_error<'tcx>(
diag.code(E0080);
diag.span_label(
span,
inline_fluent!(
msg!(
"evaluation of `{$instance}` failed {$num_frames ->
[0] here
*[other] inside this call

View file

@ -5,7 +5,7 @@ use std::hash::Hash;
use rustc_abi::{Align, Size};
use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
use rustc_errors::inline_fluent;
use rustc_errors::msg;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem};
use rustc_middle::mir::AssertMessage;
@ -489,7 +489,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
let align = match Align::from_bytes(align) {
Ok(a) => a,
Err(err) => throw_ub_custom!(
inline_fluent!(
msg!(
"invalid align passed to `{$name}`: {$align} is {$err_kind ->
[not_power_of_two] not a power of 2
[too_large] too large
@ -519,7 +519,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
let align = match Align::from_bytes(align) {
Ok(a) => a,
Err(err) => throw_ub_custom!(
inline_fluent!(
msg!(
"invalid align passed to `{$name}`: {$align} is {$err_kind ->
[not_power_of_two] not a power of 2
[too_large] too large

View file

@ -6,7 +6,7 @@ use rustc_abi::WrappingRange;
use rustc_errors::codes::*;
use rustc_errors::{
Diag, DiagArgValue, DiagMessage, Diagnostic, EmissionGuarantee, Level, MultiSpan,
Subdiagnostic, inline_fluent,
Subdiagnostic, msg,
};
use rustc_hir::ConstContext;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@ -389,9 +389,9 @@ impl Subdiagnostic for FrameNote {
diag.arg("instance", self.instance);
let mut span: MultiSpan = self.span.into();
if self.has_label && !self.span.is_dummy() {
span.push_span_label(self.span, inline_fluent!("the failure occurred here"));
span.push_span_label(self.span, msg!("the failure occurred here"));
}
let msg = diag.eagerly_translate(inline_fluent!(
let msg = diag.eagerly_translate(msg!(
r#"{$times ->
[0] inside {$where_ ->
[closure] closure
@ -653,25 +653,25 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
ValidationError(e) => e.diagnostic_message(),
Unreachable => "entering unreachable code".into(),
BoundsCheckFailed { .. } => inline_fluent!("indexing out of bounds: the len is {$len} but the index is {$index}"),
BoundsCheckFailed { .. } => msg!("indexing out of bounds: the len is {$len} but the index is {$index}"),
DivisionByZero => "dividing by zero".into(),
RemainderByZero => "calculating the remainder with a divisor of zero".into(),
DivisionOverflow => "overflow in signed division (dividing MIN by -1)".into(),
RemainderOverflow => "overflow in signed remainder (dividing MIN by -1)".into(),
PointerArithOverflow => "overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize`".into(),
ArithOverflow { .. } => inline_fluent!("arithmetic overflow in `{$intrinsic}`"),
ShiftOverflow { .. } => inline_fluent!("overflowing shift by {$shift_amount} in `{$intrinsic}`"),
ArithOverflow { .. } => msg!("arithmetic overflow in `{$intrinsic}`"),
ShiftOverflow { .. } => msg!("overflowing shift by {$shift_amount} in `{$intrinsic}`"),
InvalidMeta(InvalidMetaKind::SliceTooBig) => "invalid metadata in wide pointer: slice is bigger than largest supported object".into(),
InvalidMeta(InvalidMetaKind::TooBig) => "invalid metadata in wide pointer: total size is bigger than largest supported object".into(),
UnterminatedCString(_) => "reading a null-terminated string starting at {$pointer} with no null found before end of allocation".into(),
PointerUseAfterFree(_, _) => inline_fluent!(
PointerUseAfterFree(_, _) => msg!(
"{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
*[Dereferenceable] pointer not dereferenceable
}: {$alloc_id} has been freed, so this pointer is dangling"
),
PointerOutOfBounds { .. } => inline_fluent!(
PointerOutOfBounds { .. } => msg!(
"{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
@ -708,7 +708,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
}
}"
),
DanglingIntPointer { addr: 0, .. } => inline_fluent!(
DanglingIntPointer { addr: 0, .. } => msg!(
"{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
@ -728,7 +728,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
*[x] be dereferenceable for {$inbounds_size} bytes
}
}, but got null pointer"),
DanglingIntPointer { .. } => inline_fluent!(
DanglingIntPointer { .. } => msg!(
"{$operation ->
[MemoryAccess] memory access failed
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
@ -748,34 +748,34 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
*[x] be dereferenceable for {$inbounds_size} bytes
}
}, but got {$pointer} which is a dangling pointer (it has no provenance)"),
AlignmentCheckFailed { .. } => inline_fluent!(
AlignmentCheckFailed { .. } => msg!(
"{$msg ->
[AccessedPtr] accessing memory
*[other] accessing memory based on pointer
} with alignment {$has}, but alignment {$required} is required"
),
WriteToReadOnly(_) => inline_fluent!("writing to {$allocation} which is read-only"),
DerefFunctionPointer(_) => inline_fluent!("accessing {$allocation} which contains a function"),
DerefVTablePointer(_) => inline_fluent!("accessing {$allocation} which contains a vtable"),
DerefTypeIdPointer(_) => inline_fluent!("accessing {$allocation} which contains a `TypeId`"),
InvalidBool(_) => inline_fluent!("interpreting an invalid 8-bit value as a bool: 0x{$value}"),
InvalidChar(_) => inline_fluent!("interpreting an invalid 32-bit value as a char: 0x{$value}"),
InvalidTag(_) => inline_fluent!("enum value has invalid tag: {$tag}"),
InvalidFunctionPointer(_) => inline_fluent!("using {$pointer} as function pointer but it does not point to a function"),
InvalidVTablePointer(_) => inline_fluent!("using {$pointer} as vtable pointer but it does not point to a vtable"),
InvalidVTableTrait { .. } => inline_fluent!("using vtable for `{$vtable_dyn_type}` but `{$expected_dyn_type}` was expected"),
InvalidStr(_) => inline_fluent!("this string is not valid UTF-8: {$err}"),
WriteToReadOnly(_) => msg!("writing to {$allocation} which is read-only"),
DerefFunctionPointer(_) => msg!("accessing {$allocation} which contains a function"),
DerefVTablePointer(_) => msg!("accessing {$allocation} which contains a vtable"),
DerefTypeIdPointer(_) => msg!("accessing {$allocation} which contains a `TypeId`"),
InvalidBool(_) => msg!("interpreting an invalid 8-bit value as a bool: 0x{$value}"),
InvalidChar(_) => msg!("interpreting an invalid 32-bit value as a char: 0x{$value}"),
InvalidTag(_) => msg!("enum value has invalid tag: {$tag}"),
InvalidFunctionPointer(_) => msg!("using {$pointer} as function pointer but it does not point to a function"),
InvalidVTablePointer(_) => msg!("using {$pointer} as vtable pointer but it does not point to a vtable"),
InvalidVTableTrait { .. } => msg!("using vtable for `{$vtable_dyn_type}` but `{$expected_dyn_type}` was expected"),
InvalidStr(_) => msg!("this string is not valid UTF-8: {$err}"),
InvalidUninitBytes(None) => "using uninitialized data, but this operation requires initialized memory".into(),
InvalidUninitBytes(Some(_)) => inline_fluent!("reading memory at {$alloc}{$access}, but memory is uninitialized at {$uninit}, and this operation requires initialized memory"),
InvalidUninitBytes(Some(_)) => msg!("reading memory at {$alloc}{$access}, but memory is uninitialized at {$uninit}, and this operation requires initialized memory"),
DeadLocal => "accessing a dead local variable".into(),
ScalarSizeMismatch(_) => inline_fluent!("scalar size mismatch: expected {$target_size} bytes but got {$data_size} bytes instead"),
ScalarSizeMismatch(_) => msg!("scalar size mismatch: expected {$target_size} bytes but got {$data_size} bytes instead"),
UninhabitedEnumVariantWritten(_) => "writing discriminant of an uninhabited enum variant".into(),
UninhabitedEnumVariantRead(_) => "read discriminant of an uninhabited enum variant".into(),
InvalidNichedEnumVariantWritten { .. } => {
inline_fluent!("trying to set discriminant of a {$ty} to the niched variant, but the value does not match")
msg!("trying to set discriminant of a {$ty} to the niched variant, but the value does not match")
}
AbiMismatchArgument { .. } => inline_fluent!("calling a function whose parameter #{$arg_idx} has type {$callee_ty} passing argument of type {$caller_ty}"),
AbiMismatchReturn { .. } => inline_fluent!("calling a function with return type {$callee_ty} passing return place of type {$caller_ty}"),
AbiMismatchArgument { .. } => msg!("calling a function whose parameter #{$arg_idx} has type {$callee_ty} passing argument of type {$caller_ty}"),
AbiMismatchReturn { .. } => msg!("calling a function with return type {$callee_ty} passing return place of type {$caller_ty}"),
}
}
@ -920,29 +920,25 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
match self.kind {
PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => {
inline_fluent!(
"{$front_matter}: encountered a box pointing to uninhabited type {$ty}"
)
msg!("{$front_matter}: encountered a box pointing to uninhabited type {$ty}")
}
PtrToUninhabited { ptr_kind: PointerKind::Ref(_), .. } => {
inline_fluent!(
"{$front_matter}: encountered a reference pointing to uninhabited type {$ty}"
)
msg!("{$front_matter}: encountered a reference pointing to uninhabited type {$ty}")
}
PointerAsInt { .. } => {
inline_fluent!("{$front_matter}: encountered a pointer, but {$expected}")
msg!("{$front_matter}: encountered a pointer, but {$expected}")
}
PartialPointer => {
msg!("{$front_matter}: encountered a partial pointer or a mix of pointers")
}
PartialPointer => inline_fluent!(
"{$front_matter}: encountered a partial pointer or a mix of pointers"
),
MutableRefToImmutable => {
inline_fluent!(
msg!(
"{$front_matter}: encountered mutable reference or box pointing to read-only memory"
)
}
NullFnPtr { .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
@ -950,84 +946,78 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
)
}
NeverVal => {
inline_fluent!("{$front_matter}: encountered a value of the never type `!`")
msg!("{$front_matter}: encountered a value of the never type `!`")
}
NonnullPtrMaybeNull { .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a maybe-null pointer, but expected something that is definitely non-zero"
)
}
PtrOutOfRange { .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a pointer with unknown absolute address, but expected something that is definitely {$in_range}"
)
}
OutOfRange { .. } => {
inline_fluent!(
"{$front_matter}: encountered {$value}, but expected something {$in_range}"
)
msg!("{$front_matter}: encountered {$value}, but expected something {$in_range}")
}
UnsafeCellInImmutable => {
inline_fluent!("{$front_matter}: encountered `UnsafeCell` in read-only memory")
msg!("{$front_matter}: encountered `UnsafeCell` in read-only memory")
}
UninhabitedVal { .. } => {
inline_fluent!("{$front_matter}: encountered a value of uninhabited type `{$ty}`")
msg!("{$front_matter}: encountered a value of uninhabited type `{$ty}`")
}
InvalidEnumTag { .. } => {
inline_fluent!(
"{$front_matter}: encountered {$value}, but expected a valid enum tag"
)
msg!("{$front_matter}: encountered {$value}, but expected a valid enum tag")
}
UninhabitedEnumVariant => {
inline_fluent!("{$front_matter}: encountered an uninhabited enum variant")
msg!("{$front_matter}: encountered an uninhabited enum variant")
}
Uninit { .. } => {
inline_fluent!("{$front_matter}: encountered uninitialized memory, but {$expected}")
msg!("{$front_matter}: encountered uninitialized memory, but {$expected}")
}
InvalidVTablePtr { .. } => {
inline_fluent!(
"{$front_matter}: encountered {$value}, but expected a vtable pointer"
)
msg!("{$front_matter}: encountered {$value}, but expected a vtable pointer")
}
InvalidMetaWrongTrait { .. } => {
inline_fluent!(
msg!(
"{$front_matter}: wrong trait in wide pointer vtable: expected `{$expected_dyn_type}`, but encountered `{$vtable_dyn_type}`"
)
}
InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Box } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered invalid box metadata: slice is bigger than largest supported object"
)
}
InvalidMetaSliceTooLarge { ptr_kind: PointerKind::Ref(_) } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered invalid reference metadata: slice is bigger than largest supported object"
)
}
InvalidMetaTooLarge { ptr_kind: PointerKind::Box } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered invalid box metadata: total size is bigger than largest supported object"
)
}
InvalidMetaTooLarge { ptr_kind: PointerKind::Ref(_) } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered invalid reference metadata: total size is bigger than largest supported object"
)
}
UnalignedPtr { ptr_kind: PointerKind::Ref(_), .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})"
)
}
UnalignedPtr { ptr_kind: PointerKind::Box, .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})"
)
}
NullPtr { ptr_kind: PointerKind::Box, .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
@ -1035,7 +1025,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
)
}
NullPtr { ptr_kind: PointerKind::Ref(_), .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
@ -1043,66 +1033,59 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
)
}
DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => {
inline_fluent!(
"{$front_matter}: encountered a dangling box ({$pointer} has no provenance)"
)
msg!("{$front_matter}: encountered a dangling box ({$pointer} has no provenance)")
}
DanglingPtrNoProvenance { ptr_kind: PointerKind::Ref(_), .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a dangling reference ({$pointer} has no provenance)"
)
}
DanglingPtrOutOfBounds { ptr_kind: PointerKind::Box } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a dangling box (going beyond the bounds of its allocation)"
)
}
DanglingPtrOutOfBounds { ptr_kind: PointerKind::Ref(_) } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered a dangling reference (going beyond the bounds of its allocation)"
)
}
DanglingPtrUseAfterFree { ptr_kind: PointerKind::Box } => {
inline_fluent!("{$front_matter}: encountered a dangling box (use-after-free)")
msg!("{$front_matter}: encountered a dangling box (use-after-free)")
}
DanglingPtrUseAfterFree { ptr_kind: PointerKind::Ref(_) } => {
inline_fluent!("{$front_matter}: encountered a dangling reference (use-after-free)")
msg!("{$front_matter}: encountered a dangling reference (use-after-free)")
}
InvalidBool { .. } => {
inline_fluent!("{$front_matter}: encountered {$value}, but expected a boolean")
msg!("{$front_matter}: encountered {$value}, but expected a boolean")
}
InvalidChar { .. } => {
inline_fluent!(
msg!(
"{$front_matter}: encountered {$value}, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)"
)
}
InvalidFnPtr { .. } => {
inline_fluent!(
"{$front_matter}: encountered {$value}, but expected a function pointer"
)
msg!("{$front_matter}: encountered {$value}, but expected a function pointer")
}
}
}
fn add_args<G: EmissionGuarantee>(self, err: &mut Diag<'_, G>) {
use rustc_errors::inline_fluent;
use rustc_errors::msg;
use rustc_middle::mir::interpret::ValidationErrorKind::*;
if let PointerAsInt { .. } | PartialPointer = self.kind {
err.help(inline_fluent!("this code performed an operation that depends on the underlying bytes representing a pointer"));
err.help(inline_fluent!("the absolute address of a pointer is not known at compile-time, so such operations are not supported"));
err.help(msg!("this code performed an operation that depends on the underlying bytes representing a pointer"));
err.help(msg!("the absolute address of a pointer is not known at compile-time, so such operations are not supported"));
}
let message = if let Some(path) = self.path {
err.dcx.eagerly_translate_to_string(
inline_fluent!("constructing invalid value at {$path}"),
msg!("constructing invalid value at {$path}"),
[("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
)
} else {
err.dcx.eagerly_translate_to_string(
inline_fluent!("constructing invalid value"),
[].into_iter(),
)
err.dcx.eagerly_translate_to_string(msg!("constructing invalid value"), [].into_iter())
};
err.arg("front_matter", message);
@ -1115,17 +1098,17 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
let WrappingRange { start: lo, end: hi } = r;
assert!(hi <= max_hi);
let msg = if lo > hi {
inline_fluent!("less or equal to {$hi}, or greater or equal to {$lo}")
msg!("less or equal to {$hi}, or greater or equal to {$lo}")
} else if lo == hi {
inline_fluent!("equal to {$lo}")
msg!("equal to {$lo}")
} else if lo == 0 {
assert!(hi < max_hi, "should not be printing if the range covers everything");
inline_fluent!("less or equal to {$hi}")
msg!("less or equal to {$hi}")
} else if hi == max_hi {
assert!(lo > 0, "should not be printing if the range covers everything");
inline_fluent!("greater or equal to {$lo}")
msg!("greater or equal to {$lo}")
} else {
inline_fluent!("in the range {$lo}..={$hi}")
msg!("in the range {$lo}..={$hi}")
};
let args = [
@ -1143,17 +1126,17 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
}
PointerAsInt { expected } | Uninit { expected } => {
let msg = match expected {
ExpectedKind::Reference => inline_fluent!("expected a reference"),
ExpectedKind::Box => inline_fluent!("expected a box"),
ExpectedKind::RawPtr => inline_fluent!("expected a raw pointer"),
ExpectedKind::InitScalar => inline_fluent!("expected initialized scalar value"),
ExpectedKind::Bool => inline_fluent!("expected a boolean"),
ExpectedKind::Char => inline_fluent!("expected a unicode scalar value"),
ExpectedKind::Float => inline_fluent!("expected a floating point number"),
ExpectedKind::Int => inline_fluent!("expected an integer"),
ExpectedKind::FnPtr => inline_fluent!("expected a function pointer"),
ExpectedKind::EnumTag => inline_fluent!("expected a valid enum tag"),
ExpectedKind::Str => inline_fluent!("expected a string"),
ExpectedKind::Reference => msg!("expected a reference"),
ExpectedKind::Box => msg!("expected a box"),
ExpectedKind::RawPtr => msg!("expected a raw pointer"),
ExpectedKind::InitScalar => msg!("expected initialized scalar value"),
ExpectedKind::Bool => msg!("expected a boolean"),
ExpectedKind::Char => msg!("expected a unicode scalar value"),
ExpectedKind::Float => msg!("expected a floating point number"),
ExpectedKind::Int => msg!("expected an integer"),
ExpectedKind::FnPtr => msg!("expected a function pointer"),
ExpectedKind::EnumTag => msg!("expected a valid enum tag"),
ExpectedKind::Str => msg!("expected a string"),
};
let msg = err.dcx.eagerly_translate_to_string(msg, [].into_iter());
err.arg("expected", msg);
@ -1207,14 +1190,14 @@ impl ReportErrorExt for UnsupportedOpInfo {
}
UnsupportedOpInfo::UnsizedLocal => "unsized locals are not supported".into(),
UnsupportedOpInfo::ReadPartialPointer(_) => {
inline_fluent!("unable to read parts of a pointer from memory at {$ptr}")
msg!("unable to read parts of a pointer from memory at {$ptr}")
}
UnsupportedOpInfo::ReadPointerAsInt(_) => "unable to turn pointer into integer".into(),
UnsupportedOpInfo::ThreadLocalStatic(_) => {
inline_fluent!("cannot access thread local static `{$did}`")
msg!("cannot access thread local static `{$did}`")
}
UnsupportedOpInfo::ExternStatic(_) => {
inline_fluent!("cannot access extern static `{$did}`")
msg!("cannot access extern static `{$did}`")
}
}
.into()

View file

@ -6,7 +6,7 @@ use std::borrow::Cow;
use either::{Left, Right};
use rustc_abi::{self as abi, ExternAbi, FieldIdx, Integer, VariantIdx};
use rustc_data_structures::assert_matches;
use rustc_errors::inline_fluent;
use rustc_errors::msg;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
use rustc_middle::ty::{self, AdtDef, Instance, Ty, VariantDef};
@ -297,9 +297,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
// Find next caller arg.
let Some((caller_arg, caller_abi)) = caller_args.next() else {
throw_ub_custom!(inline_fluent!(
"calling a function with fewer arguments than it requires"
));
throw_ub_custom!(msg!("calling a function with fewer arguments than it requires"));
};
assert_eq!(caller_arg.layout().layout, caller_abi.layout.layout);
// Sadly we cannot assert that `caller_arg.layout().ty` and `caller_abi.layout.ty` are
@ -366,7 +364,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if caller_fn_abi.conv != callee_fn_abi.conv {
throw_ub_custom!(
rustc_errors::inline_fluent!(
rustc_errors::msg!(
"calling a function with calling convention \"{$callee_conv}\" using calling convention \"{$caller_conv}\""
),
callee_conv = format!("{}", callee_fn_abi.conv),
@ -499,9 +497,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
"mismatch between callee ABI and callee body arguments"
);
if caller_args.next().is_some() {
throw_ub_custom!(inline_fluent!(
"calling a function with more arguments than it expected"
));
throw_ub_custom!(msg!("calling a function with more arguments than it expected"));
}
// Don't forget to check the return type!
if !self.check_argument_compat(&caller_fn_abi.ret, &callee_fn_abi.ret)? {
@ -701,7 +697,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let vtable_entries = self.vtable_entries(receiver_trait.principal(), dyn_ty);
let Some(ty::VtblEntry::Method(fn_inst)) = vtable_entries.get(idx).copied() else {
// FIXME(fee1-dead) these could be variants of the UB info enum instead of this
throw_ub_custom!(inline_fluent!(
throw_ub_custom!(msg!(
"`dyn` call trying to call something that is not a method"
));
};
@ -900,7 +896,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
);
if unwinding && self.frame_idx() == 0 {
throw_ub_custom!(inline_fluent!("unwinding past the topmost frame of the stack"));
throw_ub_custom!(msg!("unwinding past the topmost frame of the stack"));
}
// Get out the return value. Must happen *before* the frame is popped as we have to get the

View file

@ -2,7 +2,7 @@ use rustc_abi::{FieldIdx, Integer};
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_apfloat::{Float, FloatConvert};
use rustc_data_structures::assert_matches;
use rustc_errors::inline_fluent;
use rustc_errors::msg;
use rustc_middle::mir::CastKind;
use rustc_middle::mir::interpret::{InterpResult, PointerArithmetic, Scalar};
use rustc_middle::ty::adjustment::PointerCoercion;
@ -139,7 +139,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
assert_eq!(cast_ty, dest.layout.ty); // we otherwise ignore `cast_ty` enirely...
if src.layout.size != dest.layout.size {
throw_ub_custom!(
inline_fluent!(
msg!(
"transmuting from {$src_bytes}-byte type to {$dest_bytes}-byte type: `{$src}` -> `{$dest}`"
),
src_bytes = src.layout.size.bytes(),

View file

@ -1,7 +1,7 @@
use either::{Left, Right};
use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout};
use rustc_data_structures::debug_assert_matches;
use rustc_errors::{DiagCtxtHandle, inline_fluent};
use rustc_errors::{DiagCtxtHandle, msg};
use rustc_hir::def_id::DefId;
use rustc_hir::limit::Limit;
use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo};
@ -555,7 +555,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
mir::UnwindAction::Cleanup(block) => Left(mir::Location { block, statement_index: 0 }),
mir::UnwindAction::Continue => Right(self.frame_mut().body.span),
mir::UnwindAction::Unreachable => {
throw_ub_custom!(inline_fluent!(
throw_ub_custom!(msg!(
"unwinding past a stack frame that does not allow unwinding"
));
}

View file

@ -7,7 +7,7 @@ mod simd;
use rustc_abi::{FIRST_VARIANT, FieldIdx, HasDataLayout, Size, VariantIdx};
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_data_structures::assert_matches;
use rustc_errors::inline_fluent;
use rustc_errors::msg;
use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint};
@ -443,7 +443,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
_ => {
// Not into the same allocation -- this is UB.
throw_ub_custom!(
inline_fluent!(
msg!(
"`{$name}` called on two different pointers that are not both derived from the same allocation"
),
name = intrinsic_name,
@ -466,7 +466,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// a < b
if intrinsic_name == sym::ptr_offset_from_unsigned {
throw_ub_custom!(
inline_fluent!(
msg!(
"`ptr_offset_from_unsigned` called when first pointer has smaller {$is_addr ->
[true] address
*[false] offset
@ -483,7 +483,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let dist = val.to_target_isize(self)?;
if dist >= 0 || i128::from(dist) == self.pointer_size().signed_int_min() {
throw_ub_custom!(
inline_fluent!(
msg!(
"`{$name}` called when first pointer is too far before second"
),
name = intrinsic_name,
@ -497,7 +497,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// because they were more than isize::MAX apart.
if dist < 0 {
throw_ub_custom!(
inline_fluent!(
msg!(
"`{$name}` called when first pointer is too far ahead of second"
),
name = intrinsic_name,
@ -518,12 +518,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
&& a_alloc_id == b_alloc_id
{
err_ub_custom!(
inline_fluent!("`{$name}` called on two different pointers where the memory range between them is not in-bounds of an allocation"),
msg!("`{$name}` called on two different pointers where the memory range between them is not in-bounds of an allocation"),
name = intrinsic_name,
)
} else {
err_ub_custom!(
inline_fluent!("`{$name}` called on two different pointers that are not both derived from the same allocation"),
msg!("`{$name}` called on two different pointers that are not both derived from the same allocation"),
name = intrinsic_name,
)
}
@ -538,7 +538,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
.map_err_kind(|_| {
// Make the error more specific.
err_ub_custom!(
inline_fluent!("`{$name}` called on two different pointers that are not both derived from the same allocation"),
msg!("`{$name}` called on two different pointers that are not both derived from the same allocation"),
name = intrinsic_name,
)
})?;
@ -768,7 +768,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let op = self.eval_operand(op, None)?;
let cond = self.read_scalar(&op)?.to_bool()?;
if !cond {
throw_ub_custom!(inline_fluent!("`assume` called with `false`"));
throw_ub_custom!(msg!("`assume` called with `false`"));
}
interp_ok(())
}
@ -798,7 +798,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let bits_out = match name {
sym::ctpop => u128::from(bits.count_ones()),
sym::ctlz_nonzero | sym::cttz_nonzero if bits == 0 => {
throw_ub_custom!(inline_fluent!("`{$name}` called on 0"), name = name,);
throw_ub_custom!(msg!("`{$name}` called on 0"), name = name,);
}
sym::ctlz | sym::ctlz_nonzero => u128::from(bits.leading_zeros()) - extra,
sym::cttz | sym::cttz_nonzero => u128::from((bits << extra).trailing_zeros()) - extra,
@ -831,7 +831,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// sign does not matter for 0 test, so `to_bits` is fine
if rem.to_scalar().to_bits(a.layout.size)? != 0 {
throw_ub_custom!(
inline_fluent!("exact_div: {$a} cannot be divided by {$b} without remainder"),
msg!("exact_div: {$a} cannot be divided by {$b} without remainder"),
a = format!("{a}"),
b = format!("{b}")
)
@ -916,7 +916,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let size = self.compute_size_in_bytes(size, count).ok_or_else(|| {
err_ub_custom!(
inline_fluent!("overflow computing total size of `{$name}`"),
msg!("overflow computing total size of `{$name}`"),
name = if nonoverlapping { "copy_nonoverlapping" } else { "copy" }
)
})?;
@ -980,10 +980,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// `checked_mul` enforces a too small bound (the correct one would probably be target_isize_max),
// but no actual allocation can be big enough for the difference to be noticeable.
let len = self.compute_size_in_bytes(layout.size, count).ok_or_else(|| {
err_ub_custom!(
inline_fluent!("overflow computing total size of `{$name}`"),
name = name
)
err_ub_custom!(msg!("overflow computing total size of `{$name}`"), name = name)
})?;
let bytes = std::iter::repeat_n(byte, len.bytes_usize());

View file

@ -15,7 +15,7 @@ use rustc_abi::{Align, HasDataLayout, Size};
use rustc_ast::Mutability;
use rustc_data_structures::assert_matches;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_errors::inline_fluent;
use rustc_errors::msg;
use rustc_middle::mir::display_allocation;
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_middle::{bug, throw_ub_format};
@ -291,7 +291,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let (alloc_id, offset, _prov) = self.ptr_get_alloc_id(ptr, 0)?;
if offset.bytes() != 0 {
throw_ub_custom!(
inline_fluent!(
msg!(
"{$kind ->
[dealloc] deallocating
[realloc] reallocating
@ -377,7 +377,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if offset.bytes() != 0 {
throw_ub_custom!(
inline_fluent!(
msg!(
"{$kind ->
[dealloc] deallocating
[realloc] reallocating
@ -394,7 +394,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
return Err(match self.tcx.try_get_global_alloc(alloc_id) {
Some(GlobalAlloc::Function { .. }) => {
err_ub_custom!(
inline_fluent!(
msg!(
"deallocating {$alloc_id}, which is {$kind ->
[fn] a function
[vtable] a vtable
@ -408,7 +408,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
Some(GlobalAlloc::VTable(..)) => {
err_ub_custom!(
inline_fluent!(
msg!(
"deallocating {$alloc_id}, which is {$kind ->
[fn] a function
[vtable] a vtable
@ -422,7 +422,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
Some(GlobalAlloc::TypeId { .. }) => {
err_ub_custom!(
inline_fluent!(
msg!(
"deallocating {$alloc_id}, which is {$kind ->
[fn] a function
[vtable] a vtable
@ -436,7 +436,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
err_ub_custom!(
inline_fluent!(
msg!(
"deallocating {$alloc_id}, which is {$kind ->
[fn] a function
[vtable] a vtable
@ -454,14 +454,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
};
if alloc.mutability.is_not() {
throw_ub_custom!(
inline_fluent!("deallocating immutable allocation {$alloc}"),
alloc = alloc_id,
);
throw_ub_custom!(msg!("deallocating immutable allocation {$alloc}"), alloc = alloc_id,);
}
if alloc_kind != kind {
throw_ub_custom!(
inline_fluent!(
msg!(
"deallocating {$alloc}, which is {$alloc_kind} memory, using {$kind} deallocation operation"
),
alloc = alloc_id,
@ -472,7 +469,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if let Some((size, align)) = old_size_and_align {
if size != alloc.size() || align != alloc.align {
throw_ub_custom!(
inline_fluent!(
msg!(
"incorrect layout on deallocation: {$alloc} has size {$size} and alignment {$align}, but gave size {$size_found} and alignment {$align_found}"
),
alloc = alloc_id,
@ -1593,7 +1590,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if (src_offset <= dest_offset && src_offset + size > dest_offset)
|| (dest_offset <= src_offset && dest_offset + size > src_offset)
{
throw_ub_custom!(inline_fluent!(
throw_ub_custom!(msg!(
"`copy_nonoverlapping` called on overlapping ranges"
));
}