From e5cd75cdd3e6145363638a0cf1de51f50ea3d0a8 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 4 Apr 2017 13:43:18 -0400 Subject: [PATCH 1/3] Fix example to compile Previously, hoedown did not understand that this was an example. pulldown-cmark does. This fixes the example to be compile-able. Fixes https://github.com/rust-lang/rust/issues/40994 --- src/base64.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/base64.rs b/src/base64.rs index 86abea1..6b588bf 100644 --- a/src/base64.rs +++ b/src/base64.rs @@ -330,26 +330,26 @@ impl<'a, T: ?Sized + FromBase64> FromBase64 for &'a T { } /// Base64 decoding lookup table, generated using: -/// ```rust -/// let mut ch = 0u8; -/// loop { -/// let code = match ch { -/// b'A'...b'Z' => ch - 0x41, -/// b'a'...b'z' => ch - 0x47, -/// b'0'...b'9' => ch + 0x04, -/// b'+' | b'-' => 0x3E, -/// b'/' | b'_' => 0x3F, -/// b'=' => 0xFE, -/// b'\r' | b'\n' => 0xFD, -/// _ => 0xFF, -/// }; -/// print!("0x{:02X}, ", code); -/// if ch % 16 == 15 { println!(""); } -/// else if ch == 0xFF { break; } -/// ch += 1; -/// } -/// println!(""); +/// +/// ``` +/// let mut ch = 0u8; +/// loop { +/// let code = match ch { +/// b'A'...b'Z' => ch - 0x41, +/// b'a'...b'z' => ch - 0x47, +/// b'0'...b'9' => ch + 0x04, +/// b'+' | b'-' => 0x3E, +/// b'/' | b'_' => 0x3F, +/// b'=' => 0xFE, +/// b'\r' | b'\n' => 0xFD, +/// _ => 0xFF, +/// }; +/// print!("0x{:02X}, ", code); +/// if ch % 16 == 15 { println!(""); } +/// else if ch == 0xFF { break; } +/// ch += 1; /// } +/// println!(""); /// ``` const DECODE_TABLE: [u8; 256] = [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, From ab47be0725d88ebdd55cc69b34998c782f9417d8 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 4 Apr 2017 17:29:57 -0400 Subject: [PATCH 2/3] fix overflow --- src/base64.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/base64.rs b/src/base64.rs index 6b588bf..415da3f 100644 --- a/src/base64.rs +++ b/src/base64.rs @@ -333,7 +333,8 @@ impl<'a, T: ?Sized + FromBase64> FromBase64 for &'a T { /// /// ``` /// let mut ch = 0u8; -/// loop { +/// for ch in 0..255 { +/// let ch = ch as u8; /// let code = match ch { /// b'A'...b'Z' => ch - 0x41, /// b'a'...b'z' => ch - 0x47, From ac66d52dda1d1e91ce5c063d1579fb428e5b45ad Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 4 Apr 2017 17:35:37 -0400 Subject: [PATCH 3/3] oops i had this locally and forgot to update --- src/base64.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base64.rs b/src/base64.rs index 415da3f..5e5ce6e 100644 --- a/src/base64.rs +++ b/src/base64.rs @@ -334,7 +334,7 @@ impl<'a, T: ?Sized + FromBase64> FromBase64 for &'a T { /// ``` /// let mut ch = 0u8; /// for ch in 0..255 { -/// let ch = ch as u8; +/// let mut ch = ch as u8; /// let code = match ch { /// b'A'...b'Z' => ch - 0x41, /// b'a'...b'z' => ch - 0x47,