From 7b8df5d8fda6218f7df61e2b6e40f01cc8c980c9 Mon Sep 17 00:00:00 2001 From: dploch Date: Wed, 25 Sep 2024 11:57:55 -0400 Subject: [PATCH] ui: simplify stripping logic and get rid of warning --- cli/src/ui.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/src/ui.rs b/cli/src/ui.rs index 5b5b85d87..e70a8bb1b 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -566,8 +566,6 @@ impl Ui { .unwrap_or(false) } - #[allow(unknown_lints)] // XXX FIXME (aseipp): nightly bogons; re-test this occasionally - #[allow(clippy::assigning_clones)] pub fn prompt(&self, prompt: &str) -> io::Result { if !Self::can_prompt() { return Err(io::Error::new( @@ -580,15 +578,16 @@ impl Ui { let mut buf = String::new(); io::stdin().read_line(&mut buf)?; - if let Some(trimmed) = buf.strip_suffix('\n') { - buf = trimmed.to_owned(); - } else if buf.is_empty() { + if buf.is_empty() { return Err(io::Error::new( io::ErrorKind::UnexpectedEof, "Prompt cancelled by EOF", )); } + if let Some(trimmed) = buf.strip_suffix('\n') { + buf.truncate(trimmed.len()); + } Ok(buf) }