modify trait bound of itemize_list
This commit is contained in:
parent
ea02de27ff
commit
6ccf539b19
@ -99,7 +99,7 @@ fn format_derive(
|
||||
",",
|
||||
|span| span.lo(),
|
||||
|span| span.hi(),
|
||||
|span| Some(context.snippet(*span).to_owned()),
|
||||
|span| Ok(context.snippet(*span).to_owned()),
|
||||
// We update derive attribute spans to start after the opening '('
|
||||
// This helps us focus parsing to just what's inside #[derive(...)]
|
||||
context.snippet_provider.span_after(attr.span, "("),
|
||||
|
@ -312,7 +312,7 @@ fn rewrite_closure_fn_decl(
|
||||
",",
|
||||
|param| span_lo_for_param(param),
|
||||
|param| span_hi_for_param(context, param),
|
||||
|param| param.rewrite(context, param_shape),
|
||||
|param| param.rewrite_result(context, param_shape),
|
||||
context.snippet_provider.span_after(span, "|"),
|
||||
body.span.lo(),
|
||||
false,
|
||||
|
22
src/expr.rs
22
src/expr.rs
@ -1671,15 +1671,25 @@ fn rewrite_struct_lit<'a>(
|
||||
let rewrite = |item: &StructLitField<'_>| match *item {
|
||||
StructLitField::Regular(field) => {
|
||||
// The 1 taken from the v_budget is for the comma.
|
||||
let v_shape = v_shape.sub_width(1)?;
|
||||
rewrite_field(context, field, v_shape, 0).ok()
|
||||
rewrite_field(
|
||||
context,
|
||||
field,
|
||||
v_shape.sub_width(1).max_width_error(v_shape.width, span)?,
|
||||
0,
|
||||
)
|
||||
.unknown_error()
|
||||
}
|
||||
StructLitField::Base(expr) => {
|
||||
// 2 = ..
|
||||
let v_shape = v_shape.sub_width(2)?;
|
||||
expr.rewrite(context, v_shape).map(|s| format!("..{}", s))
|
||||
expr.rewrite_result(
|
||||
context,
|
||||
v_shape
|
||||
.offset_left(2)
|
||||
.max_width_error(v_shape.width, span)?,
|
||||
)
|
||||
.map(|s| format!("..{}", s))
|
||||
}
|
||||
StructLitField::Rest(_) => Some("..".to_owned()),
|
||||
StructLitField::Rest(_) => Ok("..".to_owned()),
|
||||
};
|
||||
|
||||
let items = itemize_list(
|
||||
@ -1843,7 +1853,7 @@ fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + IntoOverflowableItem<'a>>(
|
||||
",",
|
||||
|item| item.span().lo(),
|
||||
|item| item.span().hi(),
|
||||
|item| item.rewrite(context, nested_shape),
|
||||
|item| item.rewrite_result(context, nested_shape),
|
||||
list_lo,
|
||||
span.hi() - BytePos(1),
|
||||
false,
|
||||
|
@ -470,7 +470,7 @@ impl UseTree {
|
||||
",",
|
||||
|tree| tree.span.lo(),
|
||||
|tree| tree.span.hi(),
|
||||
|_| Some("".to_owned()), // We only need comments for now.
|
||||
|_| Ok("".to_owned()), // We only need comments for now.
|
||||
context.snippet_provider.span_after(a.span, "{"),
|
||||
a.span.hi(),
|
||||
false,
|
||||
|
13
src/items.rs
13
src/items.rs
@ -629,7 +629,10 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
},
|
||||
|f| f.span.hi(),
|
||||
|f| self.format_variant(f, one_line_width, pad_discrim_ident_to),
|
||||
|f| {
|
||||
self.format_variant(f, one_line_width, pad_discrim_ident_to)
|
||||
.unknown_error()
|
||||
},
|
||||
body_lo,
|
||||
body_hi,
|
||||
false,
|
||||
@ -2777,8 +2780,8 @@ fn rewrite_params(
|
||||
|param| param.ty.span.hi(),
|
||||
|param| {
|
||||
param
|
||||
.rewrite(context, Shape::legacy(multi_line_budget, param_indent))
|
||||
.or_else(|| Some(context.snippet(param.span()).to_owned()))
|
||||
.rewrite_result(context, Shape::legacy(multi_line_budget, param_indent))
|
||||
.or_else(|_| Ok(context.snippet(param.span()).to_owned()))
|
||||
},
|
||||
span.lo(),
|
||||
span.hi(),
|
||||
@ -3048,7 +3051,7 @@ fn rewrite_bounds_on_where_clause(
|
||||
",",
|
||||
|pred| pred.span().lo(),
|
||||
|pred| pred.span().hi(),
|
||||
|pred| pred.rewrite(context, shape),
|
||||
|pred| pred.rewrite_result(context, shape),
|
||||
span_start,
|
||||
span_end,
|
||||
false,
|
||||
@ -3129,7 +3132,7 @@ fn rewrite_where_clause(
|
||||
",",
|
||||
|pred| pred.span().lo(),
|
||||
|pred| pred.span().hi(),
|
||||
|pred| pred.rewrite(context, Shape::legacy(budget, offset)),
|
||||
|pred| pred.rewrite_result(context, Shape::legacy(budget, offset)),
|
||||
span_start,
|
||||
span_end,
|
||||
false,
|
||||
|
@ -8,7 +8,7 @@ use rustc_span::BytePos;
|
||||
use crate::comment::{find_comment_end, rewrite_comment, FindUncommented};
|
||||
use crate::config::lists::*;
|
||||
use crate::config::{Config, IndentStyle};
|
||||
use crate::rewrite::RewriteContext;
|
||||
use crate::rewrite::{RewriteContext, RewriteResult};
|
||||
use crate::shape::{Indent, Shape};
|
||||
use crate::utils::{
|
||||
count_newlines, first_line_width, last_line_width, mk_sp, starts_with_newline,
|
||||
@ -281,6 +281,7 @@ where
|
||||
let indent_str = &formatting.shape.indent.to_string(formatting.config);
|
||||
while let Some((i, item)) = iter.next() {
|
||||
let item = item.as_ref();
|
||||
// TODO here Is it possible to 실제로 list item이 없으면..
|
||||
let inner_item = item.item.as_ref()?;
|
||||
let first = i == 0;
|
||||
let last = iter.peek().is_none();
|
||||
@ -741,7 +742,7 @@ where
|
||||
I: Iterator<Item = T>,
|
||||
F1: Fn(&T) -> BytePos,
|
||||
F2: Fn(&T) -> BytePos,
|
||||
F3: Fn(&T) -> Option<String>,
|
||||
F3: Fn(&T) -> RewriteResult,
|
||||
{
|
||||
type Item = ListItem;
|
||||
|
||||
@ -778,7 +779,7 @@ where
|
||||
item: if self.inner.peek().is_none() && self.leave_last {
|
||||
None
|
||||
} else {
|
||||
(self.get_item_string)(&item)
|
||||
(self.get_item_string)(&item).ok()
|
||||
},
|
||||
post_comment,
|
||||
new_lines,
|
||||
@ -805,7 +806,7 @@ where
|
||||
I: Iterator<Item = T>,
|
||||
F1: Fn(&T) -> BytePos,
|
||||
F2: Fn(&T) -> BytePos,
|
||||
F3: Fn(&T) -> Option<String>,
|
||||
F3: Fn(&T) -> RewriteResult,
|
||||
{
|
||||
ListItems {
|
||||
snippet_provider,
|
||||
|
@ -31,7 +31,7 @@ use crate::lists::{itemize_list, write_list, ListFormatting};
|
||||
use crate::overflow;
|
||||
use crate::parse::macros::lazy_static::parse_lazy_static;
|
||||
use crate::parse::macros::{parse_expr, parse_macro_args, ParsedMacroArgs};
|
||||
use crate::rewrite::{Rewrite, RewriteContext};
|
||||
use crate::rewrite::{Rewrite, RewriteContext, RewriteError};
|
||||
use crate::shape::{Indent, Shape};
|
||||
use crate::source_map::SpanUtils;
|
||||
use crate::spanned::Spanned;
|
||||
@ -452,13 +452,13 @@ pub(crate) fn rewrite_macro_def(
|
||||
|branch| branch.span.lo(),
|
||||
|branch| branch.span.hi(),
|
||||
|branch| match branch.rewrite(context, arm_shape, multi_branch_style) {
|
||||
Some(v) => Some(v),
|
||||
Some(v) => Ok(v),
|
||||
// if the rewrite returned None because a macro could not be rewritten, then return the
|
||||
// original body
|
||||
None if context.macro_rewrite_failure.get() => {
|
||||
Some(context.snippet(branch.body).trim().to_string())
|
||||
Ok(context.snippet(branch.body).trim().to_string())
|
||||
}
|
||||
None => None,
|
||||
None => Err(RewriteError::Unknown),
|
||||
},
|
||||
context.snippet_provider.span_after(span, "{"),
|
||||
span.hi(),
|
||||
|
@ -225,7 +225,7 @@ fn rewrite_match_arms(
|
||||
"|",
|
||||
|arm| arm.span().lo(),
|
||||
|arm| arm.span().hi(),
|
||||
|arm| arm.rewrite(context, arm_shape),
|
||||
|arm| arm.rewrite_result(context, arm_shape),
|
||||
open_brace_pos,
|
||||
span.hi(),
|
||||
false,
|
||||
|
@ -623,7 +623,7 @@ impl<'a> Context<'a> {
|
||||
",",
|
||||
|item| item.span().lo(),
|
||||
|item| item.span().hi(),
|
||||
|item| item.rewrite(self.context, self.nested_shape),
|
||||
|item| item.rewrite_result(self.context, self.nested_shape),
|
||||
span.lo(),
|
||||
span.hi(),
|
||||
true,
|
||||
|
@ -343,7 +343,7 @@ fn rewrite_struct_pat(
|
||||
}
|
||||
},
|
||||
|f| f.span.hi(),
|
||||
|f| f.rewrite(context, v_shape),
|
||||
|f| f.rewrite_result(context, v_shape),
|
||||
context.snippet_provider.span_after(span, "{"),
|
||||
span.hi(),
|
||||
false,
|
||||
@ -551,7 +551,7 @@ fn count_wildcard_suffix_len(
|
||||
",",
|
||||
|item| item.span().lo(),
|
||||
|item| item.span().hi(),
|
||||
|item| item.rewrite(context, shape),
|
||||
|item| item.rewrite_result(context, shape),
|
||||
context.snippet_provider.span_after(span, "("),
|
||||
span.hi() - BytePos(1),
|
||||
false,
|
||||
|
@ -15,7 +15,7 @@ use crate::config::{Config, GroupImportsTactic};
|
||||
use crate::imports::{normalize_use_trees_with_granularity, UseSegmentKind, UseTree};
|
||||
use crate::items::{is_mod_decl, rewrite_extern_crate, rewrite_mod};
|
||||
use crate::lists::{itemize_list, write_list, ListFormatting, ListItem};
|
||||
use crate::rewrite::RewriteContext;
|
||||
use crate::rewrite::{RewriteContext, RewriteErrorExt};
|
||||
use crate::shape::Shape;
|
||||
use crate::source_map::LineRangeUtils;
|
||||
use crate::spanned::Spanned;
|
||||
@ -99,7 +99,7 @@ fn rewrite_reorderable_or_regroupable_items(
|
||||
";",
|
||||
|item| item.span().lo(),
|
||||
|item| item.span().hi(),
|
||||
|_item| Some("".to_owned()),
|
||||
|_item| Ok("".to_owned()),
|
||||
span.lo(),
|
||||
span.hi(),
|
||||
false,
|
||||
@ -151,7 +151,7 @@ fn rewrite_reorderable_or_regroupable_items(
|
||||
";",
|
||||
|item| item.span().lo(),
|
||||
|item| item.span().hi(),
|
||||
|item| rewrite_reorderable_item(context, item, shape),
|
||||
|item| rewrite_reorderable_item(context, item, shape).unknown_error(),
|
||||
span.lo(),
|
||||
span.hi(),
|
||||
false,
|
||||
|
@ -388,7 +388,7 @@ where
|
||||
",",
|
||||
|arg| arg.span().lo(),
|
||||
|arg| arg.span().hi(),
|
||||
|arg| arg.rewrite(context, list_shape),
|
||||
|arg| arg.rewrite_result(context, list_shape),
|
||||
list_lo,
|
||||
span.hi(),
|
||||
false,
|
||||
|
@ -231,7 +231,6 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
|
||||
|field| {
|
||||
field
|
||||
.rewrite_aligned_item(context, item_shape, field_prefix_max_width)
|
||||
.ok()
|
||||
},
|
||||
span.lo(),
|
||||
span.hi(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user