]> git.lizzy.rs Git - rust.git/commitdiff
Add clarifying comment regarding the trailing type of a block
authorvarkor <github@varkor.com>
Fri, 26 Jan 2018 15:39:19 +0000 (15:39 +0000)
committervarkor <github@varkor.com>
Fri, 26 Jan 2018 15:39:19 +0000 (15:39 +0000)
src/librustc_mir/build/block.rs
src/test/run-pass/never-type-rvalues.rs

index f8718c36ede9899c2093320a8437442323f2f2d5..ef30b1e452230df786add31df2af97b9344bda0d 100644 (file)
@@ -143,6 +143,10 @@ fn ast_block_stmts(&mut self,
         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() {
index 9bf003ee1dd3bdea137f5749a84a433dab788598..bda288f40869b225aabd345e3681d8138d4237af 100644 (file)
@@ -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.
 //