Skip to content

Commit 3478b16

Browse files
committed
rustc_const_eval: remove huge error imports
1 parent 4442f13 commit 3478b16

File tree

1 file changed

+35
-37
lines changed
  • compiler/rustc_const_eval/src/transform/check_consts

1 file changed

+35
-37
lines changed

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ use rustc_span::{BytePos, Pos, Span, Symbol};
2222
use rustc_trait_selection::traits::SelectionContext;
2323

2424
use super::ConstCx;
25-
use crate::errors::{
26-
InteriorMutabilityBorrow, InteriorMutableDataRefer, MutDerefErr, NonConstFmtMacroCall,
27-
NonConstFnCall, NonConstOpErr, PanicNonStrErr, RawPtrToIntErr, StaticAccessErr,
28-
TransientMutBorrowErr, TransientMutBorrowErrRaw, UnallowedFnPointerCall,
29-
UnallowedHeapAllocations, UnallowedInlineAsm, UnallowedMutableRefs, UnallowedMutableRefsRaw,
30-
UnallowedOpInConstContext, UnstableConstFn,
31-
};
25+
use crate::errors;
3226
use crate::util::{call_kind, CallDesugaringKind, CallKind};
3327

3428
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -99,7 +93,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
9993
ccx: &ConstCx<'_, 'tcx>,
10094
span: Span,
10195
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
102-
ccx.tcx.sess.create_err(UnallowedFnPointerCall { span, kind: ccx.const_kind() })
96+
ccx.tcx.sess.create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
10397
}
10498
}
10599

@@ -303,10 +297,11 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
303297
diag_trait(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span)));
304298
err
305299
}
306-
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => {
307-
ccx.tcx.sess.create_err(NonConstFmtMacroCall { span, kind: ccx.const_kind() })
308-
}
309-
_ => ccx.tcx.sess.create_err(NonConstFnCall {
300+
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => ccx
301+
.tcx
302+
.sess
303+
.create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind() }),
304+
_ => ccx.tcx.sess.create_err(errors::NonConstFnCall {
310305
span,
311306
def_path_str: ccx.tcx.def_path_str_with_substs(callee, substs),
312307
kind: ccx.const_kind(),
@@ -351,7 +346,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
351346
let mut err = ccx
352347
.tcx
353348
.sess
354-
.create_err(UnstableConstFn { span, def_path: ccx.tcx.def_path_str(def_id) });
349+
.create_err(errors::UnstableConstFn { span, def_path: ccx.tcx.def_path_str(def_id) });
355350

356351
if ccx.is_const_stable_const_fn() {
357352
err.help("const-stable functions can only call other const-stable functions");
@@ -387,11 +382,11 @@ impl<'tcx> NonConstOp<'tcx> for Generator {
387382
let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind());
388383
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
389384
ccx.tcx.sess.create_feature_err(
390-
UnallowedOpInConstContext { span, msg },
385+
errors::UnallowedOpInConstContext { span, msg },
391386
sym::const_async_blocks,
392387
)
393388
} else {
394-
ccx.tcx.sess.create_err(UnallowedOpInConstContext { span, msg })
389+
ccx.tcx.sess.create_err(errors::UnallowedOpInConstContext { span, msg })
395390
}
396391
}
397392
}
@@ -404,7 +399,7 @@ impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
404399
ccx: &ConstCx<'_, 'tcx>,
405400
span: Span,
406401
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
407-
ccx.tcx.sess.create_err(UnallowedHeapAllocations {
402+
ccx.tcx.sess.create_err(errors::UnallowedHeapAllocations {
408403
span,
409404
kind: ccx.const_kind(),
410405
teach: ccx.tcx.sess.teach(&error_code!(E0010)).then_some(()),
@@ -420,7 +415,7 @@ impl<'tcx> NonConstOp<'tcx> for InlineAsm {
420415
ccx: &ConstCx<'_, 'tcx>,
421416
span: Span,
422417
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
423-
ccx.tcx.sess.create_err(UnallowedInlineAsm { span, kind: ccx.const_kind() })
418+
ccx.tcx.sess.create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() })
424419
}
425420
}
426421

@@ -471,7 +466,9 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
471466
ccx: &ConstCx<'_, 'tcx>,
472467
span: Span,
473468
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
474-
ccx.tcx.sess.create_feature_err(InteriorMutabilityBorrow { span }, sym::const_refs_to_cell)
469+
ccx.tcx
470+
.sess
471+
.create_feature_err(errors::InteriorMutabilityBorrow { span }, sym::const_refs_to_cell)
475472
}
476473
}
477474

