mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 14:02:57 +00:00
Make type_var_origin take a vid
This commit is contained in:
parent
fc1e7ceb4b
commit
5accaf3af4
@ -517,9 +517,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UncoveredTyParamCollector<'_, 'tcx> {
|
||||
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) {
|
||||
return;
|
||||
}
|
||||
let Some(origin) = self.infcx.type_var_origin(ty) else {
|
||||
let ty::Infer(ty::TyVar(vid)) = *ty.kind() else {
|
||||
return ty.super_visit_with(self);
|
||||
};
|
||||
let origin = self.infcx.type_var_origin(vid);
|
||||
if let Some(def_id) = origin.param_def_id {
|
||||
self.uncovered_params.insert(def_id);
|
||||
}
|
||||
@ -546,9 +547,10 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for TyVarReplacer<'cx, 'tcx> {
|
||||
if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) {
|
||||
return ty;
|
||||
}
|
||||
let Some(origin) = self.infcx.type_var_origin(ty) else {
|
||||
let ty::Infer(ty::TyVar(vid)) = *ty.kind() else {
|
||||
return ty.super_fold_with(self);
|
||||
};
|
||||
let origin = self.infcx.type_var_origin(vid);
|
||||
if let Some(def_id) = origin.param_def_id {
|
||||
// The generics of an `impl` don't have a parent, we can index directly.
|
||||
let index = self.generics.param_def_id_to_index[&def_id];
|
||||
|
@ -175,7 +175,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
||||
};
|
||||
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
|
||||
|
||||
let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP);
|
||||
let span = ty.ty_vid().map_or(DUMMY_SP, |vid| self.infcx.type_var_origin(vid).span);
|
||||
self.demand_eqtype(span, ty, fallback);
|
||||
self.fallback_has_occurred.set(true);
|
||||
true
|
||||
|
@ -338,8 +338,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindAmbiguousParameter<'_, 'tcx> {
|
||||
type Result = ControlFlow<ty::GenericArg<'tcx>>;
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
|
||||
if let Some(origin) = self.0.type_var_origin(ty)
|
||||
&& let Some(def_id) = origin.param_def_id
|
||||
if let ty::Infer(ty::TyVar(vid)) = *ty.kind()
|
||||
&& let Some(def_id) = self.0.type_var_origin(vid).param_def_id
|
||||
&& let generics = self.0.tcx.generics_of(self.1)
|
||||
&& let Some(index) = generics.param_def_id_to_index(self.0.tcx, def_id)
|
||||
&& let Some(arg) =
|
||||
|
@ -718,17 +718,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
t.fold_with(&mut self.freshener())
|
||||
}
|
||||
|
||||
/// Returns the origin of the type variable identified by `vid`, or `None`
|
||||
/// if this is not a type variable.
|
||||
/// Returns the origin of the type variable identified by `vid`.
|
||||
///
|
||||
/// No attempt is made to resolve `ty`.
|
||||
pub fn type_var_origin(&self, ty: Ty<'tcx>) -> Option<TypeVariableOrigin> {
|
||||
match *ty.kind() {
|
||||
ty::Infer(ty::TyVar(vid)) => {
|
||||
Some(self.inner.borrow_mut().type_variables().var_origin(vid))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
/// No attempt is made to resolve `vid` to its root variable.
|
||||
pub fn type_var_origin(&self, vid: TyVid) -> TypeVariableOrigin {
|
||||
self.inner.borrow_mut().type_variables().var_origin(vid)
|
||||
}
|
||||
|
||||
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx> {
|
||||
|
Loading…
Reference in New Issue
Block a user