about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-06-20 02:45:08 +0000
committerbors <bors@rust-lang.org>2020-06-20 02:45:08 +0000
commit033013cab3a861224fd55f494c8be1cb0349eb49 (patch)
tree1252179bcb152e2712bda63c7a51bedbf772c783 /src/librustc_error_codes/error_codes
parent34c5cd9a64d8537236626c4ccbed39a924cd38e2 (diff)
parent3e40cca65ab5b0f862a5c538a3aec5c55683688b (diff)
downloadrust-033013cab3a861224fd55f494c8be1cb0349eb49.tar.gz
rust-033013cab3a861224fd55f494c8be1cb0349eb49.zip
Auto merge of #73528 - Manishearth:rollup-7djz8nd, r=Manishearth
Rollup of 16 pull requests

Successful merges:

 - #71420 (Specialization is unsound)
 - #71899 (Refactor `try_find` a little)
 - #72689 (add str to common types)
 - #72791 (update coerce docs and unify relevant tests)
 - #72934 (forbid mutable references in all constant contexts except for const-fns)
 - #73027 (Make `need_type_info_err` more conservative)
 - #73347 (Diagnose use of incompatible sanitizers)
 - #73359 (shim.rs: avoid creating `Call` terminators calling `Self`)
 - #73399 (Clean up E0668 explanation)
 - #73436 (Clean up E0670 explanation)
 - #73440 (Add src/librustdoc as an alias for src/tools/rustdoc)
 - #73442 (pretty/mir: const value enums with no variants)
 - #73452 (Unify region variables when projecting associated types)
 - #73458 (Use alloc::Layout in DroplessArena API)
 - #73484 (Update the doc for std::prelude to the correct behavior)
 - #73506 (Bump Rustfmt and RLS)

Failed merges:

r? @ghost
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-rw-r--r--src/librustc_error_codes/error_codes/E0668.md13
-rw-r--r--src/librustc_error_codes/error_codes/E0670.md2
-rw-r--r--src/librustc_error_codes/error_codes/E0764.md39
3 files changed, 48 insertions, 6 deletions
diff --git a/src/librustc_error_codes/error_codes/E0668.md b/src/librustc_error_codes/error_codes/E0668.md
index 3b43a1bcae9..b6fedfe53fc 100644
--- a/src/librustc_error_codes/error_codes/E0668.md
+++ b/src/librustc_error_codes/error_codes/E0668.md
@@ -1,11 +1,7 @@
 Malformed inline assembly rejected by LLVM.
 
-LLVM checks the validity of the constraints and the assembly string passed to
-it. This error implies that LLVM seems something wrong with the inline
-assembly call.
+Erroneous code example:
 
-In particular, it can happen if you forgot the closing bracket of a register
-constraint (see issue #51430):
 ```compile_fail,E0668
 #![feature(llvm_asm)]
 
@@ -17,3 +13,10 @@ fn main() {
     }
 }
 ```
+
+LLVM checks the validity of the constraints and the assembly string passed to
+it. This error implies that LLVM seems something wrong with the inline
+assembly call.
+
+In particular, it can happen if you forgot the closing bracket of a register
+constraint (see issue #51430), like in the previous code example.
diff --git a/src/librustc_error_codes/error_codes/E0670.md b/src/librustc_error_codes/error_codes/E0670.md
index 2026370bec3..74c1af06cf4 100644
--- a/src/librustc_error_codes/error_codes/E0670.md
+++ b/src/librustc_error_codes/error_codes/E0670.md
@@ -1,6 +1,6 @@
 Rust 2015 does not permit the use of `async fn`.
 
-Example of erroneous code:
+Erroneous code example:
 
 ```compile_fail,E0670
 async fn foo() {}
diff --git a/src/librustc_error_codes/error_codes/E0764.md b/src/librustc_error_codes/error_codes/E0764.md
new file mode 100644
index 00000000000..e9061f988ac
--- /dev/null
+++ b/src/librustc_error_codes/error_codes/E0764.md
@@ -0,0 +1,39 @@
+Mutable references (`&mut`) can only be used in constant functions, not statics
+or constants. This limitation exists to prevent the creation of constants that
+have a mutable reference in their final value. If you had a constant of `&mut
+i32` type, you could modify the value through that reference, making the
+constant essentially mutable. While there could be a more fine-grained scheme
+in the future that allows mutable references if they are not "leaked" to the
+final value, a more conservative approach was chosen for now. `const fn` do not
+have this problem, as the borrow checker will prevent the `const fn` from
+returning new mutable references.
+
+Erroneous code example:
+
+```compile_fail,E0764
+#![feature(const_fn)]
+#![feature(const_mut_refs)]
+
+fn main() {
+    const OH_NO: &'static mut usize = &mut 1; // error!
+}
+```
+
+Remember: you cannot use a function call inside a constant or static. However,
+you can totally use it in constant functions:
+
+```
+#![feature(const_fn)]
+#![feature(const_mut_refs)]
+
+const fn foo(x: usize) -> usize {
+    let mut y = 1;
+    let z = &mut y;
+    *z += x;
+    y
+}
+
+fn main() {
+    const FOO: usize = foo(10); // ok!
+}
+```