Skip to content

Commit

Permalink
fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
FwP-IDN committed Feb 18, 2025
1 parent d87b0b2 commit 20c6e60
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
17 changes: 10 additions & 7 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use crate::string::{StringFormat, rewrite_string};
use crate::types::{PathContext, rewrite_path};
use crate::utils::{
colon_spaces, contains_skip, count_newlines, filtered_str_fits, first_line_ends_with,
inner_attributes, is_absolute_decl_path, last_line_extendable, last_line_width, mk_sp, outer_attributes,
semicolon_for_expr, unicode_str_width, wrap_str,
inner_attributes, is_absolute_decl_path, last_line_extendable, last_line_width, mk_sp,
outer_attributes, semicolon_for_expr, unicode_str_width, wrap_str,
};
use crate::vertical::rewrite_with_alignment;
use crate::visitor::FmtVisitor;
Expand Down Expand Up @@ -1887,7 +1887,9 @@ pub(crate) fn struct_lit_field_separator(config: &Config, force_space_after_colo
fn extract_ast_path_from_expr(expr: &ast::Expr) -> Option<&ast::Path> {
match &expr.kind {
ast::ExprKind::Call(ptr_expr, ..) => extract_ast_path_from_expr(&*ptr_expr),
ast::ExprKind::MethodCall(box_method_call, ..) => extract_ast_path_from_expr(&*box_method_call.receiver),
ast::ExprKind::MethodCall(box_method_call, ..) => {
extract_ast_path_from_expr(&*box_method_call.receiver)
}
ast::ExprKind::Binary(_, left_expr, ..) => extract_ast_path_from_expr(&*left_expr),
ast::ExprKind::Cast(ptr_expr, ..) => extract_ast_path_from_expr(&*ptr_expr),
ast::ExprKind::Type(ptr_expr, ..) => extract_ast_path_from_expr(&*ptr_expr),
Expand All @@ -1896,9 +1898,7 @@ fn extract_ast_path_from_expr(expr: &ast::Expr) -> Option<&ast::Path> {
ast::ExprKind::Range(Some(start_expr), ..) => extract_ast_path_from_expr(&*start_expr),
ast::ExprKind::Path(_, path, ..) => Some(&path),
ast::ExprKind::MacCall(mac, ..) => Some(&(*mac).path),
ast::ExprKind::Struct(ptr_struct_expr, ..) => {
Some(&(*ptr_struct_expr).path)
}
ast::ExprKind::Struct(ptr_struct_expr, ..) => Some(&(*ptr_struct_expr).path),
_ => None,
}
}
Expand All @@ -1924,7 +1924,10 @@ pub(crate) fn rewrite_field(
Some(path) => is_absolute_decl_path(path),
_ => false,
};
let mut separator = String::from(struct_lit_field_separator(context.config, force_space_after_colon));
let mut separator = String::from(struct_lit_field_separator(
context.config,
force_space_after_colon,
));
for _ in 0..prefix_max_width.saturating_sub(name.len()) {
separator.push(' ');
}
Expand Down
9 changes: 3 additions & 6 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ impl Rewrite for ast::Local {
let mut infix = String::with_capacity(32);

if let Some(ref ty) = self.ty {
let force_space_after_colon =
is_ty_kind_with_absolute_decl(&(*ty).kind);
let force_space_after_colon = is_ty_kind_with_absolute_decl(&(*ty).kind);
let separator = type_annotation_separator(context.config, force_space_after_colon);

let ty_shape = if pat_str.contains('\n') {
Expand Down Expand Up @@ -1910,8 +1909,7 @@ pub(crate) fn rewrite_struct_field_prefix(
) -> RewriteResult {
let vis = format_visibility(context, &field.vis);
let safety = format_safety(field.safety);
let force_space_after_colon =
is_ty_kind_with_absolute_decl(&(*field.ty).kind);
let force_space_after_colon = is_ty_kind_with_absolute_decl(&(*field.ty).kind);
let type_annotation_spacing = type_annotation_spacing(context.config, force_space_after_colon);
Ok(match field.ident {
Some(name) => format!(
Expand Down Expand Up @@ -1948,8 +1946,7 @@ pub(crate) fn rewrite_struct_field(
return Ok(context.snippet(field.span()).to_owned());
}

let force_space_after_colon =
is_ty_kind_with_absolute_decl(&(*field.ty).kind);
let force_space_after_colon = is_ty_kind_with_absolute_decl(&(*field.ty).kind);
let type_annotation_spacing = type_annotation_spacing(context.config, force_space_after_colon);
let prefix = rewrite_struct_field_prefix(context, field)?;

Expand Down
21 changes: 12 additions & 9 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,16 @@ fn is_bound_starts_with_absolut_decl(bounds: &ast::GenericBounds) -> bool {
} else {
let first_bound = &bounds[0];
match first_bound {
ast::GenericBound::Trait(poly_trait_ref) =>
poly_trait_ref.bound_generic_params.len() == 0 &&
poly_trait_ref.modifiers == ast::TraitBoundModifiers{
constness: ast::BoundConstness::Never,
asyncness: ast::BoundAsyncness::Normal,
polarity: ast::BoundPolarity::Positive,
} &&
is_absolute_decl_path(&poly_trait_ref.trait_ref.path),
ast::GenericBound::Trait(poly_trait_ref) => {
let plain_trait_modifiers = ast::TraitBoundModifiers {
constness: ast::BoundConstness::Never,
asyncness: ast::BoundAsyncness::Normal,
polarity: ast::BoundPolarity::Positive,
};
poly_trait_ref.modifiers == plain_trait_modifiers
&& poly_trait_ref.bound_generic_params.len() == 0
&& is_absolute_decl_path(&poly_trait_ref.trait_ref.path)
}
_ => false,
}
}
Expand Down Expand Up @@ -587,7 +589,8 @@ fn rewrite_bounded_lifetime(
if bounds.is_empty() {
Ok(result)
} else {
// the code for this point is `x:&'a SomeType`, so, no need to force adding space after colon
// the code for this point is `x:&'a SomeType`,
// so, no need to force adding space after colon
let colon = type_bound_colon(context, false);
let overhead = last_line_width(&result) + colon.len();
let shape = shape.sub_width(overhead, span)?;
Expand Down
3 changes: 1 addition & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ mod test {
}
}


pub fn is_absolute_decl_path(path: &ast::Path) -> bool {
let segments = &path.segments;
match segments.first() {
Expand All @@ -730,4 +729,4 @@ pub fn is_ty_kind_with_absolute_decl(ty_kind: &ast::TyKind) -> bool {
ast::TyKind::Path(None, ast_path) => is_absolute_decl_path(ast_path),
_ => false,
}
}
}

0 comments on commit 20c6e60

Please sign in to comment.