diff options
| author | bors <bors@rust-lang.org> | 2016-06-12 03:11:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-12 03:11:36 -0700 |
| commit | b1b752655d374819064bf01ba760305ad3a1f623 (patch) | |
| tree | 9115d78163e59c059e6190bd6d11a16523ab00d5 | |
| parent | 5b09f2a1a61ba09fa4d027bc58249e29a7fde78d (diff) | |
| parent | ae755938640e4477acc77331aac2b02d0f17ac94 (diff) | |
| download | rust-b1b752655d374819064bf01ba760305ad3a1f623.tar.gz rust-b1b752655d374819064bf01ba760305ad3a1f623.zip | |
Auto merge of #34161 - kennytm:fix-E0277-format, r=GuillaumeGomez
Fix markdown formatting error of E0277, E0310 and E0502. Fix bad format we see in https://doc.rust-lang.org/nightly/error-index.html#E0277.
| -rw-r--r-- | src/librustc/diagnostics.rs | 6 | ||||
| -rw-r--r-- | src/librustc_borrowck/diagnostics.rs | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 1ba722b6bae..30dcca833f8 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1112,6 +1112,7 @@ fn main() { ``` Or in a generic context, an erroneous code example would look like: + ```compile_fail fn some_func<T>(foo: T) { println!("{:?}", foo); // error: the trait `core::fmt::Debug` is not @@ -1130,6 +1131,7 @@ we only call it with a parameter that does implement `Debug`, the compiler still rejects the function: It must work with all possible input types. In order to make this example compile, we need to restrict the generic type we're accepting: + ``` use std::fmt; @@ -1146,11 +1148,10 @@ fn main() { // struct WithoutDebug; // some_func(WithoutDebug); } +``` Rust only looks at the signature of the called function, as such it must already specify all requirements that will be used for every type parameter. -``` - "##, E0281: r##" @@ -1381,6 +1382,7 @@ denotes this will cause this error. struct Foo<T> { foo: &'static T } +``` This will compile, because it has the constraint on the type parameter: diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index 0624d72dd59..8852d17c98d 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -516,8 +516,10 @@ fn foo(a: &mut i32) { // as immutable } ``` + To fix this error, ensure that you don't have any other references to the variable before trying to access it mutably: + ``` fn bar(x: &mut i32) {} fn foo(a: &mut i32) { @@ -525,6 +527,7 @@ fn foo(a: &mut i32) { let ref y = a; // ok! } ``` + For more information on the rust ownership system, take a look at https://doc.rust-lang.org/stable/book/references-and-borrowing.html. "##, |
