Skip to content

Commit 5accaf3

Browse files
Make type_var_origin take a vid
1 parent fc1e7ce commit 5accaf3

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UncoveredTyParamCollector<'_, 'tcx> {
517517
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) {
518518
return;
519519
}
520-
let Some(origin) = self.infcx.type_var_origin(ty) else {
520+
let ty::Infer(ty::TyVar(vid)) = *ty.kind() else {
521521
return ty.super_visit_with(self);
522522
};
523+
let origin = self.infcx.type_var_origin(vid);
523524
if let Some(def_id) = origin.param_def_id {
524525
self.uncovered_params.insert(def_id);
525526
}
@@ -546,9 +547,10 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for TyVarReplacer<'cx, 'tcx> {
546547
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) {
547548
return ty;
548549
}
549-
let Some(origin) = self.infcx.type_var_origin(ty) else {
550+
let ty::Infer(ty::TyVar(vid)) = *ty.kind() else {
550551
return ty.super_fold_with(self);
551552
};
553+
let origin = self.infcx.type_var_origin(vid);
552554
if let Some(def_id) = origin.param_def_id {
553555
// The generics of an `impl` don't have a parent, we can index directly.
554556
let index = self.generics.param_def_id_to_index[&def_id];

compiler/rustc_hir_typeck/src/fallback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
175175
};
176176
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
177177

178-
let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP);
178+
let span = ty.ty_vid().map_or(DUMMY_SP, |vid| self.infcx.type_var_origin(vid).span);
179179
self.demand_eqtype(span, ty, fallback);
180180
self.fallback_has_occurred.set(true);
181181
true

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
338338
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindAmbiguousParameter<'_, 'tcx> {
339339
type Result = ControlFlow<ty::GenericArg<'tcx>>;
340340
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
341-
if let Some(origin) = self.0.type_var_origin(ty)
342-
&& let Some(def_id) = origin.param_def_id
341+
if let ty::Infer(ty::TyVar(vid)) = *ty.kind()
342+
&& let Some(def_id) = self.0.type_var_origin(vid).param_def_id
343343
&& let generics = self.0.tcx.generics_of(self.1)
344344
&& let Some(index) = generics.param_def_id_to_index(self.0.tcx, def_id)
345345
&& let Some(arg) =

compiler/rustc_infer/src/infer/mod.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -718,17 +718,11 @@ impl<'tcx> InferCtxt<'tcx> {
718718
t.fold_with(&mut self.freshener())
719719
}
720720

721-
/// Returns the origin of the type variable identified by `vid`, or `None`
722-
/// if this is not a type variable.
721+
/// Returns the origin of the type variable identified by `vid`.
723722
///
724-
/// No attempt is made to resolve `ty`.
725-
pub fn type_var_origin(&self, ty: Ty<'tcx>) -> Option<TypeVariableOrigin> {
726-
match *ty.kind() {
727-
ty::Infer(ty::TyVar(vid)) => {
728-
Some(self.inner.borrow_mut().type_variables().var_origin(vid))
729-
}
730-
_ => None,
731-
}
723+
/// No attempt is made to resolve `vid` to its root variable.
724+
pub fn type_var_origin(&self, vid: TyVid) -> TypeVariableOrigin {
725+
self.inner.borrow_mut().type_variables().var_origin(vid)
732726
}
733727

734728
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx> {

0 commit comments

Comments
 (0)