about summary refs log tree commit diff
path: root/compiler/rustc_error_codes/src
diff options
context:
space:
mode:
authorRyan Levick <me@ryanlevick.com>2021-03-18 13:22:25 +0100
committerRyan Levick <me@ryanlevick.com>2021-04-08 15:36:28 +0200
commit152c86211b4e79634dc4b811d59bb3166d106ca5 (patch)
treeaab58af3ec9ac2ed0822071d39bef7c05ec785b7 /compiler/rustc_error_codes/src
parent1d84947bb568ab7652fb0e04d6f0f1bdaaaf489a (diff)
downloadrust-152c86211b4e79634dc4b811d59bb3166d106ca5.tar.gz
rust-152c86211b4e79634dc4b811d59bb3166d106ca5.zip
Proper format for error code explanations
Diffstat (limited to 'compiler/rustc_error_codes/src')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0782.md21
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0783.md22
2 files changed, 30 insertions, 13 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0782.md b/compiler/rustc_error_codes/src/error_codes/E0782.md
index 933e37763f6..63c48506e7f 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0782.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0782.md
@@ -1,17 +1,26 @@
 Trait objects must include the `dyn` keyword.
 
-Trait objects are a way to call methods on types that are not known until
-runtime but conform to some trait.
-
-In the following code the trait object should be formed with
-`Box<dyn Foo>`, but `dyn` is left off.
+Erroneous code example:
 
-```no_run
+```edition2021,compile_fail,E782
 trait Foo {}
 fn test(arg: Box<Foo>) {}
 ```
 
+Trait objects are a way to call methods on types that are not known until
+runtime but conform to some trait.
+
+Trait objects should be formed with `Box<dyn Foo>`, but in the code above
+`dyn` is left off.
+
 This makes it harder to see that `arg` is a trait object and not a
 simply a heap allocated type called `Foo`.
 
+To fix this issue, add `dyn` before the trait name.
+
+```
+trait Foo {}
+fn test(arg: Box<dyn Foo>) {}
+```
+
 This used to be allowed before edition 2021, but is now an error.
diff --git a/compiler/rustc_error_codes/src/error_codes/E0783.md b/compiler/rustc_error_codes/src/error_codes/E0783.md
index 73c19cd7f02..41989b3ba2f 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0783.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0783.md
@@ -1,18 +1,26 @@
 The range pattern `...` is no longer allowed.
 
+Erroneous code example:
+
+```edition2021,compile_fail,E782
+fn main() {
+    match 2u8 {
+        0...9 => println!("Got a number less than 10"),
+        _ => println!("Got a number 10 or more")
+    }
+}
+```
+
 Older Rust code using previous editions allowed `...` to stand for exclusive
 ranges which are now signified using `..=`.
 
-The following code use to compile, but now it now longer does.
+To make this code compile replace the `...` with `..=`.
 
-```no_run
+```
 fn main() {
-    let n = 2u8;
-    match n {
-        ...9 => println!("Got a number less than 10"),
+    match 2u8 {
+        0..=9 => println!("Got a number less than 10"),
         _ => println!("Got a number 10 or more")
     }
 }
 ```
-
-To make this code compile replace the `...` with `..=`.