Skip to content

Commit 79cfce3

Browse files
committed
Auto merge of #44167 - cengizIO:master, r=nikomatsakis
Improve SubSupConflict with a named and an anonymous lifetime parameter #42701 Hello! This fixes #42701. ## UPDATE 01 Tests are producing different results between different env builds. This inconsistency might take a long time to investigate and fix. So, be patient ## UPDATE 02 Changed an `FxHashMap` with a `BTreeMap`. Inconsistency seems to be resolved for now.
2 parents fb5ba4e + f53fc57 commit 79cfce3

32 files changed

+99
-131
lines changed

src/librustc/infer/error_reporting/different_lifetimes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6060
pub fn try_report_anon_anon_conflict(&self, error: &RegionResolutionError<'tcx>) -> bool {
6161
let (span, sub, sup) = match *error {
6262
ConcreteFailure(ref origin, sub, sup) => (origin.span(), sub, sup),
63+
SubSupConflict(_, ref origin, sub, _, sup) => (origin.span(), sub, sup),
6364
_ => return false, // inapplicable
6465
};
6566

src/librustc/infer/error_reporting/named_anon_conflict.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
2121
pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'tcx>) -> bool {
2222
let (span, sub, sup) = match *error {
2323
ConcreteFailure(ref origin, sub, sup) => (origin.span(), sub, sup),
24+
SubSupConflict(_, ref origin, sub, _, sup) => (origin.span(), sub, sup),
2425
_ => return false, // inapplicable
2526
};
2627

src/librustc/infer/region_inference/graphviz.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use util::nodemap::{FxHashMap, FxHashSet};
3030

3131
use std::borrow::Cow;
3232
use std::collections::hash_map::Entry::Vacant;
33+
use std::collections::btree_map::BTreeMap;
3334
use std::env;
3435
use std::fs::File;
3536
use std::io;
@@ -124,7 +125,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
124125
struct ConstraintGraph<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
125126
graph_name: String,
126127
region_rels: &'a RegionRelations<'a, 'gcx, 'tcx>,
127-
map: &'a FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
128+
map: &'a BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
128129
node_ids: FxHashMap<Node, usize>,
129130
}
130131

@@ -264,7 +265,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
264265
}
265266
}
266267

267-
pub type ConstraintMap<'tcx> = FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>;
268+
pub type ConstraintMap<'tcx> = BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>;
268269

269270
fn dump_region_constraints_to<'a, 'gcx, 'tcx>(region_rels: &RegionRelations<'a, 'gcx, 'tcx>,
270271
map: &ConstraintMap<'tcx>,

src/librustc/infer/region_inference/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use ty::{Region, RegionVid};
2828
use ty::{ReEmpty, ReStatic, ReFree, ReEarlyBound, ReErased};
2929
use ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
3030

31+
use std::collections::BTreeMap;
3132
use std::cell::{Cell, RefCell};
3233
use std::fmt;
3334
use std::mem;
@@ -36,7 +37,7 @@ use std::u32;
3637
mod graphviz;
3738

3839
/// A constraint that influences the inference process.
39-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
40+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
4041
pub enum Constraint<'tcx> {
4142
/// One region variable is subregion of another
4243
ConstrainVarSubVar(RegionVid, RegionVid),
@@ -186,7 +187,13 @@ pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
186187
/// Constraints of the form `A <= B` introduced by the region
187188
/// checker. Here at least one of `A` and `B` must be a region
188189
/// variable.
189-
constraints: RefCell<FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>>,
190+
///
191+
/// Using `BTreeMap` because the order in which we iterate over
192+
/// these constraints can affect the way we build the region graph,
193+
/// which in turn affects the way that region errors are reported,
194+
/// leading to small variations in error output across runs and
195+
/// platforms.
196+
constraints: RefCell<BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>>,
190197

191198
/// A "verify" is something that we need to verify after inference is
192199
/// done, but which does not directly affect inference in any way.
@@ -357,7 +364,7 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
357364
tcx,
358365
var_origins: RefCell::new(Vec::new()),
359366
values: RefCell::new(None),
360-
constraints: RefCell::new(FxHashMap()),
367+
constraints: RefCell::new(BTreeMap::new()),
361368
verifys: RefCell::new(Vec::new()),
362369
givens: RefCell::new(FxHashSet()),
363370
lubs: RefCell::new(FxHashMap()),

