Skip to content

Commit

Permalink
typeck: use NoExpectation to check return type of diverging fn
Browse files Browse the repository at this point in the history
This fixes rust-lang#35849, a regression introduced by the typeck refactoring
around TyNever/!.
  • Loading branch information
Alex Burka committed Aug 22, 2016
1 parent 4901896 commit 9d53faf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,12 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,

inherited.tables.borrow_mut().liberated_fn_sigs.insert(fn_id, fn_sig);

fcx.check_block_with_expected(body, ExpectHasType(fcx.ret_ty));
let expected = if fcx.ret_ty.is_never() {
NoExpectation
} else {
ExpectHasType(fcx.ret_ty)
};
fcx.check_block_with_expected(body, expected);

fcx
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/run-pass/diverging-fn-tail-35849.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2016 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn _assert_sizeof() -> ! {
unsafe {
::std::mem::transmute::<f64, [u8; 8]>(panic!())
}
}

fn main() { }

0 comments on commit 9d53faf

Please sign in to comment.