Skip to content

Commit a66d0f8

Browse files
Rollup merge of #152186 - GuillaumeGomez:inline-diag-rustc_const_eval, r=JonathanBrouwer
Convert to inline diagnostics in `rustc_const_eval` Part of #151366. r? @JonathanBrouwer
2 parents 4fa1cdb + c682902 commit a66d0f8

16 files changed

Lines changed: 735 additions & 759 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3703,7 +3703,6 @@ dependencies = [
37033703
"rustc_ast",
37043704
"rustc_data_structures",
37053705
"rustc_errors",
3706-
"rustc_fluent_macro",
37073706
"rustc_hir",
37083707
"rustc_index",
37093708
"rustc_infer",

compiler/rustc_const_eval/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ rustc_apfloat = "0.2.0"
1111
rustc_ast = { path = "../rustc_ast" }
1212
rustc_data_structures = { path = "../rustc_data_structures" }
1313
rustc_errors = { path = "../rustc_errors" }
14-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1514
rustc_hir = { path = "../rustc_hir" }
1615
rustc_index = { path = "../rustc_index" }
1716
rustc_infer = { path = "../rustc_infer" }

compiler/rustc_const_eval/messages.ftl

Lines changed: 0 additions & 507 deletions
This file was deleted.

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use hir::{ConstContext, LangItem};
44
use rustc_errors::codes::*;
5-
use rustc_errors::{Applicability, Diag, MultiSpan};
5+
use rustc_errors::{Applicability, Diag, MultiSpan, inline_fluent};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::DefId;
88
use rustc_infer::infer::TyCtxtInferExt;
@@ -23,7 +23,7 @@ use rustc_trait_selection::traits::SelectionContext;
2323
use tracing::debug;
2424

2525
use super::ConstCx;
26-
use crate::{errors, fluent_generated};
26+
use crate::errors;
2727

2828
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2929
pub enum Status {
@@ -181,7 +181,9 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
181181
);
182182

183183
if let ConstContext::Static(_) = ccx.const_kind() {
184-
err.note(fluent_generated::const_eval_lazy_lock);
184+
err.note(inline_fluent!(
185+
"consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`"
186+
));
185187
}
186188

187189
err

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,41 @@ pub enum ConstEvalErrKind {
4343
impl MachineStopType for ConstEvalErrKind {
4444
fn diagnostic_message(&self) -> DiagMessage {
4545
use ConstEvalErrKind::*;
46+
use rustc_errors::inline_fluent;
4647

47-
use crate::fluent_generated::*;
4848
match self {
49-
ConstAccessesMutGlobal => const_eval_const_accesses_mut_global,
50-
ModifiedGlobal => const_eval_modified_global,
51-
Panic { .. } => const_eval_panic,
52-
RecursiveStatic => const_eval_recursive_static,
49+
ConstAccessesMutGlobal => "constant accesses mutable global memory".into(),
50+
ModifiedGlobal => {
51+
"modifying a static's initial value from another static's initializer".into()
52+
}
53+
Panic { .. } => inline_fluent!("evaluation panicked: {$msg}"),
54+
RecursiveStatic => {
55+
"encountered static that tried to access itself during initialization".into()
56+
}
5357
AssertFailure(x) => x.diagnostic_message(),
54-
WriteThroughImmutablePointer => const_eval_write_through_immutable_pointer,
58+
WriteThroughImmutablePointer => {
59+
inline_fluent!(
60+
"writing through a pointer that was derived from a shared (immutable) reference"
61+
)
62+
}
5563
ConstMakeGlobalPtrAlreadyMadeGlobal { .. } => {
56-
const_eval_const_make_global_ptr_already_made_global
64+
inline_fluent!(
65+
"attempting to call `const_make_global` twice on the same allocation {$alloc}"
66+
)
67+
}
68+
ConstMakeGlobalPtrIsNonHeap(_) => {
69+
inline_fluent!(
70+
"pointer passed to `const_make_global` does not point to a heap allocation: {$ptr}"
71+
)
72+
}
73+
ConstMakeGlobalWithDanglingPtr(_) => {
74+
inline_fluent!("pointer passed to `const_make_global` is dangling: {$ptr}")
75+
}
76+
ConstMakeGlobalWithOffset(_) => {
77+
inline_fluent!(
78+
"making {$ptr} global which does not point to the beginning of an object"
79+
)
5780
}
58-
ConstMakeGlobalPtrIsNonHeap(_) => const_eval_const_make_global_ptr_is_non_heap,
59-
ConstMakeGlobalWithDanglingPtr(_) => const_eval_const_make_global_with_dangling_ptr,
60-
ConstMakeGlobalWithOffset(_) => const_eval_const_make_global_with_offset,
6181
}
6282
}
6383
fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)) {

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::atomic::Ordering::Relaxed;
22

33
use either::{Left, Right};
44
use rustc_abi::{self as abi, BackendRepr};
5-
use rustc_errors::E0080;
5+
use rustc_errors::{E0080, inline_fluent};
66
use rustc_hir::def::DefKind;
77
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo};
88
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
@@ -467,7 +467,15 @@ fn report_eval_error<'tcx>(
467467
let num_frames = frames.len();
468468
// FIXME(oli-obk): figure out how to use structured diagnostics again.
469469
diag.code(E0080);
470-
diag.span_label(span, crate::fluent_generated::const_eval_error);
470+
diag.span_label(
471+
span,
472+
inline_fluent!(
473+
"evaluation of `{$instance}` failed {$num_frames ->
474+
[0] here
475+
*[other] inside this call
476+
}"
477+
),
478+
);
471479
for frame in frames {
472480
diag.subdiagnostic(frame);
473481
}
@@ -506,8 +514,8 @@ fn report_validation_error<'tcx>(
506514
move |diag, span, frames| {
507515
// FIXME(oli-obk): figure out how to use structured diagnostics again.
508516
diag.code(E0080);
509-
diag.span_label(span, crate::fluent_generated::const_eval_validation_failure);
510-
diag.note(crate::fluent_generated::const_eval_validation_failure_note);
517+
diag.span_label(span, "it is undefined behavior to use this value");
518+
diag.note("the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.");
511519
for frame in frames {
512520
diag.subdiagnostic(frame);
513521
}

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::hash::Hash;
55
use rustc_abi::{Align, Size};
66
use rustc_ast::Mutability;
77
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
8+
use rustc_errors::inline_fluent;
89
use rustc_hir::def_id::{DefId, LocalDefId};
910
use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem};
1011
use rustc_middle::mir::AssertMessage;
@@ -19,7 +20,6 @@ use tracing::debug;
1920

