summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergi-Ferrez <sergiferrezpuig@gmail.com>2024-06-04 16:05:51 +0200
committerSergi-Ferrez <sergiferrezpuig@gmail.com>2024-06-04 16:05:51 +0200
commit744dc8c503debec5ce39f9529de80300ee1f7a2a (patch)
tree749e77cc299834d57b6ddb6a59d5719e6f99ceb1
parent617e64c9e7233ec1f936b8e14c30037fc3f6a1be (diff)
downloadrust-744dc8c503debec5ce39f9529de80300ee1f7a2a.tar.gz
rust-744dc8c503debec5ce39f9529de80300ee1f7a2a.zip
Use checked_sub
-rw-r--r--src/librustdoc/html/format.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index ff49f65ed08..4268fadd6c5 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -1439,7 +1439,7 @@ impl clean::FnDecl {
             write!(f, "\n{}", Indent(n + 4))?;
         }
 
-        let last_input_index = self.inputs.values.len() - 1;
+        let last_input_index = self.inputs.values.len().checked_sub(1);
         for (i, input) in self.inputs.values.iter().enumerate() {
             if let Some(selfty) = input.to_self() {
                 match selfty {
@@ -1473,11 +1473,12 @@ impl clean::FnDecl {
                 write!(f, "{}: ", input.name)?;
                 input.type_.print(cx).fmt(f)?;
             }
-            match line_wrapping_indent {
-                None if i == last_input_index => (),
-                None => write!(f, ", ")?,
-                Some(_n) if i == last_input_index => write!(f, ",\n")?,
-                Some(n) => write!(f, ",\n{}", Indent(n + 4))?,
+            match (line_wrapping_indent, last_input_index) {
+                (_, None) => (),
+                (None, Some(last_i)) if i != last_i => write!(f, ", ")?,
+                (None, Some(_)) => (),
+                (Some(n), Some(last_i)) if i != last_i => write!(f, ",\n{}", Indent(n + 4))?,
+                (Some(_), Some(_)) => write!(f, ",\n")?,
             }
         }