From 506f676e4463ab83d513494820c54c53bcb871dc Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 1 Dec 2024 15:30:52 -0600 Subject: [PATCH] Use RewriteResult in rewrite_reorderable_or_regroupable_items --- src/reorder.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/reorder.rs b/src/reorder.rs index 012e3c67021..69792262d34 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -16,7 +16,7 @@ use crate::config::{Config, GroupImportsTactic}; use crate::imports::{UseSegmentKind, UseTree, normalize_use_trees_with_granularity}; use crate::items::{is_mod_decl, rewrite_extern_crate, rewrite_mod}; use crate::lists::{ListFormatting, ListItem, itemize_list, write_list}; -use crate::rewrite::{RewriteContext, RewriteErrorExt}; +use crate::rewrite::{RewriteContext, RewriteError, RewriteErrorExt, RewriteResult}; use crate::shape::Shape; use crate::sort::version_sort; use crate::source_map::LineRangeUtils; @@ -69,11 +69,11 @@ fn wrap_reorderable_items( context: &RewriteContext<'_>, list_items: &[ListItem], shape: Shape, -) -> Option { +) -> RewriteResult { let fmt = ListFormatting::new(shape, context.config) .separator("") .align_comments(false); - write_list(list_items, &fmt).ok() + write_list(list_items, &fmt) } fn rewrite_reorderable_item( @@ -96,7 +96,7 @@ fn rewrite_reorderable_or_regroupable_items( reorderable_items: &[&ast::Item], shape: Shape, span: Span, -) -> Option { +) -> RewriteResult { match reorderable_items[0].kind { // FIXME: Remove duplicated code. ast::ItemKind::Use(..) => { @@ -138,7 +138,7 @@ fn rewrite_reorderable_or_regroupable_items( } // 4 = "use ", 1 = ";" - let nested_shape = shape.offset_left_opt(4)?.sub_width_opt(1)?; + let nested_shape = shape.offset_left(4, span)?.sub_width(1, span)?; let item_vec: Vec<_> = regrouped_items .into_iter() .filter(|use_group| !use_group.is_empty()) @@ -159,10 +159,10 @@ fn rewrite_reorderable_or_regroupable_items( .collect(); wrap_reorderable_items(context, &item_vec, nested_shape) }) - .collect::>>()?; + .collect::, RewriteError>>()?; let join_string = format!("\n\n{}", shape.indent.to_string(context.config)); - Some(item_vec.join(&join_string)) + Ok(item_vec.join(&join_string)) } _ => { let list_items = itemize_list( @@ -313,7 +313,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.shape(), span, ); - self.push_rewrite(span, rw); + self.push_rewrite(span, rw.ok()); } else { for item in items { self.push_rewrite(item.span, None);