src/librustc/ty/sty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
760760
/// is the outer fn.
761761
///
762762
/// [dbi]: http://en.wikipedia.org/wiki/De_Bruijn_index
763-
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, Copy)]
763+
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, Copy, PartialOrd, Ord)]
764764
pub struct DebruijnIndex {
765765
/// We maintain the invariant that this is never 0. So 1 indicates
766766
/// the innermost binder. To ensure this, create with `DebruijnIndex::new`.
@@ -825,7 +825,7 @@ pub type Region<'tcx> = &'tcx RegionKind;
825825
///
826826
/// [1] http://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/
827827
/// [2] http://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/
828-
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable)]
828+
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
829829
pub enum RegionKind {
830830
// Region bound in a type or fn declaration which will be
831831
// substituted 'early' -- that is, at the same time when type
@@ -871,7 +871,7 @@ pub enum RegionKind {
871871

872872
impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
873873

874-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
874+
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, PartialOrd, Ord)]
875875
pub struct EarlyBoundRegion {
876876
pub def_id: DefId,
877877
pub index: u32,
@@ -893,12 +893,12 @@ pub struct FloatVid {
893893
pub index: u32,
894894
}
895895

896-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
896+
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy, PartialOrd, Ord)]
897897
pub struct RegionVid {
898898
pub index: u32,
899899
}
900900

901-
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
901+
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
902902
pub struct SkolemizedRegionVid {
903903
pub index: u32,
904904
}

src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
3030
{
3131
// x and y here have two distinct lifetimes:
3232
let z: I::A = if cond { x } else { y };
33-
//~^ ERROR cannot infer
33+
//~^ ERROR lifetime mismatch
3434
}
3535

3636
pub fn main() {}

src/test/compile-fail/associated-types/cache/project-fn-ret-contravariant.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
5050

5151
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
5252
fn transmute<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
53-
let a = bar(foo, y); //[krisskross]~ ERROR E0495
54-
let b = bar(foo, x); //[krisskross]~ ERROR E0495
55-
(a, b)
53+
let a = bar(foo, y);
54+
let b = bar(foo, x);
55+
(a, b) //[krisskross]~ ERROR 55:5: 55:6: lifetime mismatch [E0623]
56+
//[krisskross]~^ ERROR 55:8: 55:9: lifetime mismatch [E0623]
5657
}
5758

5859
#[rustc_error]

src/test/compile-fail/associated-types/cache/project-fn-ret-invariant.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
4545
#[cfg(oneuse)] // one instantiation: BAD
4646
fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
4747
let f = foo; // <-- No consistent type can be inferred for `f` here.
48-
let a = bar(f, x); //[oneuse]~^ ERROR E0495
49-
let b = bar(f, y);
48+
let a = bar(f, x);
49+
let b = bar(f, y); //[oneuse]~ ERROR 49:19: 49:20: lifetime mismatch [E0623]
5050
(a, b)
5151
}
5252

@@ -60,9 +60,9 @@ fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
6060

6161
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
6262
fn transmute<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
63-
let a = bar(foo, y); //[krisskross]~ ERROR E0495
64-
let b = bar(foo, x); //[krisskross]~ ERROR E0495
65-
(a, b)
63+
let a = bar(foo, y); //[krisskross]~ ERROR E0623
64+
let b = bar(foo, x);
65+
(a, b) //[krisskross]~ ERROR E0623
6666
}
6767

6868
#[rustc_error]

src/test/compile-fail/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct S<'a> {
1717

1818
fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
1919
S { pointer: &mut *p.pointer }
20-
//~^ ERROR cannot infer
20+
//~^ ERROR lifetime mismatch
2121
}
2222

2323
fn main() {

src/test/compile-fail/issue-13058.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'r> Itble<'r, usize, Range<usize>> for (usize, usize) {
2222
fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
2323
{
2424
let cont_iter = cont.iter();
25-
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
25+
//~^ ERROR 24:26: 24:30: explicit lifetime required in the type of `cont` [E0621]
2626
let result = cont_iter.fold(Some(0), |state, val| {
2727
state.map_or(None, |mask| {
2828
let bit = 1 << val;

0 commit comments

Comments
 (0)