mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Factor out PairParts::infix
This commit is contained in:
+15
-4
@@ -92,7 +92,7 @@ pub fn format_expr(
|
||||
rewrite_pair(
|
||||
&**lhs,
|
||||
&**rhs,
|
||||
PairParts::new("", &format!(" {} ", context.snippet(op.span)), ""),
|
||||
PairParts::infix(&format!(" {} ", context.snippet(op.span))),
|
||||
context,
|
||||
shape,
|
||||
context.config.binop_separator(),
|
||||
@@ -211,7 +211,7 @@ pub fn format_expr(
|
||||
ast::ExprKind::Cast(ref expr, ref ty) => rewrite_pair(
|
||||
&**expr,
|
||||
&**ty,
|
||||
PairParts::new("", " as ", ""),
|
||||
PairParts::infix(" as "),
|
||||
context,
|
||||
shape,
|
||||
SeparatorPlace::Front,
|
||||
@@ -219,7 +219,7 @@ pub fn format_expr(
|
||||
ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair(
|
||||
&**expr,
|
||||
&**ty,
|
||||
PairParts::new("", ": ", ""),
|
||||
PairParts::infix(": "),
|
||||
context,
|
||||
shape,
|
||||
SeparatorPlace::Back,
|
||||
@@ -288,7 +288,7 @@ fn needs_space_after_range(rhs: &ast::Expr) -> bool {
|
||||
rewrite_pair(
|
||||
&*lhs,
|
||||
&*rhs,
|
||||
PairParts::new("", &sp_delim, ""),
|
||||
PairParts::infix(&sp_delim),
|
||||
context,
|
||||
shape,
|
||||
context.config.binop_separator(),
|
||||
@@ -435,6 +435,7 @@ fn rewrite_simple_binaries(
|
||||
None
|
||||
}
|
||||
|
||||
/// Sigils that decorate a binop pair.
|
||||
#[derive(new, Clone, Copy)]
|
||||
pub struct PairParts<'a> {
|
||||
prefix: &'a str,
|
||||
@@ -442,6 +443,16 @@ pub struct PairParts<'a> {
|
||||
suffix: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> PairParts<'a> {
|
||||
pub fn infix(infix: &'a str) -> PairParts<'a> {
|
||||
PairParts {
|
||||
prefix: "",
|
||||
infix,
|
||||
suffix: "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rewrite_pair<LHS, RHS>(
|
||||
lhs: &LHS,
|
||||
rhs: &RHS,
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
rewrite_pair(
|
||||
&**lhs,
|
||||
&**rhs,
|
||||
PairParts::new("", &infix, ""),
|
||||
PairParts::infix(&infix),
|
||||
context,
|
||||
shape,
|
||||
SeparatorPlace::Front,
|
||||
|
||||
Reference in New Issue
Block a user