Lookup region variable origin instead of choosing one
This commit is contained in:
parent
2d48ffa9c6
commit
688cbad9b8
@ -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 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
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 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, '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 crate::ty::{Region, RegionVid};
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::{cmp, fmt, mem, u32};
|
||||
use std::ops::Range;
|
||||
|
||||
mod leak_check;
|
||||
|
||||
@ -841,8 +840,16 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
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::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
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 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user