Skip to content

Commit

Permalink
Use RewriteResult in rewrite_reorderable_or_regroupable_items
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed Dec 1, 2024
1 parent 78aa72f commit 506f676
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,11 +69,11 @@ fn wrap_reorderable_items(
context: &RewriteContext<'_>,
list_items: &[ListItem],
shape: Shape,
) -> Option<String> {
) -> 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(
Expand All @@ -96,7 +96,7 @@ fn rewrite_reorderable_or_regroupable_items(
reorderable_items: &[&ast::Item],
shape: Shape,
span: Span,
) -> Option<String> {
) -> RewriteResult {
match reorderable_items[0].kind {
// FIXME: Remove duplicated code.
ast::ItemKind::Use(..) => {
Expand Down Expand Up @@ -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())
Expand All @@ -159,10 +159,10 @@ fn rewrite_reorderable_or_regroupable_items(
.collect();
wrap_reorderable_items(context, &item_vec, nested_shape)
})
.collect::<Option<Vec<_>>>()?;
.collect::<Result<Vec<_>, 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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 506f676

Please sign in to comment.