@@ -488,14 +485,14 @@ impl<'tcx> NonConstOp<'tcx> for CellBorrow {
488485
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
489486
// FIXME: Maybe a more elegant solution to this if else case
490487
if let hir::ConstContext::Static(_) = ccx.const_kind() {
491-
ccx.tcx.sess.create_err(InteriorMutableDataRefer {
488+
ccx.tcx.sess.create_err(errors::InteriorMutableDataRefer {
492489
span,
493490
opt_help: Some(()),
494491
kind: ccx.const_kind(),
495492
teach: ccx.tcx.sess.teach(&error_code!(E0492)).then_some(()),
496493
})
497494
} else {
498-
ccx.tcx.sess.create_err(InteriorMutableDataRefer {
495+
ccx.tcx.sess.create_err(errors::InteriorMutableDataRefer {
499496
span,
500497
opt_help: None,
501498
kind: ccx.const_kind(),
@@ -528,12 +525,12 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
528525
span: Span,
529526
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
530527
match self.0 {
531-
hir::BorrowKind::Raw => ccx.tcx.sess.create_err(UnallowedMutableRefsRaw {
528+
hir::BorrowKind::Raw => ccx.tcx.sess.create_err(errors::UnallowedMutableRefsRaw {
532529
span,
533530
kind: ccx.const_kind(),
534531
teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
535532
}),
536-
hir::BorrowKind::Ref => ccx.tcx.sess.create_err(UnallowedMutableRefs {
533+
hir::BorrowKind::Ref => ccx.tcx.sess.create_err(errors::UnallowedMutableRefs {
537534
span,
538535
kind: ccx.const_kind(),
539536
teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
@@ -557,14 +554,14 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
557554
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
558555
let kind = ccx.const_kind();
559556
match self.0 {
560-
hir::BorrowKind::Raw => ccx
561-
.tcx
562-
.sess
563-
.create_feature_err(TransientMutBorrowErrRaw { span, kind }, sym::const_mut_refs),
564-
hir::BorrowKind::Ref => ccx
565-
.tcx
566-
.sess
567-
.create_feature_err(TransientMutBorrowErr { span, kind }, sym::const_mut_refs),
557+
hir::BorrowKind::Raw => ccx.tcx.sess.create_feature_err(
558+
errors::TransientMutBorrowErrRaw { span, kind },
559+
sym::const_mut_refs,
560+
),
561+
hir::BorrowKind::Ref => ccx.tcx.sess.create_feature_err(
562+
errors::TransientMutBorrowErr { span, kind },
563+
sym::const_mut_refs,
564+
),
568565
}
569566
}
570567
}
@@ -586,9 +583,10 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
586583
ccx: &ConstCx<'_, 'tcx>,
587584
span: Span,
588585
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
589-
ccx.tcx
590-
.sess
591-
.create_feature_err(MutDerefErr { span, kind: ccx.const_kind() }, sym::const_mut_refs)
586+
ccx.tcx.sess.create_feature_err(
587+
errors::MutDerefErr { span, kind: ccx.const_kind() },
588+
sym::const_mut_refs,
589+
)
592590
}
593591
}
594592

@@ -601,7 +599,7 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
601599
ccx: &ConstCx<'_, 'tcx>,
602600
span: Span,
603601
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
604-
ccx.tcx.sess.create_err(PanicNonStrErr { span })
602+
ccx.tcx.sess.create_err(errors::PanicNonStrErr { span })
605603
}
606604
}
607605

@@ -652,7 +650,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
652650
ccx: &ConstCx<'_, 'tcx>,
653651
span: Span,
654652
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
655-
ccx.tcx.sess.create_err(RawPtrToIntErr { span })
653+
ccx.tcx.sess.create_err(errors::RawPtrToIntErr { span })
656654
}
657655
}
658656

@@ -673,7 +671,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
673671
ccx: &ConstCx<'_, 'tcx>,
674672
span: Span,
675673
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
676-
ccx.tcx.sess.create_err(StaticAccessErr {
674+
ccx.tcx.sess.create_err(errors::StaticAccessErr {
677675
span,
678676
kind: ccx.const_kind(),
679677
teach: ccx.tcx.sess.teach(&error_code!(E0013)).then_some(()),
@@ -690,7 +688,7 @@ impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
690688
ccx: &ConstCx<'_, 'tcx>,
691689
span: Span,
692690
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
693-
ccx.tcx.sess.create_err(NonConstOpErr { span })
691+
ccx.tcx.sess.create_err(errors::NonConstOpErr { span })
694692
}
695693
}
696694

0 commit comments

Comments
 (0)