diff --git a/src/librustc/middle/infer/equate.rs b/src/librustc/middle/infer/equate.rs index cbbf73d942073..8a01f78a7580c 100644 --- a/src/librustc/middle/infer/equate.rs +++ b/src/librustc/middle/infer/equate.rs @@ -17,6 +17,7 @@ use middle::ty::{self, Ty}; use middle::ty::TyVar; use middle::ty_relate::{Relate, RelateResult, TypeRelation}; +/// Ensures `a` is made equal to `b`. Returns `a` on success. pub struct Equate<'a, 'tcx: 'a> { fields: CombineFields<'a, 'tcx> } @@ -68,7 +69,8 @@ impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx> { } _ => { - combine::super_combine_tys(self.fields.infcx, self, a, b) + try!(combine::super_combine_tys(self.fields.infcx, self, a, b)); + Ok(a) } } } diff --git a/src/librustc/middle/infer/sub.rs b/src/librustc/middle/infer/sub.rs index 4d76d613392ee..7d0cc648fd46f 100644 --- a/src/librustc/middle/infer/sub.rs +++ b/src/librustc/middle/infer/sub.rs @@ -18,7 +18,7 @@ use middle::ty::TyVar; use middle::ty_relate::{Cause, Relate, RelateResult, TypeRelation}; use std::mem; -/// "Greatest lower bound" (common subtype) +/// Ensures `a` is made a subtype of `b`. Returns `a` on success. pub struct Sub<'a, 'tcx: 'a> { fields: CombineFields<'a, 'tcx>, } @@ -90,7 +90,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx> { } _ => { - combine::super_combine_tys(self.fields.infcx, self, a, b) + try!(combine::super_combine_tys(self.fields.infcx, self, a, b)); + Ok(a) } } } diff --git a/src/test/run-pass/issue-28279.rs b/src/test/run-pass/issue-28279.rs new file mode 100644 index 0000000000000..ae40ce44d178d --- /dev/null +++ b/src/test/run-pass/issue-28279.rs @@ -0,0 +1,30 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::rc::Rc; + +fn test1() -> Rc Fn(&'a usize) + 'static> { + if let Some(_) = Some(1) { + loop{} + } else { + loop{} + } +} + +fn test2() -> *mut for<'a> Fn(&'a usize) + 'static { + if let Some(_) = Some(1) { + loop{} + } else { + loop{} + } +} + +fn main() {} +