Skip to content

Commit ecbd8c3

Browse files
committed
Auto merge of #28369 - ebfull:fix-higher-ranked, r=nikomatsakis
Fixes #28279. Currently `common_supertype(*mut for<'a> Fn(&'a usize), *mut for<'a> Fn(&'a usize) + 'static)` equals `*mut Fn(&usize)` which seems to be caused by `higher_ranked_sub()` allowing region variables to escape the comparison. This prevents inference from working properly with stuff like `Rc<Fn(&T)>`. r? @nikomatsakis
2 parents 9c1aaeb + e567cb5 commit ecbd8c3

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/librustc/middle/infer/equate.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use middle::ty::{self, Ty};
1717
use middle::ty::TyVar;
1818
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
1919

20+
/// Ensures `a` is made equal to `b`. Returns `a` on success.
2021
pub struct Equate<'a, 'tcx: 'a> {
2122
fields: CombineFields<'a, 'tcx>
2223
}
@@ -68,7 +69,8 @@ impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx> {
6869
}
6970

7071
_ => {
71-
combine::super_combine_tys(self.fields.infcx, self, a, b)
72+
try!(combine::super_combine_tys(self.fields.infcx, self, a, b));
73+
Ok(a)
7274
}
7375
}
7476
}

src/librustc/middle/infer/sub.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use middle::ty::TyVar;
1818
use middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
1919
use std::mem;
2020

21-
/// "Greatest lower bound" (common subtype)
21+
/// Ensures `a` is made a subtype of `b`. Returns `a` on success.
2222
pub struct Sub<'a, 'tcx: 'a> {
2323
fields: CombineFields<'a, 'tcx>,
2424
}
@@ -90,7 +90,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx> {
9090
}
9191

9292
_ => {
93-
combine::super_combine_tys(self.fields.infcx, self, a, b)
93+
try!(combine::super_combine_tys(self.fields.infcx, self, a, b));
94+
Ok(a)
9495
}
9596
}
9697
}

src/test/run-pass/issue-28279.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 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+
use std::rc::Rc;
12+
13+
fn test1() -> Rc<for<'a> Fn(&'a usize) + 'static> {
14+
if let Some(_) = Some(1) {
15+
loop{}
16+
} else {
17+
loop{}
18+
}
19+
}
20+
21+
fn test2() -> *mut for<'a> Fn(&'a usize) + 'static {
22+
if let Some(_) = Some(1) {
23+
loop{}
24+
} else {
25+
loop{}
26+
}
27+
}
28+
29+
fn main() {}
30+

0 commit comments

Comments
 (0)