2021
use super::error::*;
2122
use crate::errors::{LongRunning, LongRunningWarn};
22-
use crate::fluent_generated as fluent;
2323
use crate::interpret::{
2424
self, AllocId, AllocInit, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame,
2525
GlobalAlloc, ImmTy, InterpCx, InterpResult, OpTy, PlaceTy, RangeSet, Scalar,
@@ -489,7 +489,13 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
489489
let align = match Align::from_bytes(align) {
490490
Ok(a) => a,
491491
Err(err) => throw_ub_custom!(
492-
fluent::const_eval_invalid_align_details,
492+
inline_fluent!(
493+
"invalid align passed to `{$name}`: {$align} is {$err_kind ->
494+
[not_power_of_two] not a power of 2
495+
[too_large] too large
496+
*[other] {\"\"}
497+
}"
498+
),
493499
name = "const_allocate",
494500
err_kind = err.diag_ident(),
495501
align = err.align()
@@ -513,7 +519,13 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
513519
let align = match Align::from_bytes(align) {
514520
Ok(a) => a,
515521
Err(err) => throw_ub_custom!(
516-
fluent::const_eval_invalid_align_details,
522+
inline_fluent!(
523+
"invalid align passed to `{$name}`: {$align} is {$err_kind ->
524+
[not_power_of_two] not a power of 2
525+
[too_large] too large
526+
*[other] {\"\"}
527+
}"
528+
),
517529
name = "const_deallocate",
518530
err_kind = err.diag_ident(),
519531
align = err.align()

0 commit comments

Comments
 (0)