Skip to content

Commit 03f563a

Browse files
committed
Auto merge of #24109 - sanxiyn:diverging-closure, r=pnkfelix
Fix #23896.
2 parents 5afa270 + e78f631 commit 03f563a

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

src/librustc/middle/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>(
477477
def_id: fn_trait_def_id,
478478
substs: tcx.mk_substs(trait_substs),
479479
});
480-
ty::Binder((trait_ref, sig.0.output.unwrap()))
480+
ty::Binder((trait_ref, sig.0.output.unwrap_or(ty::mk_nil(tcx))))
481481
}
482482

483483
impl<'tcx,O:Repr<'tcx>> Repr<'tcx> for super::Obligation<'tcx, O> {

src/librustc/middle/ty.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,13 @@ impl<'tcx> FnOutput<'tcx> {
10921092
ty::FnDiverging => unreachable!()
10931093
}
10941094
}
1095+
1096+
pub fn unwrap_or(self, def: Ty<'tcx>) -> Ty<'tcx> {
1097+
match self {
1098+
ty::FnConverging(t) => t,
1099+
ty::FnDiverging => def
1100+
}
1101+
}
10951102
}
10961103

10971104
pub type PolyFnOutput<'tcx> = Binder<FnOutput<'tcx>>;

src/librustc_typeck/check/callee.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,11 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
387387
demand::eqtype(fcx, self.call_expr.span, self_arg_ty, method_arg_ty);
388388
}
389389

390+
let nilty = ty::mk_nil(fcx.tcx());
390391
demand::eqtype(fcx,
391392
self.call_expr.span,
392-
method_sig.output.unwrap(),
393-
self.fn_sig.output.unwrap());
393+
method_sig.output.unwrap_or(nilty),
394+
self.fn_sig.output.unwrap_or(nilty));
394395

395396
write_overloaded_call_method_map(fcx, self.call_expr, method_callee);
396397
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// error-pattern:oops
12+
13+
fn main() {
14+
let func = || -> ! {
15+
panic!("oops");
16+
};
17+
func();
18+
}

0 commit comments

Comments
 (0)