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.
|
/// unified.
|
||||||
pub fn fudge_inference_if_ok<T, E, F>(
|
pub fn fudge_inference_if_ok<T, E, F>(
|
||||||
&self,
|
&self,
|
||||||
origin: &RegionVariableOrigin,
|
|
||||||
f: F,
|
f: F,
|
||||||
) -> Result<T, E> where
|
) -> Result<T, E> where
|
||||||
F: FnOnce() -> Result<T, E>,
|
F: FnOnce() -> Result<T, E>,
|
||||||
T: TypeFoldable<'tcx>,
|
T: TypeFoldable<'tcx>,
|
||||||
{
|
{
|
||||||
debug!("fudge_inference_if_ok(origin={:?})", origin);
|
debug!("fudge_inference_if_ok()");
|
||||||
|
|
||||||
let (mut fudger, value) = self.probe(|snapshot| {
|
let (mut fudger, value) = self.probe(|snapshot| {
|
||||||
match f() {
|
match f() {
|
||||||
@ -88,7 +87,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||||||
int_vars,
|
int_vars,
|
||||||
float_vars,
|
float_vars,
|
||||||
region_vars,
|
region_vars,
|
||||||
origin,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((fudger, value))
|
Ok((fudger, value))
|
||||||
@ -120,8 +118,7 @@ pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
|||||||
type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
|
type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
|
||||||
int_vars: Range<IntVid>,
|
int_vars: Range<IntVid>,
|
||||||
float_vars: Range<FloatVid>,
|
float_vars: Range<FloatVid>,
|
||||||
region_vars: Range<RegionVid>,
|
region_vars: FxHashMap<RegionVid, RegionVariableOrigin>,
|
||||||
origin: &'a RegionVariableOrigin,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx> {
|
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> {
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
match *r {
|
if let ty::ReVar(vid) = r {
|
||||||
ty::ReVar(vid) if self.region_vars.contains(&vid) => {
|
if let Some(&origin) = self.region_vars.get(&vid) {
|
||||||
self.infcx.next_region_var(self.origin.clone())
|
return self.infcx.next_region_var(origin);
|
||||||
}
|
}
|
||||||
_ => r,
|
|
||||||
}
|
}
|
||||||
|
r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ use crate::ty::{Region, RegionVid};
|
|||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::{cmp, fmt, mem, u32};
|
use std::{cmp, fmt, mem, u32};
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
mod leak_check;
|
mod leak_check;
|
||||||
|
|
||||||
@ -841,8 +840,16 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Range<RegionVid> {
|
pub fn vars_since_snapshot(
|
||||||
self.unification_table.vars_since_snapshot(&mark.region_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`].
|
/// See [`RegionInference::region_constraints_added_in_snapshot`].
|
||||||
|
@ -92,7 +92,7 @@ use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
|||||||
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
||||||
use crate::middle::lang_items;
|
use crate::middle::lang_items;
|
||||||
use crate::namespace::Namespace;
|
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::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
@ -3229,8 +3229,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
Some(ret) => ret,
|
Some(ret) => ret,
|
||||||
None => return Vec::new()
|
None => return Vec::new()
|
||||||
};
|
};
|
||||||
let origin = RegionVariableOrigin::Coercion(call_span);
|
let expect_args = self.fudge_inference_if_ok(|| {
|
||||||
let expect_args = self.fudge_inference_if_ok(&origin, || {
|
|
||||||
// Attempt to apply a subtyping relationship between the formal
|
// Attempt to apply a subtyping relationship between the formal
|
||||||
// return type (likely containing type variables if the function
|
// return type (likely containing type variables if the function
|
||||||
// is polymorphic) and the expected return type.
|
// is polymorphic) and the expected return type.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user