Skip to content

Commit b5718d0

Browse files
Rollup merge of #159153 - GuillaumeGomez:rename-err-to-diag, r=JonathanBrouwer
Rename `errors.rs` file to `diagnostics.rs` (12/N) Follow-up of #157485. r? @JonathanBrouwer
2 parents 2125270 + cba2097 commit b5718d0

27 files changed

Lines changed: 477 additions & 391 deletions

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use super::qualifs::{self, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
2929
use super::resolver::FlowSensitiveAnalysis;
3030
use super::{ConstCx, Qualif};
3131
use crate::check_consts::is_fn_or_trait_safe_to_expose_on_stable;
32-
use crate::errors;
32+
use crate::diagnostics;
3333

3434
type QualifResults<'mir, 'tcx, Q> =
3535
rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'tcx, Q>>;
@@ -475,7 +475,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
475475
if self.enforce_recursive_const_stability()
476476
&& !is_fn_or_trait_safe_to_expose_on_stable(self.tcx, def_id)
477477
{
478-
self.dcx().emit_err(errors::UnmarkedConstItemExposed {
478+
self.dcx().emit_err(diagnostics::UnmarkedConstItemExposed {
479479
span: self.span,
480480
def_path: self.tcx.def_path_str(def_id),
481481
});
@@ -874,7 +874,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
874874
// regular stability, and regular stability is checked separately.
875875
// However, we *do* have to worry about *recursive* const stability.
876876
if !is_const_stable && self.enforce_recursive_const_stability() {
877-
self.dcx().emit_err(errors::UnmarkedIntrinsicExposed {
877+
self.dcx().emit_err(diagnostics::UnmarkedIntrinsicExposed {
878878
span: self.span,
879879
def_path: self.tcx.def_path_str(callee),
880880
});
@@ -988,7 +988,7 @@ fn emit_unstable_in_stable_exposed_error(
988988
) -> ErrorGuaranteed {
989989
let attr_span = ccx.tcx.def_span(ccx.def_id()).shrink_to_lo();
990990

991-
ccx.dcx().emit_err(errors::UnstableInStableExposed {
991+
ccx.dcx().emit_err(diagnostics::UnstableInStableExposed {
992992
gate: gate.to_string(),
993993
span,
994994
attr_span,

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_trait_selection::traits::SelectionContext;
2323
use tracing::debug;
2424

2525
use super::ConstCx;
26-
use crate::errors;
26+
use crate::diagnostics;
2727

2828
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2929
pub enum Status {
@@ -71,7 +71,7 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug {
7171
pub(crate) struct FnCallIndirect;
7272
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
7373
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
74-
ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
74+
ccx.dcx().create_err(diagnostics::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
7575
}
7676
}
7777

@@ -90,7 +90,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallCVariadic {
9090

9191
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
9292
ccx.tcx.sess.create_feature_err(
93-
errors::NonConstCVariadicCall { span, kind: ccx.const_kind() },
93+
diagnostics::NonConstCVariadicCall { span, kind: ccx.const_kind() },
9494
sym::const_c_variadic,
9595
)
9696
}
@@ -192,7 +192,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
192192
// FIXME(const_trait_impl) revisit this
193193
if !tcx.is_const_trait_impl(data.impl_def_id) {
194194
let span = tcx.def_span(data.impl_def_id);
195-
err.subdiagnostic(errors::NonConstImplNote { span });
195+
err.subdiagnostic(diagnostics::NonConstImplNote { span });
196196
}
197197
}
198198
}
@@ -235,7 +235,7 @@ fn build_error_for_const_call<'tcx>(
235235
CallKind::Normal { desugaring: Some((kind, self_ty)), .. } => {
236236
macro_rules! error {
237237
($err:ident) => {
238-
tcx.dcx().create_err(errors::$err {
238+
tcx.dcx().create_err(diagnostics::$err {
239239
span,
240240
ty: self_ty,
241241
kind: ccx.const_kind(),
@@ -273,14 +273,14 @@ fn build_error_for_const_call<'tcx>(
273273
span_bug!(span, "calling const FnDef errored when it shouldn't");
274274
}
275275

276-
Some(errors::NonConstClosureNote::FnDef { span })
276+
Some(diagnostics::NonConstClosureNote::FnDef { span })
277277
}
278-
FnPtr(..) => Some(errors::NonConstClosureNote::FnPtr { kind }),
279-
Closure(..) => Some(errors::NonConstClosureNote::Closure { kind }),
278+
FnPtr(..) => Some(diagnostics::NonConstClosureNote::FnPtr { kind }),
279+
Closure(..) => Some(diagnostics::NonConstClosureNote::Closure { kind }),
280280
_ => None,
281281
};
282282

283-
let mut err = tcx.dcx().create_err(errors::NonConstClosure {
283+
let mut err = tcx.dcx().create_err(diagnostics::NonConstClosure {
284284
span,
285285
kind: ccx.const_kind(),
286286
note,
@@ -292,7 +292,7 @@ fn build_error_for_const_call<'tcx>(
292292
}
293293
CallKind::Operator { trait_id, self_ty, .. } => {
294294
let mut err = if let CallSource::MatchCmp = call_source {
295-
tcx.dcx().create_err(errors::NonConstMatchEq {
295+
tcx.dcx().create_err(diagnostics::NonConstMatchEq {
296296
span,
297297
kind: ccx.const_kind(),
298298
ty: self_ty,
@@ -323,7 +323,7 @@ fn build_error_for_const_call<'tcx>(
323323
{
324324
let rhs_pos = span.lo() + BytePos::from_usize(eq_idx + 2 + rhs_idx);
325325
let rhs_span = span.with_lo(rhs_pos).with_hi(rhs_pos);
326-
sugg = Some(errors::ConsiderDereferencing {
326+
sugg = Some(diagnostics::ConsiderDereferencing {
327327
deref,
328328
span: span.shrink_to_lo(),
329329
rhs_span,
@@ -333,7 +333,7 @@ fn build_error_for_const_call<'tcx>(
333333
_ => {}
334334
}
335335
}
336-
tcx.dcx().create_err(errors::NonConstOperator {
336+
tcx.dcx().create_err(diagnostics::NonConstOperator {
337337
span,
338338
kind: ccx.const_kind(),
339339
sugg,
@@ -354,7 +354,7 @@ fn build_error_for_const_call<'tcx>(
354354
None
355355
};
356356

357-
let mut err = tcx.dcx().create_err(errors::NonConstDerefCoercion {
357+
let mut err = tcx.dcx().create_err(diagnostics::NonConstDerefCoercion {
358358
span,
359359
ty: self_ty,
360360
kind: ccx.const_kind(),
@@ -367,15 +367,15 @@ fn build_error_for_const_call<'tcx>(
367367
err
368368
}
369369
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::FmtArgumentsNew) => {
370-
ccx.dcx().create_err(errors::NonConstFmtMacroCall {
370+
ccx.dcx().create_err(diagnostics::NonConstFmtMacroCall {
371371
span,
372372
kind: ccx.const_kind(),
373373
non_or_conditionally,
374374
})
375375
}
376376
_ => {
377377
let def_descr = ccx.tcx.def_descr(callee);
378-
let mut err = ccx.dcx().create_err(errors::NonConstFnCall {
378+
let mut err = ccx.dcx().create_err(diagnostics::NonConstFnCall {
379379
span,
380380
def_descr,
381381
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
@@ -471,12 +471,12 @@ impl<'tcx> NonConstOp<'tcx> for CallUnstable {
471471
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
472472
assert!(!self.feature_enabled);
473473
let mut err = if self.is_function_call {
474-
ccx.dcx().create_err(errors::UnstableConstFn {
474+
ccx.dcx().create_err(diagnostics::UnstableConstFn {
475475
span,
476476
def_path: ccx.tcx.def_path_str(self.def_id),
477477
})
478478
} else {
479-
ccx.dcx().create_err(errors::UnstableConstTrait {
479+
ccx.dcx().create_err(diagnostics::UnstableConstTrait {
480480
span,
481481
def_path: ccx.tcx.def_path_str(self.def_id),
482482
})
@@ -494,7 +494,7 @@ pub(crate) struct IntrinsicNonConst {
494494

495495
impl<'tcx> NonConstOp<'tcx> for IntrinsicNonConst {
496496
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
497-
ccx.dcx().create_err(errors::NonConstIntrinsic {
497+
ccx.dcx().create_err(diagnostics::NonConstIntrinsic {
498498
span,
499499
name: self.name,
500500
kind: ccx.const_kind(),
@@ -523,7 +523,7 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
523523
}
524524

525525
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
526-
ccx.dcx().create_err(errors::UnstableIntrinsic {
526+
ccx.dcx().create_err(diagnostics::UnstableIntrinsic {
527527
span,
528528
name: self.name,
529529
feature: self.feature,
@@ -556,9 +556,11 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
556556
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
557557
let msg = format!("{} are not allowed in {}s", self.0.to_plural_string(), ccx.const_kind());
558558
if let Status::Unstable { gate, .. } = self.status_in_item(ccx) {
559-
ccx.tcx.sess.create_feature_err(errors::UnallowedOpInConstContext { span, msg }, gate)
559+
ccx.tcx
560+
.sess
561+
.create_feature_err(diagnostics::UnallowedOpInConstContext { span, msg }, gate)
560562
} else {
561-
ccx.dcx().create_err(errors::UnallowedOpInConstContext { span, msg })
563+
ccx.dcx().create_err(diagnostics::UnallowedOpInConstContext { span, msg })
562564
}
563565
}
564566
}
@@ -567,7 +569,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
567569
pub(crate) struct InlineAsm;
568570
impl<'tcx> NonConstOp<'tcx> for InlineAsm {
569571
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
570-
ccx.dcx().create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() })
572+
ccx.dcx().create_err(diagnostics::UnallowedInlineAsm { span, kind: ccx.const_kind() })
571573
}
572574
}
573575

@@ -593,15 +595,15 @@ impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {
593595

594596
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
595597
if self.needs_non_const_drop {
596-
ccx.dcx().create_err(errors::LiveDrop {
598+
ccx.dcx().create_err(diagnostics::LiveDrop {
597599
span,
598600
dropped_ty: self.dropped_ty,
599601
kind: ccx.const_kind(),
600602
dropped_at: self.dropped_at,
601603
})
602604
} else {
603605
ccx.tcx.sess.create_feature_err(
604-
errors::LiveDrop {
606+
diagnostics::LiveDrop {
605607
span,
606608
dropped_ty: self.dropped_ty,
607609
kind: ccx.const_kind(),
@@ -625,7 +627,8 @@ impl<'tcx> NonConstOp<'tcx> for EscapingCellBorrow {
625627
DiagImportance::Secondary
626628
}
627629
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
628-
ccx.dcx().create_err(errors::InteriorMutableBorrowEscaping { span, kind: ccx.const_kind() })
630+
ccx.dcx()
631+
.create_err(diagnostics::InteriorMutableBorrowEscaping { span, kind: ccx.const_kind() })
629632
}
630633
}
631634

@@ -647,7 +650,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow {
647650
}
648651

649652
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
650-
ccx.dcx().create_err(errors::MutableBorrowEscaping { span, kind: ccx.const_kind() })
653+
ccx.dcx().create_err(diagnostics::MutableBorrowEscaping { span, kind: ccx.const_kind() })
651654
}
652655
}
653656

@@ -656,7 +659,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow {
656659
pub(crate) struct PanicNonStr;
657660
impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
658661
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
659-
ccx.dcx().create_err(errors::PanicNonStrErr { span })
662+
ccx.dcx().create_err(diagnostics::PanicNonStrErr { span })
660663
}
661664
}
662665

@@ -668,7 +671,7 @@ pub(crate) struct RawPtrComparison;
668671
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
669672
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
670673
// FIXME(const_trait_impl): revert to span_bug?
671-
ccx.dcx().create_err(errors::RawPtrComparisonErr { span })
674+
ccx.dcx().create_err(diagnostics::RawPtrComparisonErr { span })
672675
}
673676
}
674677

@@ -679,7 +682,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
679682
pub(crate) struct RawPtrToIntCast;
680683
impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
681684
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
682-
ccx.dcx().create_err(errors::RawPtrToIntErr { span })
685+
ccx.dcx().create_err(diagnostics::RawPtrToIntErr { span })
683686
}
684687
}
685688

@@ -688,6 +691,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
688691
pub(crate) struct ThreadLocalAccess;
689692
impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
690693
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
691-
ccx.dcx().create_err(errors::ThreadLocalAccessErr { span })
694+
ccx.dcx().create_err(diagnostics::ThreadLocalAccessErr { span })
692695
}
693696
}

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::layout::LayoutError;
1111
use rustc_span::{DUMMY_SP, Span, Symbol};
1212

1313
use super::CompileTimeMachine;
14-
use crate::errors::{self, FrameNote};
14+
use crate::diagnostics::{self, FrameNote};
1515
use crate::interpret::{
1616
CtfeProvenance, ErrorHandled, Frame, InterpCx, InterpErrorInfo, InterpErrorKind,
1717
MachineStopType, Pointer, err_inval, err_machine_stop,
@@ -95,7 +95,7 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
9595
pub(crate) fn get_span_and_frames<'tcx>(
9696
tcx: TyCtxtAt<'tcx>,
9797
stack: &[Frame<'tcx, impl Provenance, impl Sized>],
98-
) -> (Span, Vec<errors::FrameNote>) {
98+
) -> (Span, Vec<diagnostics::FrameNote>) {
9999
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack, *tcx);
100100
// Filter out `requires_caller_location` frames.
101101
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
@@ -106,8 +106,8 @@ pub(crate) fn get_span_and_frames<'tcx>(
106106
// Add notes to the backtrace. Don't print a single-line backtrace though.
107107
if stacktrace.len() > 1 {
108108
// Helper closure to print duplicated lines.
109-
let mut add_frame = |mut frame: errors::FrameNote| {
110-
frames.push(errors::FrameNote { times: 0, ..frame.clone() });
109+
let mut add_frame = |mut frame: diagnostics::FrameNote| {
110+
frames.push(diagnostics::FrameNote { times: 0, ..frame.clone() });
111111
// Don't print [... additional calls ...] if the number of lines is small
112112
if frame.times < 3 {
113113
let times = frame.times;
@@ -118,7 +118,7 @@ pub(crate) fn get_span_and_frames<'tcx>(
118118
}
119119
};
120120

121-
let mut last_frame: Option<errors::FrameNote> = None;
121+
let mut last_frame: Option<diagnostics::FrameNote> = None;
122122
for frame_info in &stacktrace {
123123
let frame = frame_info.as_note(*tcx);
124124
match last_frame.as_mut() {
@@ -207,7 +207,7 @@ pub(super) fn report<'tcx>(
207207
{
208208
let bytes = ecx.print_alloc_bytes_for_diagnostics(alloc_id);
209209
let info = ecx.get_alloc_info(alloc_id);
210-
let raw_bytes = errors::RawBytesNote {
210+
let raw_bytes = diagnostics::RawBytesNote {
211211
size: info.size.bytes(),
212212
align: info.align.bytes(),
213213
bytes,
@@ -241,7 +241,7 @@ pub(super) fn lint<'tcx, L>(
241241
tcx: TyCtxtAt<'tcx>,
242242
machine: &CompileTimeMachine<'tcx>,
243243
lint: &'static rustc_session::lint::Lint,
244-
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
244+
decorator: impl FnOnce(Vec<diagnostics::FrameNote>) -> L,
245245
) where
246246
L: for<'a> rustc_errors::Diagnostic<'a, ()>,
247247
{

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::interpret::{
2121
InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, ReturnContinuation, create_static_alloc,
2222
intern_const_alloc_recursive, interp_ok, throw_exhaust,
2323
};
24-
use crate::{CTRL_C_RECEIVED, errors};
24+
use crate::{CTRL_C_RECEIVED, diagnostics};
2525

2626
fn retry_codegen_mode_with_postanalysis<'tcx, K: TypeVisitable<TyCtxt<'tcx>>, V>(
2727
key: ty::PseudoCanonicalInput<'tcx, K>,
@@ -161,28 +161,31 @@ fn intern_and_validate<'tcx, R: InterpretationResult<'tcx>>(
161161
Ok(()) => {}
162162
Err(InternError::DanglingPointer) => {
163163
throw_inval!(AlreadyReported(ReportedErrorInfo::non_const_eval_error(
164-
ecx.tcx
165-
.dcx()
166-
.emit_err(errors::DanglingPtrInFinal { span: ecx.tcx.span, kind: intern_kind }),
164+
ecx.tcx.dcx().emit_err(diagnostics::DanglingPtrInFinal {
165+
span: ecx.tcx.span,
166+
kind: intern_kind
167+
}),
167168
)));
168169
}
169170
Err(InternError::BadMutablePointer) => {
170171
throw_inval!(AlreadyReported(ReportedErrorInfo::non_const_eval_error(
171-
ecx.tcx
172-
.dcx()
173-
.emit_err(errors::MutablePtrInFinal { span: ecx.tcx.span, kind: intern_kind }),
172+
ecx.tcx.dcx().emit_err(diagnostics::MutablePtrInFinal {
173+
span: ecx.tcx.span,
174+
kind: intern_kind
175+
}),
174176
)));
175177
}
176178
Err(InternError::ConstAllocNotGlobal) => {
177179
throw_inval!(AlreadyReported(ReportedErrorInfo::non_const_eval_error(
178-
ecx.tcx.dcx().emit_err(errors::ConstHeapPtrInFinal { span: ecx.tcx.span }),
180+
ecx.tcx.dcx().emit_err(diagnostics::ConstHeapPtrInFinal { span: ecx.tcx.span }),
179181
)));
180182
}
181183
Err(InternError::PartialPointer) => {
182184
throw_inval!(AlreadyReported(ReportedErrorInfo::non_const_eval_error(
183-
ecx.tcx
184-
.dcx()
185-
.emit_err(errors::PartialPtrInFinal { span: ecx.tcx.span, kind: intern_kind }),
185+
ecx.tcx.dcx().emit_err(diagnostics::PartialPtrInFinal {
186+
span: ecx.tcx.span,
187+
kind: intern_kind
188+
}),
186189
)));
187190
}
188191
}
@@ -532,7 +535,7 @@ fn report_validation_error<'tcx>(
532535
let bytes = ecx.print_alloc_bytes_for_diagnostics(alloc_id);
533536
let info = ecx.get_alloc_info(alloc_id);
534537
let raw_bytes =
535-
errors::RawBytesNote { size: info.size.bytes(), align: info.align.bytes(), bytes };
538+
diagnostics::RawBytesNote { size: info.size.bytes(), align: info.align.bytes(), bytes };
536539

537540
crate::const_eval::report(ecx, error, move |diag, span, frames| {
538541
diag.span_label(span, "it is undefined behavior to use this value");

0 commit comments

Comments
 (0)