]> git.proxmox.com Git - rustc.git/blobdiff - src/doc/reference/src/expressions/block-expr.md
New upstream version 1.23.0+dfsg1
[rustc.git] / src / doc / reference / src / expressions / block-expr.md
index ee0d8c14d18a04698adef6d1f54bb14c9efe32ae..4ac5cbcdf19b5ae0a7d323e8063c77acf00b1d06 100644 (file)
@@ -1,5 +1,13 @@
 # Block expressions
 
+> **<sup>Syntax</sup>**  
+> _BlockExpression_ :  
+> &nbsp;&nbsp; `{`  
+> &nbsp;&nbsp; &nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>  
+> &nbsp;&nbsp; &nbsp;&nbsp; [_Statement_]<sup>\*</sup>  
+> &nbsp;&nbsp; &nbsp;&nbsp; [_Expression_]<sup>?</sup>  
+> &nbsp;&nbsp; `}`  
+
 A _block expression_ is similar to a module in terms of the declarations that
 are possible, but can also contain [statements](statements.html) and end with
 an expression. Each block conceptually introduces a new namespace scope. Use
@@ -28,7 +36,27 @@ if really needed.
 
 ## `unsafe` blocks
 
+> **<sup>Syntax</sup>**  
+> _UnsafeBlockExpression_ :  
+> &nbsp;&nbsp; `unsafe` _BlockExpression_
+
 _See [`unsafe` block](unsafe-blocks.html) for more information on when to use `unsafe`_
 
 A block of code can be prefixed with the `unsafe` keyword, to permit calling
-`unsafe` functions or dereferencing raw pointers within a safe function.
+`unsafe` functions or dereferencing raw pointers within a safe function. Examples:
+
+```rust
+unsafe {
+    let b = [13u8, 17u8];
+    let a = &b[0] as *const u8;
+    assert_eq!(*a, 13);
+    assert_eq!(*a.offset(1), 17);
+}
+
+# unsafe fn f() -> i32 { 10 }
+let a = unsafe { f() };
+```
+
+[_InnerAttribute_]: attributes.html
+[_Statement_]: statements.html
+[_Expression_]: expressions.html