Skip to content

Commit 9b4db69

Browse files
committed
Auto merge of #73176 - LeSeulArtichaut:tyctxtat-err, r=eddyb
Add `TyCtxtAt::{ty_error, ty_error_with_message}` ~~Only e2d957d was added, the rest comes from #70551.~~ I was unsure where to put the implementation for those methods, please tell me if there is a better place for it. Closes #72619, ~~blocked on #70551~~. r? @eddyb cc @mark-i-m, maybe this should be part of #70551? If so feel free to cherry-pick or ask me to file a PR against your fork.
2 parents 009551f + 30fa84e commit 9b4db69

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
};
@@ -2615,6 +2616,21 @@ impl<'tcx> TyCtxt<'tcx> {
26152616
}
26162617
}
26172618

2619+
impl TyCtxtAt<'tcx> {
2620+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
2621+
#[track_caller]
2622+
pub fn ty_error(self) -> Ty<'tcx> {
2623+
self.tcx.ty_error_with_message(self.span, "TyKind::Error constructed but no error reported")
2624+
}
2625+
2626+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
2627+
/// ensure it gets used.
2628+
#[track_caller]
2629+
pub fn ty_error_with_message(self, msg: &str) -> Ty<'tcx> {
2630+
self.tcx.ty_error_with_message(self.span, msg)
2631+
}
2632+
}
2633+
26182634
pub trait InternAs<T: ?Sized, R> {
26192635
type Output;
26202636
fn intern_with<F>(self, f: F) -> Self::Output

0 commit comments

Comments
 (0)