Skip to content

Commit 688cbad

Browse files
committed
Lookup region variable origin instead of choosing one
1 parent 2d48ffa commit 688cbad

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/librustc/infer/fudge.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5050
/// unified.
5151
pub fn fudge_inference_if_ok<T, E, F>(
5252
&self,
53-
origin: &RegionVariableOrigin,
5453
f: F,
5554
) -> Result<T, E> where
5655
F: FnOnce() -> Result<T, E>,
5756
T: TypeFoldable<'tcx>,
5857
{
59-
debug!("fudge_inference_if_ok(origin={:?})", origin);
58+
debug!("fudge_inference_if_ok()");
6059

6160
let (mut fudger, value) = self.probe(|snapshot| {
6261
match f() {
@@ -88,7 +87,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
8887
int_vars,
8988
float_vars,
9089
region_vars,
91-
origin,
9290
};
9391

9492
Ok((fudger, value))
@@ -120,8 +118,7 @@ pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
120118
type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
121119
int_vars: Range<IntVid>,
122120
float_vars: Range<FloatVid>,
123-
region_vars: Range<RegionVid>,
124-
origin: &'a RegionVariableOrigin,
121+
region_vars: FxHashMap<RegionVid, RegionVariableOrigin>,
125122
}
126123

127124
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>
167164
}
168165

169166
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
170-
match *r {
171-
ty::ReVar(vid) if self.region_vars.contains(&vid) => {
172-
self.infcx.next_region_var(self.origin.clone())
167+
if let ty::ReVar(vid) = r {
168+
if let Some(&origin) = self.region_vars.get(&vid) {
169+
return self.infcx.next_region_var(origin);
173170
}
174-
_ => r,
175171
}
172+
r
176173
}
177174
}

src/librustc/infer/region_constraints/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::ty::{Region, RegionVid};
1616

1717
use std::collections::BTreeMap;
1818
use std::{cmp, fmt, mem, u32};
19-
use std::ops::Range;
2019

2120
mod leak_check;
2221

@@ -841,8 +840,16 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
841840
}
842841
}
843842

844-
pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Range<RegionVid> {
845-
self.unification_table.vars_since_snapshot(&mark.region_snapshot)
843+
pub fn vars_since_snapshot(
844+
&self,
845+
mark: &RegionSnapshot,
846+
) -> FxHashMap<RegionVid, RegionVariableOrigin> {
847+
let range = self.unification_table.vars_since_snapshot(&mark.region_snapshot);
848+
(range.start.index()..range.end.index()).map(|index| {
849+
let vid = ty::RegionVid::from(index);
850+
let origin = self.var_infos[vid].origin.clone();
851+
(vid, origin)
852+
}).collect()
846853
}
847854

848855
/// See [`RegionInference::region_constraints_added_in_snapshot`].

src/librustc_typeck/check/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
9292
use rustc::hir::itemlikevisit::ItemLikeVisitor;
9393
use crate::middle::lang_items;
9494
use crate::namespace::Namespace;
95-
use rustc::infer::{self, InferCtxt, InferOk, InferResult, RegionVariableOrigin};
95+
use rustc::infer::{self, InferCtxt, InferOk, InferResult};
9696
use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
9797
use rustc_data_structures::indexed_vec::Idx;
9898
use rustc_data_structures::sync::Lrc;
@@ -3229,8 +3229,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32293229
Some(ret) => ret,
32303230
None => return Vec::new()
32313231
};
3232-
let origin = RegionVariableOrigin::Coercion(call_span);
3233-
let expect_args = self.fudge_inference_if_ok(&origin, || {
3232+
let expect_args = self.fudge_inference_if_ok(|| {
32343233
// Attempt to apply a subtyping relationship between the formal
32353234
// return type (likely containing type variables if the function
32363235
// is polymorphic) and the expected return type.

0 commit comments

Comments
 (0)