Skip to content

Commit 30fa84e

Browse files
Add TyCtxtAt::{ty_error, ty_error_with_message}
1 parent a99ae95 commit 30fa84e

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/librustc_middle/ty/context.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ use crate::middle::stability;
1313
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
1414
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
1515
use crate::traits;
16+
use crate::ty::query::{self, TyCtxtAt};
1617
use crate::ty::steal::Steal;
1718
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
1819
use crate::ty::TyKind::*;
1920
use crate::ty::{
20-
self, query, AdtDef, AdtKind, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid,
21-
DefIdTree, ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy,
22-
IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
21+
self, AdtDef, AdtKind, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid, DefIdTree,
22+
ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntVar,
23+
IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
2324
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
2425
TyVid, TypeAndMut,
2526
};
@@ -2652,6 +2653,21 @@ impl<'tcx> TyCtxt<'tcx> {
26522653
}
26532654
}
26542655

2656+
impl TyCtxtAt<'tcx> {
2657+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
2658+
#[track_caller]
2659+
pub fn ty_error(self) -> Ty<'tcx> {
2660+
self.tcx.ty_error_with_message(self.span, "TyKind::Error constructed but no error reported")
2661+
}
2662+
2663+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
2664+
/// ensure it gets used.
2665+
#[track_caller]
2666+
pub fn ty_error_with_message(self, msg: &str) -> Ty<'tcx> {
2667+
self.tcx.ty_error_with_message(self.span, msg)
2668+
}
2669+
}
2670+
26552671
pub trait InternAs<T: ?Sized, R> {
26562672
type Output;
26572673
fn intern_with<F>(self, f: F) -> Self::Output

0 commit comments

Comments
 (0)