Skip to content

Commit 20c6e60

Browse files
committed
fix test error
1 parent d87b0b2 commit 20c6e60

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

src/expr.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use crate::string::{StringFormat, rewrite_string};
3232
use crate::types::{PathContext, rewrite_path};
3333
use crate::utils::{
3434
colon_spaces, contains_skip, count_newlines, filtered_str_fits, first_line_ends_with,
35-
inner_attributes, is_absolute_decl_path, last_line_extendable, last_line_width, mk_sp, outer_attributes,
36-
semicolon_for_expr, unicode_str_width, wrap_str,
35+
inner_attributes, is_absolute_decl_path, last_line_extendable, last_line_width, mk_sp,
36+
outer_attributes, semicolon_for_expr, unicode_str_width, wrap_str,
3737
};
3838
use crate::vertical::rewrite_with_alignment;
3939
use crate::visitor::FmtVisitor;
@@ -1887,7 +1887,9 @@ pub(crate) fn struct_lit_field_separator(config: &Config, force_space_after_colo
18871887
fn extract_ast_path_from_expr(expr: &ast::Expr) -> Option<&ast::Path> {
18881888
match &expr.kind {
18891889
ast::ExprKind::Call(ptr_expr, ..) => extract_ast_path_from_expr(&*ptr_expr),
1890-
ast::ExprKind::MethodCall(box_method_call, ..) => extract_ast_path_from_expr(&*box_method_call.receiver),
1890+
ast::ExprKind::MethodCall(box_method_call, ..) => {
1891+
extract_ast_path_from_expr(&*box_method_call.receiver)
1892+
}
18911893
ast::ExprKind::Binary(_, left_expr, ..) => extract_ast_path_from_expr(&*left_expr),
18921894
ast::ExprKind::Cast(ptr_expr, ..) => extract_ast_path_from_expr(&*ptr_expr),
18931895
ast::ExprKind::Type(ptr_expr, ..) => extract_ast_path_from_expr(&*ptr_expr),
@@ -1896,9 +1898,7 @@ fn extract_ast_path_from_expr(expr: &ast::Expr) -> Option<&ast::Path> {
18961898
ast::ExprKind::Range(Some(start_expr), ..) => extract_ast_path_from_expr(&*start_expr),
18971899
ast::ExprKind::Path(_, path, ..) => Some(&path),
18981900
ast::ExprKind::MacCall(mac, ..) => Some(&(*mac).path),
1899-
ast::ExprKind::Struct(ptr_struct_expr, ..) => {
1900-
Some(&(*ptr_struct_expr).path)
1901-
}
1901+
ast::ExprKind::Struct(ptr_struct_expr, ..) => Some(&(*ptr_struct_expr).path),
19021902
_ => None,
19031903
}
19041904
}
@@ -1924,7 +1924,10 @@ pub(crate) fn rewrite_field(
19241924
Some(path) => is_absolute_decl_path(path),
19251925
_ => false,
19261926
};
1927-
let mut separator = String::from(struct_lit_field_separator(context.config, force_space_after_colon));
1927+
let mut separator = String::from(struct_lit_field_separator(
1928+
context.config,
1929+
force_space_after_colon,
1930+
));
19281931
for _ in 0..prefix_max_width.saturating_sub(name.len()) {
19291932
separator.push(' ');
19301933
}

src/items.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ impl Rewrite for ast::Local {
9696
let mut infix = String::with_capacity(32);
9797

9898
if let Some(ref ty) = self.ty {
99-
let force_space_after_colon =
100-
is_ty_kind_with_absolute_decl(&(*ty).kind);
99+
let force_space_after_colon = is_ty_kind_with_absolute_decl(&(*ty).kind);
101100
let separator = type_annotation_separator(context.config, force_space_after_colon);
102101

103102
let ty_shape = if pat_str.contains('\n') {
@@ -1910,8 +1909,7 @@ pub(crate) fn rewrite_struct_field_prefix(
19101909
) -> RewriteResult {
19111910
let vis = format_visibility(context, &field.vis);
19121911
let safety = format_safety(field.safety);
1913-
let force_space_after_colon =
1914-
is_ty_kind_with_absolute_decl(&(*field.ty).kind);
1912+
let force_space_after_colon = is_ty_kind_with_absolute_decl(&(*field.ty).kind);
19151913
let type_annotation_spacing = type_annotation_spacing(context.config, force_space_after_colon);
19161914
Ok(match field.ident {
19171915
Some(name) => format!(
@@ -1948,8 +1946,7 @@ pub(crate) fn rewrite_struct_field(
19481946
return Ok(context.snippet(field.span()).to_owned());
19491947
}
19501948

1951-
let force_space_after_colon =
1952-
is_ty_kind_with_absolute_decl(&(*field.ty).kind);
1949+
let force_space_after_colon = is_ty_kind_with_absolute_decl(&(*field.ty).kind);
19531950
let type_annotation_spacing = type_annotation_spacing(context.config, force_space_after_colon);
19541951
let prefix = rewrite_struct_field_prefix(context, field)?;
19551952

src/types.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,16 @@ fn is_bound_starts_with_absolut_decl(bounds: &ast::GenericBounds) -> bool {
461461
} else {
462462
let first_bound = &bounds[0];
463463
match first_bound {
464-
ast::GenericBound::Trait(poly_trait_ref) =>
465-
poly_trait_ref.bound_generic_params.len() == 0 &&
466-
poly_trait_ref.modifiers == ast::TraitBoundModifiers{
467-
constness: ast::BoundConstness::Never,
468-
asyncness: ast::BoundAsyncness::Normal,
469-
polarity: ast::BoundPolarity::Positive,
470-
} &&
471-
is_absolute_decl_path(&poly_trait_ref.trait_ref.path),
464+
ast::GenericBound::Trait(poly_trait_ref) => {
465+
let plain_trait_modifiers = ast::TraitBoundModifiers {
466+
constness: ast::BoundConstness::Never,
467+
asyncness: ast::BoundAsyncness::Normal,
468+
polarity: ast::BoundPolarity::Positive,
469+
};
470+
poly_trait_ref.modifiers == plain_trait_modifiers
471+
&& poly_trait_ref.bound_generic_params.len() == 0
472+
&& is_absolute_decl_path(&poly_trait_ref.trait_ref.path)
473+
}
472474
_ => false,
473475
}
474476
}
@@ -587,7 +589,8 @@ fn rewrite_bounded_lifetime(
587589
if bounds.is_empty() {
588590
Ok(result)
589591
} else {
590-
// the code for this point is `x:&'a SomeType`, so, no need to force adding space after colon
592+
// the code for this point is `x:&'a SomeType`,
593+
// so, no need to force adding space after colon
591594
let colon = type_bound_colon(context, false);
592595
let overhead = last_line_width(&result) + colon.len();
593596
let shape = shape.sub_width(overhead, span)?;

src/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ mod test {
716716
}
717717
}
718718

719-
720719
pub fn is_absolute_decl_path(path: &ast::Path) -> bool {
721720
let segments = &path.segments;
722721
match segments.first() {
@@ -730,4 +729,4 @@ pub fn is_ty_kind_with_absolute_decl(ty_kind: &ast::TyKind) -> bool {
730729
ast::TyKind::Path(None, ast_path) => is_absolute_decl_path(ast_path),
731730
_ => false,
732731
}
733-
}
732+
}

0 commit comments

Comments
 (0)