提交 688cbad9 编写于 作者: V varkor

Lookup region variable origin instead of choosing one

上级 2d48ffa9
......@@ -50,13 +50,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
/// unified.
pub fn fudge_inference_if_ok<T, E, F>(
&self,
origin: &RegionVariableOrigin,
f: F,
) -> Result<T, E> where
F: FnOnce() -> Result<T, E>,
T: TypeFoldable<'tcx>,
{
debug!("fudge_inference_if_ok(origin={:?})", origin);
debug!("fudge_inference_if_ok()");
let (mut fudger, value) = self.probe(|snapshot| {
match f() {
......@@ -88,7 +87,6 @@ pub fn fudge_inference_if_ok<T, E, F>(
int_vars,
float_vars,
region_vars,
origin,
};
Ok((fudger, value))
......@@ -120,8 +118,7 @@ pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
int_vars: Range<IntVid>,
float_vars: Range<FloatVid>,
region_vars: Range<RegionVid>,
origin: &'a RegionVariableOrigin,
region_vars: FxHashMap<RegionVid, RegionVariableOrigin>,
}
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx> {
......@@ -167,11 +164,11 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
}
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
ty::ReVar(vid) if self.region_vars.contains(&vid) => {
self.infcx.next_region_var(self.origin.clone())
if let ty::ReVar(vid) = r {
if let Some(&origin) = self.region_vars.get(&vid) {
return self.infcx.next_region_var(origin);
}
_ => r,
}
r
}
}
......@@ -16,7 +16,6 @@
use std::collections::BTreeMap;
use std::{cmp, fmt, mem, u32};
use std::ops::Range;
mod leak_check;
......@@ -841,8 +840,16 @@ pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
}
}
pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Range<RegionVid> {
self.unification_table.vars_since_snapshot(&mark.region_snapshot)
pub fn vars_since_snapshot(
&self,
mark: &RegionSnapshot,
) -> FxHashMap<RegionVid, RegionVariableOrigin> {
let range = self.unification_table.vars_since_snapshot(&mark.region_snapshot);
(range.start.index()..range.end.index()).map(|index| {
let vid = ty::RegionVid::from(index);
let origin = self.var_infos[vid].origin.clone();
(vid, origin)
}).collect()
}
/// See [`RegionInference::region_constraints_added_in_snapshot`].
......
......@@ -92,7 +92,7 @@
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use crate::middle::lang_items;
use crate::namespace::Namespace;
use rustc::infer::{self, InferCtxt, InferOk, InferResult, RegionVariableOrigin};
use rustc::infer::{self, InferCtxt, InferOk, InferResult};
use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::sync::Lrc;
......@@ -3229,8 +3229,7 @@ fn expected_inputs_for_expected_output(&self,
Some(ret) => ret,
None => return Vec::new()
};
let origin = RegionVariableOrigin::Coercion(call_span);
let expect_args = self.fudge_inference_if_ok(&origin, || {
let expect_args = self.fudge_inference_if_ok(|| {
// Attempt to apply a subtyping relationship between the formal
// return type (likely containing type variables if the function
// is polymorphic) and the expected return type.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册