Remove duplicate definitions

This commit removes duplicated definitions of `type_annotation_separator` and
`type_bound_colon`.
This commit is contained in:
topecongiro 2017-03-28 23:14:48 +09:00
parent 7377dfc38c
commit a2d57e956a
3 changed files with 16 additions and 15 deletions

View File

@ -23,7 +23,8 @@ use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTacti
struct_lit_tactic, shape_for_tactic, struct_lit_formatting};
use string::{StringFormat, rewrite_string};
use utils::{extra_offset, last_line_width, wrap_str, binary_search, first_line_width,
semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_expr};
semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_expr,
place_spaces};
use visitor::FmtVisitor;
use config::{Config, IndentStyle, MultilineStyle, ControlBraceStyle};
use comment::{FindUncommented, rewrite_comment, contains_comment, recover_comment_removed};
@ -1890,13 +1891,8 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
// of space, we should fall back to BlockIndent.
}
pub fn type_annotation_separator(config: &Config) -> &str {
match (config.space_before_type_annotation, config.space_after_type_annotation_colon) {
(true, true) => " : ",
(true, false) => " :",
(false, true) => ": ",
(false, false) => ":",
}
pub fn type_annotation_separator(config: &Config) -> & str {
place_spaces (config.space_before_type_annotation, config.space_after_type_annotation_colon)
}
fn rewrite_field(context: &RewriteContext, field: &ast::Field, shape: Shape) -> Option<String> {

View File

@ -21,7 +21,7 @@ use {Shape, Spanned};
use codemap::SpanUtils;
use lists::{format_item_list, itemize_list, format_fn_args};
use rewrite::{Rewrite, RewriteContext};
use utils::{extra_offset, format_mutability, wrap_str};
use utils::{extra_offset, format_mutability, place_spaces, wrap_str};
use expr::{rewrite_unary_prefix, rewrite_pair, rewrite_tuple};
use config::TypeDensity;
use itertools::Itertools;
@ -346,12 +346,7 @@ fn format_function_type<'a, I>(inputs: I,
}
fn type_bound_colon(context: &RewriteContext) -> &'static str {
match (context.config.space_before_bound, context.config.space_after_bound_colon) {
(true, true) => " : ",
(true, false) => " :",
(false, true) => ": ",
(false, false) => ":",
}
place_spaces(context.config.space_before_bound, context.config.space_after_bound_colon)
}
impl Rewrite for ast::WherePredicate {

View File

@ -326,6 +326,16 @@ pub fn binary_search<C, T>(mut lo: usize, mut hi: usize, callback: C) -> Option<
None
}
#[inline]
pub fn place_spaces(before: bool, after: bool) -> &'static str {
match (before, after) {
(true, true) => " : ",
(true, false) => " :",
(false, true) => ": ",
(false, false) => ":",
}
}
#[test]
fn bin_search_test() {
let closure = |i| match i {