Skip to content

Commit adcb37e

Browse files
committed
Add clarifying comment regarding the trailing type of a block
1 parent 6461532 commit adcb37e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/librustc_mir/build/block.rs

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
143143
if let Some(expr) = expr {
144144
unpack!(block = this.into(destination, block, expr));
145145
} else {
146+
// If a block has no trailing expression, then it is given an implicit return type.
147+
// This return type is usually `()`, unless the block is diverging, in which case the
148+
// return type is `!`. For the unit type, we need to actually return the unit, but in
149+
// the case of `!`, no return value is required, as the block will never return.
146150
let tcx = this.hir.tcx();
147151
let ty = destination.ty(&this.local_decls, tcx).to_ty(tcx);
148152
if ty.is_nil() {

src/test/run-pass/never-type-rvalues.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

0 commit comments

Comments
 (0)