diff --git a/Cargo.toml b/Cargo.toml index 16baab021..68fd08396 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,8 @@ panic = "warn" todo = "warn" unimplemented = "warn" dbg_macro = "warn" +# `let _ =` hides a `#[must_use]` result, such as a dropped error. +let_underscore_must_use = "warn" # Every exception names its lint with `#[expect]` and says why. allow_attributes = "warn" allow_attributes_without_reason = "warn" diff --git a/apps/auth-service/src/cli/output/mod.rs b/apps/auth-service/src/cli/output/mod.rs index 65ce04278..14bfda370 100644 --- a/apps/auth-service/src/cli/output/mod.rs +++ b/apps/auth-service/src/cli/output/mod.rs @@ -261,7 +261,7 @@ impl Output { /// it is ignored, since the command fails anyway. pub(super) fn error(&self, error: &(dyn Error + 'static)) { let causes = std::iter::successors(error.source(), |&cause| cause.source()); - let _ = if self.0.json { + (if self.0.json { self.event(&Event::Error { message: error.to_string(), causes: causes.map(ToString::to_string).collect(), @@ -276,7 +276,8 @@ impl Output { Ok(()) }) .map_err(CliError::Output) - }; + }) + .ok(); } /// Asks `question` on standard error with a `[y/N]` suffix, and reads the diff --git a/apps/auth-service/src/cli/reference.rs b/apps/auth-service/src/cli/reference.rs index a796e5d43..31aa9bc24 100644 --- a/apps/auth-service/src/cli/reference.rs +++ b/apps/auth-service/src/cli/reference.rs @@ -5,7 +5,7 @@ use super::Cli; use clap::{Arg, ArgAction, Command, CommandFactory}; use sourceorigin_common::config::GeneratedFile; -use std::fmt::Write as _; +use std::fmt::{self, Write as _}; /// The page's title and introduction, after the generated-file comment. const INTRO: &str = "\ @@ -28,7 +28,7 @@ struct Reference { impl Reference { /// Renders the page from the whole command tree. - fn render() -> String { + fn render() -> Result { let mut command = Cli::command().bin_name("auth-service"); // Building fills in each subcommand's full name and its usage. command.build(); @@ -38,8 +38,8 @@ impl Reference { `apps/auth-service/src/cli`. Do not edit it by hand. -->\n\n{INTRO}" ), }; - reference.command(&command, "auth-service"); - reference.page + reference.command(&command, "auth-service")?; + Ok(reference.page) } /// Adds `command`'s section: what it does, its usage, its arguments and @@ -47,20 +47,20 @@ impl Reference { /// `invocation` is how to call it: its path with the arguments its parents /// take before it, such as `auth-service account name`, which clap's /// usage leaves out. - fn command(&mut self, command: &Command, invocation: &str) { + fn command(&mut self, command: &Command, invocation: &str) -> fmt::Result { let path = command.get_bin_name().unwrap_or(command.get_name()); - let _ = writeln!(self.page, "\n## `{path}`\n"); + writeln!(self.page, "\n## `{path}`\n")?; if let Some(about) = command.get_long_about().or(command.get_about()) { - let _ = writeln!(self.page, "{}\n", Self::sentence(&about.to_string())); + writeln!(self.page, "{}\n", Self::sentence(&about.to_string()))?; } let usage = command.clone().render_usage().to_string(); - let _ = writeln!( + writeln!( self.page, "```text\n{}\n```", usage .trim_start_matches("Usage: ") .replacen(path, invocation, 1) - ); + )?; let (positionals, options): (Vec<&Arg>, Vec<&Arg>) = command .get_arguments() @@ -68,9 +68,9 @@ impl Reference { .partition(|argument| argument.is_positional()); for (title, arguments) in [("Arguments", positionals), ("Options", options)] { if !arguments.is_empty() { - let _ = writeln!(self.page, "\n{title}:\n"); + writeln!(self.page, "\n{title}:\n")?; for argument in arguments { - self.argument(argument); + self.argument(argument)?; } } } @@ -81,32 +81,33 @@ impl Reference { .filter(|subcommand| !subcommand.is_hide_set() && subcommand.get_name() != "help") .collect(); if !subcommands.is_empty() { - let _ = writeln!(self.page, "\nCommands:\n"); + writeln!(self.page, "\nCommands:\n")?; for subcommand in &subcommands { let name = format!("{path} {}", subcommand.get_name()); let about = subcommand .get_about() .map_or_default(|about| Self::sentence(&about.to_string())); - let _ = writeln!( + writeln!( self.page, "- [`{name}`](#{}): {about}", name.replace(' ', "-") - ); + )?; } } let mut arguments = String::new(); for argument in command.get_positionals() { - let _ = write!(arguments, " {argument}"); + write!(arguments, " {argument}")?; } for subcommand in subcommands { let invocation = format!("{invocation}{arguments} {}", subcommand.get_name()); - self.command(subcommand, &invocation); + self.command(subcommand, &invocation)?; } + Ok(()) } /// Adds one argument or option: how to write it, what it does, and its /// default and accepted values. - fn argument(&mut self, argument: &Arg) { + fn argument(&mut self, argument: &Arg) -> fmt::Result { let syntax = match (argument.get_short(), argument.get_long()) { (Some(short), Some(_)) => format!("-{short}, {argument}"), _ => argument.to_string(), @@ -127,7 +128,7 @@ impl Reference { .filter(|value| value != "``") .collect(); if takes_values && !defaults.is_empty() { - let _ = write!(text, " Default: {}.", defaults.join(", ")); + write!(text, " Default: {}.", defaults.join(", "))?; } let values: Vec = argument .get_possible_values() @@ -139,9 +140,9 @@ impl Reference { }) .collect(); if takes_values && !values.is_empty() { - let _ = write!(text, " Values: {}.", values.join(", ")); + write!(text, " Values: {}.", values.join(", "))?; } - let _ = writeln!(self.page, "- {}", text.trim_end()); + writeln!(self.page, "- {}", text.trim_end()) } /// Whether `argument` belongs on the page: not hidden, and not clap's own @@ -175,7 +176,7 @@ fn cli_reference_is_current() { "/../../docs/dev/operations/cli-commands.md" ) .into(), - text: Reference::render(), + text: Reference::render().expect("rendered"), } .write_or_compare() .expect("current reference"); diff --git a/apps/auth-service/src/cli/serve/mod.rs b/apps/auth-service/src/cli/serve/mod.rs index e63c2a919..630940fe3 100644 --- a/apps/auth-service/src/cli/serve/mod.rs +++ b/apps/auth-service/src/cli/serve/mod.rs @@ -78,7 +78,7 @@ impl Command { }; let jobs = async { // Fails only once `stop` is dropped, which also means stopping. - let _ = stop.subscribe().wait_for(|stopped| *stopped).await; + stop.subscribe().wait_for(|stopped| *stopped).await.ok(); jobs.shutdown().await }; let signal = async { diff --git a/apps/auth-service/src/config/tests.rs b/apps/auth-service/src/config/tests.rs index 582901068..c0d6f38c9 100644 --- a/apps/auth-service/src/config/tests.rs +++ b/apps/auth-service/src/config/tests.rs @@ -106,7 +106,8 @@ fn configuration_reference_is_current() { §ions, 3, "the variables in `apps/auth-service/src/config`", - ), + ) + .expect("rendered"), } .write_or_compare() .expect("current reference"); diff --git a/apps/auth-service/src/deletion/export/mod.rs b/apps/auth-service/src/deletion/export/mod.rs index b6f06d8ac..ca2a98e77 100644 --- a/apps/auth-service/src/deletion/export/mod.rs +++ b/apps/auth-service/src/deletion/export/mod.rs @@ -513,7 +513,7 @@ impl AccountExport { }; tracing::error!(error = %ErrorChain(&error), "account export failed"); // The browser may already be gone. - let _ = sender.send(Err(error)).await; + sender.send(Err(error)).await.ok(); } .in_current_span(), ); diff --git a/apps/auth-service/src/jobs/mod.rs b/apps/auth-service/src/jobs/mod.rs index bff90826a..987f9db5d 100644 --- a/apps/auth-service/src/jobs/mod.rs +++ b/apps/auth-service/src/jobs/mod.rs @@ -63,7 +63,7 @@ impl Shutdown { /// Resolves once shutdown has been requested. pub(crate) async fn requested(&self) { // An error means the runner is gone, which is a shutdown too. - let _ = self.0.clone().wait_for(|&requested| requested).await; + self.0.clone().wait_for(|&requested| requested).await.ok(); } /// Runs `work` unless shutdown is requested first: its output, or `None` diff --git a/apps/web/src/main.rs b/apps/web/src/main.rs index 061e7e8c2..db586ec05 100644 --- a/apps/web/src/main.rs +++ b/apps/web/src/main.rs @@ -129,7 +129,8 @@ fn configuration_reference_is_current() { }], 3, "the variables in `apps/web/src/main.rs`", - ), + ) + .expect("rendered"), } .write_or_compare() .expect("current reference"); diff --git a/crates/common/src/config/reference.rs b/crates/common/src/config/reference.rs index d53f38cc1..c20eb6d10 100644 --- a/crates/common/src/config/reference.rs +++ b/crates/common/src/config/reference.rs @@ -5,7 +5,11 @@ //! [`GeneratedFile`]. use super::Variable; -use std::{fmt::Write as _, fs, io, path::PathBuf}; +use std::{ + fmt::{self, Write as _}, + fs, io, + path::PathBuf, +}; use thiserror::Error; /// Set to rewrite generated files instead of comparing them; `just docs reference` @@ -66,7 +70,7 @@ pub struct Documented { impl Documented { /// Renders the variable as a list item: its name, its description, and its /// default. A blank doc comment line starts a new paragraph. - fn render(&self, out: &mut String) { + fn render(&self, out: &mut String) -> fmt::Result { let mut paragraphs: Vec = vec![String::new()]; for line in self.lines { let line = line.strip_prefix(' ').unwrap_or(line).trim_end(); @@ -90,14 +94,15 @@ impl Documented { None => paragraphs.push(sentence), } } - let _ = write!(out, "- `{}`:", self.variable.name()); + write!(out, "- `{}`:", self.variable.name())?; for (index, paragraph) in paragraphs.iter().enumerate() { if index == 0 { - let _ = writeln!(out, " {paragraph}"); + writeln!(out, " {paragraph}")?; } else { - let _ = writeln!(out, "\n {paragraph}"); + writeln!(out, "\n {paragraph}")?; } } + Ok(()) } } @@ -113,18 +118,20 @@ pub struct Section { impl Section { /// Renders `sections` as a Markdown fragment, each under a heading of `level`, /// with the comment saying where it comes from and how to regenerate it. - #[must_use] - pub fn render(sections: &[Self], level: usize, source: &str) -> String { + /// + /// # Errors + /// Returns the formatter's error, which writing to a `String` never raises. + pub fn render(sections: &[Self], level: usize, source: &str) -> Result { let mut out = format!( "\n" ); for section in sections { - let _ = writeln!(out, "\n{} {}\n", "#".repeat(level), section.title); + writeln!(out, "\n{} {}\n", "#".repeat(level), section.title)?; for variable in section.variables { - variable.render(&mut out); + variable.render(&mut out)?; } } - out + Ok(out) } } diff --git a/crates/telemetry/src/lib.rs b/crates/telemetry/src/lib.rs index 95ee59da1..514ba1683 100644 --- a/crates/telemetry/src/lib.rs +++ b/crates/telemetry/src/lib.rs @@ -201,7 +201,7 @@ impl Telemetry { let tracer = self.tracer.shutdown(); let meter = self.meter.map_or(Ok(()), |meter| meter.shutdown()); let logger = self.logger.map_or(Ok(()), |logger| logger.shutdown()); - let _ = flushed.send(tracer.and(meter).and(logger)); + flushed.send(tracer.and(meter).and(logger)).ok(); }); let flushed = tokio::time::timeout(within, result) .await