about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-01-26 15:39:19 +0000
committervarkor <github@varkor.com>2018-01-26 15:39:19 +0000
commitadcb37e275ee9b06114d4debdfe453cbc89b7716 (patch)
treeb6e7d4d1e026bd1e3c156756ab31982825e27ae6
parent6461532afa8ec554e1d40d5887a2de60aa658199 (diff)
downloadrust-adcb37e275ee9b06114d4debdfe453cbc89b7716.tar.gz
rust-adcb37e275ee9b06114d4debdfe453cbc89b7716.zip
Add clarifying comment regarding the trailing type of a block
-rw-r--r--src/librustc_mir/build/block.rs4
-rw-r--r--src/test/run-pass/never-type-rvalues.rs2
2 files changed, 5 insertions, 1 deletions
diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs
index f8718c36ede..ef30b1e4522 100644
--- a/src/librustc_mir/build/block.rs
+++ b/src/librustc_mir/build/block.rs
@@ -143,6 +143,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
         if let Some(expr) = expr {
             unpack!(block = this.into(destination, block, expr));
         } else {
+            // If a block has no trailing expression, then it is given an implicit return type.
+            // This return type is usually `()`, unless the block is diverging, in which case the
+            // return type is `!`. For the unit type, we need to actually return the unit, but in
+            // the case of `!`, no return value is required, as the block will never return.
             let tcx = this.hir.tcx();
             let ty = destination.ty(&this.local_decls, tcx).to_ty(tcx);
             if ty.is_nil() {
diff --git a/src/test/run-pass/never-type-rvalues.rs b/src/test/run-pass/never-type-rvalues.rs
index 9bf003ee1dd..bda288f4086 100644
--- a/src/test/run-pass/never-type-rvalues.rs
+++ b/src/test/run-pass/never-type-rvalues.rs
@@ -1,4 +1,4 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //