From 9969e833b616d2d0e549d9ed7aee6836ca571d9c Mon Sep 17 00:00:00 2001 From: David Tolnay <dtolnay@gmail.com> Date: Sat, 13 Jan 2024 17:41:00 -0800 Subject: [PATCH 1/3] Use a consistent name for the mascot constant --- src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5782ac5..2ff0f9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ use unicode_width::UnicodeWidthStr; const ENDSL: &[u8] = b"| "; const ENDSR: &[u8] = b" |\n"; #[cfg(not(feature = "clippy"))] -const FERRIS: &[u8] = br#" +const MASCOT: &[u8] = br#" \ \ _~^~^~_ @@ -21,7 +21,7 @@ const FERRIS: &[u8] = br#" "#; #[cfg(feature = "clippy")] -const CLIPPY: &[u8] = br#" +const MASCOT: &[u8] = br#" \ \ __ @@ -139,10 +139,7 @@ where } // mascot - #[cfg(feature = "clippy")] - write_buffer.extend_from_slice(CLIPPY); - #[cfg(not(feature = "clippy"))] - write_buffer.extend_from_slice(FERRIS); + write_buffer.extend_from_slice(MASCOT); writer.write_all(&write_buffer) } From 9fc62d686c3d95337fe2b177b7b9432323af7e3d Mon Sep 17 00:00:00 2001 From: David Tolnay <dtolnay@gmail.com> Date: Sat, 13 Jan 2024 17:43:01 -0800 Subject: [PATCH 2/3] Remove conditional compilation from mascot constants Using #[cfg(...)] is not ideal here because it harms compile-time checking. For example, in order to be sure there isn't a type error, one must separately compile with and without "clippy" when making changes to the crate. Rust supports `if` in constants since version 1.46.0. --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2ff0f9e..4944e99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,18 +10,17 @@ use unicode_width::UnicodeWidthStr; // Constants! :D const ENDSL: &[u8] = b"| "; const ENDSR: &[u8] = b" |\n"; -#[cfg(not(feature = "clippy"))] -const MASCOT: &[u8] = br#" +const MASCOT: &[u8] = if !cfg!(feature = "clippy") { + br#" \ \ _~^~^~_ \) / o o \ (/ '_ - _' / '-----' \ -"#; - -#[cfg(feature = "clippy")] -const MASCOT: &[u8] = br#" +"# +} else { + br#" \ \ __ @@ -33,7 +32,8 @@ const MASCOT: &[u8] = br#" || || |\_/| \___/ -"#; +"# +}; const NEWLINE: u8 = b'\n'; const DASH: u8 = b'-'; const UNDERSCORE: u8 = b'_'; From 6b7d31edfc0543d5379884b3152d0f2f89b1efa6 Mon Sep 17 00:00:00 2001 From: David Tolnay <dtolnay@gmail.com> Date: Sat, 30 Mar 2024 09:37:50 -0700 Subject: [PATCH 3/3] Flip mascots to avoid an inverted condition --- src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4944e99..96a5f89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,16 +10,7 @@ use unicode_width::UnicodeWidthStr; // Constants! :D const ENDSL: &[u8] = b"| "; const ENDSR: &[u8] = b" |\n"; -const MASCOT: &[u8] = if !cfg!(feature = "clippy") { - br#" - \ - \ - _~^~^~_ - \) / o o \ (/ - '_ - _' - / '-----' \ -"# -} else { +const MASCOT: &[u8] = if cfg!(feature = "clippy") { br#" \ \ @@ -33,6 +24,15 @@ const MASCOT: &[u8] = if !cfg!(feature = "clippy") { |\_/| \___/ "# +} else { + br#" + \ + \ + _~^~^~_ + \) / o o \ (/ + '_ - _' + / '-----' \ +"# }; const NEWLINE: u8 = b'\n'; const DASH: u8 = b'-';