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

+1
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

+1
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

+3-2
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

+10-3
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

+5-5
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

+1-1
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

+4-3
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

+5-5
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

+1-1
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

+1-1
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;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Foo for A {}
1919
struct B<'a>(&'a (Foo+'a));
2020

2121
fn foo<'a>(a: &Foo) -> B<'a> {
22-
B(a) //~ ERROR cannot infer an appropriate lifetime
22+
B(a) //~ ERROR 22:5: 22:9: explicit lifetime required in the type of `a` [E0621]
2323
}
2424

2525
fn main() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Parser<'a> {
2525
impl<'a> Parser<'a> {
2626
pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
2727
Parser { lexer: lexer }
28-
//~^ ERROR cannot infer an appropriate lifetime
28+
//~^ ERROR 27:25: 27:30: explicit lifetime required in the type of `lexer` [E0621]
2929
}
3030
}
3131

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ trait TraversesWorld {
2121
fn attemptTraverse(&self, room: &Room, directionStr: &str) -> Result<&Room, &str> {
2222
let direction = str_to_direction(directionStr);
2323
let maybe_room = room.direction_to_room.get(&direction);
24-
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
2524
match maybe_room {
2625
Some(entry) => Ok(entry),
26+
//~^ ERROR 25:28: 25:37: lifetime mismatch [E0623]
2727
_ => Err("Direction does not exist in room.")
2828
}
2929
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct thing<'a, Q:'a> {
1313
}
1414

1515
fn thing<'a,Q>(x: &Q) -> thing<'a,Q> {
16-
thing{ x: x } //~ ERROR cannot infer
16+
thing{ x: x } //~ ERROR 16:5: 16:18: explicit lifetime required in the type of `x` [E0621]
1717
}
1818

1919
fn main() {

src/test/compile-fail/issue-40288-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ fn prove_static<T: 'static + ?Sized>(_: &'static T) {}
1212

1313
fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
1414
let mut out = [x];
15-
//~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
1615
{
1716
let slice: &mut [_] = &mut out;
1817
slice[0] = y;
1918
}
2019
out[0]
20+
//~^ ERROR 19:5: 19:11: explicit lifetime required in the type of `y` [E0621]
2121
}
2222

2323
struct Struct<T, U: ?Sized> {
@@ -27,12 +27,12 @@ struct Struct<T, U: ?Sized> {
2727

2828
fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
2929
let mut out = Struct { head: x, _tail: [()] };
30-
//~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
3130
{
3231
let dst: &mut Struct<_, [()]> = &mut out;
3332
dst.head = y;
3433
}
3534
out.head
35+
//~^ ERROR 34:5: 34:13: explicit lifetime required in the type of `y` [E0621]
3636
}
3737

3838
fn main() {

src/test/compile-fail/object-lifetime-default-from-box-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn store(ss: &mut SomeStruct, b: Box<SomeTrait>) {
3838
fn store1<'b>(ss: &mut SomeStruct, b: Box<SomeTrait+'b>) {
3939
// Here we override the lifetimes explicitly, and so naturally we get an error.
4040

41-
ss.r = b; //~ ERROR cannot infer an appropriate lifetime
41+
ss.r = b; //~ ERROR 41:12: 41:13: explicit lifetime required in the type of `ss` [E0621]
4242
}
4343

4444
fn main() {

src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) {
2121
fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) {
2222
// Here we try to call `foo` but do not know that `'a` and `'b` are
2323
// related as required.
24-
a(x, y); //~ ERROR cannot infer
24+
a(x, y); //~ ERROR 24:7: 24:8: lifetime mismatch [E0623]
2525
}
2626

2727
fn d() {

src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
2323
fn c<'a,'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
2424
// Here we try to call `foo` but do not know that `'a` and `'b` are
2525
// related as required.
26-
a(x, y, z); //~ ERROR cannot infer
26+
a(x, y, z); //~ ERROR 26:7: 26:8: lifetime mismatch [E0623]
2727
}
2828

2929
fn d() {

src/test/compile-fail/regions-bounded-method-type-parameters-cross-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn call_into_maybe_owned<'x,F:IntoMaybeOwned<'x>>(f: F) {
2727

2828
fn call_bigger_region<'x, 'y>(a: Inv<'x>, b: Inv<'y>) {
2929
// Here the value provided for 'y is 'y, and hence 'y:'x does not hold.
30-
a.bigger_region(b) //~ ERROR cannot infer
30+
a.bigger_region(b) //~ ERROR 30:7: 30:20: lifetime mismatch [E0623]
3131
}
3232

3333
fn main() { }

src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn caller1<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
2727

2828
fn caller2<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
2929
// Here the value provided for 'y is 'b, and hence 'b:'a does not hold.
30-
f.method(b); //~ ERROR cannot infer
30+
f.method(b); //~ ERROR 30:7: 30:13: lifetime mismatch [E0623]
3131
}
3232

3333
fn caller3<'a,'b:'a,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {

src/test/compile-fail/regions-creating-enums3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum ast<'a> {
1414
}
1515

1616
fn mk_add_bad1<'a,'b>(x: &'a ast<'a>, y: &'b ast<'b>) -> ast<'a> {
17-
ast::add(x, y) //~ ERROR cannot infer
17+
ast::add(x, y) //~ ERROR 17:5: 17:19: lifetime mismatch [E0623]
1818
}
1919

2020
fn main() {

src/test/compile-fail/regions-free-region-ordering-callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ fn ordering1<'a, 'b>(x: &'a &'b usize) -> &'a usize {
2020

2121
fn ordering2<'a, 'b>(x: &'a &'b usize, y: &'a usize) -> &'b usize {
2222
// However, it is not safe to assume that 'b <= 'a
23-
&*y //~ ERROR cannot infer
23+
&*y //~ ERROR 23:5: 23:8: lifetime mismatch [E0623]
2424
}
2525

2626
fn ordering3<'a, 'b>(x: &'a usize, y: &'b usize) -> &'a &'b usize {
2727
// Do not infer an ordering from the return value.
2828
let z: &'b usize = &*x;
29-
//~^ ERROR cannot infer
29+
//~^ ERROR 28:24: 28:27: lifetime mismatch [E0623]
3030
panic!();
3131
}
3232

src/test/compile-fail/regions-glb-free-free.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod argparse {
2222

2323
impl<'a> Flag<'a> {
2424
pub fn set_desc(self, s: &str) -> Flag<'a> {
25-
Flag { //~ ERROR cannot infer
25+
Flag { //~ ERROR 25:13: 30:14: explicit lifetime required in the type of `s` [E0621]
2626
name: self.name,
2727
desc: s,
2828
max_count: self.max_count,

src/test/compile-fail/regions-lifetime-bounds-on-fns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) {
2121
fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) {
2222
// Here we try to call `foo` but do not know that `'a` and `'b` are
2323
// related as required.
24-
a(x, y); //~ ERROR E0495
24+
a(x, y); //~ ERROR 24:7: 24:8: lifetime mismatch [E0623]
2525
}
2626

2727
fn d() {

src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Issue #8624. Test for reborrowing with 3 levels, not just two.
1212

1313
fn copy_borrowed_ptr<'a, 'b, 'c>(p: &'a mut &'b mut &'c mut isize) -> &'b mut isize {
14-
&mut ***p //~ ERROR cannot infer
14+
&mut ***p //~ ERROR 14:5: 14:14: lifetime mismatch [E0623]
1515
}
1616

1717
fn main() {

src/test/compile-fail/regions-reborrow-from-shorter-mut-ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// for `'a` (which must be a sublifetime of `'b`).
1414

1515
fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut isize) -> &'b mut isize {
16-
&mut **p //~ ERROR cannot infer
16+
&mut **p //~ ERROR 16:5: 16:13: lifetime mismatch [E0623]
1717
}
1818

1919
fn main() {

src/test/compile-fail/variance-trait-matching.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn get<'a, G>(get: &G) -> i32
3131
// This fails to type-check because, without variance, we can't
3232
// use `G : Get<&'a i32>` as evidence that `G : Get<&'b i32>`,
3333
// even if `'a : 'b`.
34-
pick(get, &22) //~ ERROR cannot infer
34+
pick(get, &22) //~ ERROR 34:5: 34:9: explicit lifetime required in the type of `get` [E0621]
3535
}
3636

3737
fn pick<'b, G>(get: &'b G, if_odd: &'b i32) -> i32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
field: i32,
13+
}
14+
15+
fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
16+
if true {
17+
let p: &i32 = &a.field;
18+
&*p
19+
} else {
20+
&*x
21+
}
22+
}
23+
24+
fn main() { }

0 commit comments

Comments
 (0)