Replace into() on &str with to_owned()

This commit is contained in:
Seiichi Uchida 2017-12-08 13:07:42 +09:00
parent c776443981
commit 3ebe054362
9 changed files with 43 additions and 43 deletions

View File

@ -120,7 +120,7 @@ fn run(opts: &getopts::Options) -> Result<(), FormatDiffError> {
let filter = matches
.opt_str("f")
.unwrap_or_else(|| DEFAULT_PATTERN.into());
.unwrap_or_else(|| DEFAULT_PATTERN.to_owned());
let skip_prefix = matches
.opt_str("p")
@ -247,19 +247,19 @@ fn scan_simple_git_diff() {
&ranges,
&[
Range {
file: "src/ir/item.rs".into(),
file: "src/ir/item.rs".to_owned(),
range: [148, 158],
},
Range {
file: "src/ir/item.rs".into(),
file: "src/ir/item.rs".to_owned(),
range: [160, 170],
},
Range {
file: "src/ir/traversal.rs".into(),
file: "src/ir/traversal.rs".to_owned(),
range: [9, 16],
},
Range {
file: "src/ir/traversal.rs".into(),
file: "src/ir/traversal.rs".to_owned(),
range: [35, 43],
}
]

View File

@ -918,7 +918,7 @@ pub fn recover_comment_removed(
let snippet = context.snippet(span);
if snippet != new && changed_comment_content(&snippet, &new) {
// We missed some comments. Keep the original text.
Some(snippet.into())
Some(snippet.to_owned())
} else {
Some(new)
}

View File

@ -58,7 +58,7 @@ pub fn format_expr(
skip_out_of_file_lines_range!(context, expr.span);
if contains_skip(&*expr.attrs) {
return Some(context.snippet(expr.span()).into());
return Some(context.snippet(expr.span()).to_owned());
}
let expr_rw = match expr.node {
@ -168,7 +168,7 @@ pub fn format_expr(
ast::ExprKind::Mac(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
wrap_str(
context.snippet(expr.span).into(),
context.snippet(expr.span).to_owned(),
context.config.max_width(),
shape,
)
@ -241,7 +241,7 @@ pub fn format_expr(
} else if needs_space_before_range(context, lhs) {
format!(" {}", delim)
} else {
delim.into()
delim.to_owned()
};
rewrite_pair(
&*lhs,
@ -256,7 +256,7 @@ pub fn format_expr(
let sp_delim = if context.config.spaces_around_ranges() {
format!("{} ", delim)
} else {
delim.into()
delim.to_owned()
};
rewrite_unary_prefix(context, &sp_delim, &*rhs, shape)
}
@ -264,17 +264,17 @@ pub fn format_expr(
let sp_delim = if context.config.spaces_around_ranges() {
format!(" {}", delim)
} else {
delim.into()
delim.to_owned()
};
rewrite_unary_suffix(context, &sp_delim, &*lhs, shape)
}
(None, None) => Some(delim.into()),
(None, None) => Some(delim.to_owned()),
}
}
// We do not format these expressions yet, but they should still
// satisfy our width restrictions.
ast::ExprKind::InPlace(..) | ast::ExprKind::InlineAsm(..) => {
Some(context.snippet(expr.span).into())
Some(context.snippet(expr.span).to_owned())
}
ast::ExprKind::Catch(ref block) => {
if let rw @ Some(_) = rewrite_single_line_block(context, "do catch ", block, shape) {
@ -1308,7 +1308,7 @@ fn rewrite_match(
Some(format!("match {} {{}}", cond_str))
} else {
// Empty match with comments or inner attributes? We are not going to bother, sorry ;)
Some(context.snippet(span).into())
Some(context.snippet(span).to_owned())
}
} else {
Some(format!(
@ -1768,7 +1768,7 @@ pub fn rewrite_literal(context: &RewriteContext, l: &ast::Lit, shape: Shape) ->
match l.node {
ast::LitKind::Str(_, ast::StrStyle::Cooked) => rewrite_string_lit(context, l.span, shape),
_ => wrap_str(
context.snippet(l.span).into(),
context.snippet(l.span).to_owned(),
context.config.max_width(),
shape,
),
@ -1802,7 +1802,7 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
);
return wrap_str(indented_string_lit, context.config.max_width(), shape);
} else {
return wrap_str(string_lit.into(), context.config.max_width(), shape);
return wrap_str(string_lit.to_owned(), context.config.max_width(), shape);
}
}
@ -2534,7 +2534,7 @@ pub fn rewrite_field(
prefix_max_width: usize,
) -> Option<String> {
if contains_skip(&field.attrs) {
return Some(context.snippet(field.span()).into());
return Some(context.snippet(field.span()).to_owned());
}
let name = &field.ident.node.to_string();
if field.is_shorthand {

View File

@ -148,7 +148,7 @@ impl Rewrite for ast::UseTree {
let path_str = rewrite_prefix(&self.prefix, context, prefix_shape)?;
Some(format!("{}::*", path_str))
} else {
Some("*".into())
Some("*".to_owned())
}
}
ast::UseTreeKind::Simple(ident) => {
@ -184,7 +184,7 @@ fn rewrite_import(
.and_then(|shape| match tree.kind {
// If we have an empty nested group with no attributes, we erase it
ast::UseTreeKind::Nested(ref items) if items.is_empty() && attrs.is_empty() => {
Some("".into())
Some("".to_owned())
}
_ => tree.rewrite(context, shape),
});

View File

@ -382,7 +382,7 @@ impl<'a> FmtVisitor<'a> {
format_expr(e, ExprType::Statement, &self.get_context(), self.shape())
.map(|s| s + suffix)
.or_else(|| Some(self.snippet(e.span).into()))
.or_else(|| Some(self.snippet(e.span).to_owned()))
}
None => stmt.rewrite(&self.get_context(), self.shape()),
}
@ -526,7 +526,7 @@ impl<'a> FmtVisitor<'a> {
if contains_skip(&field.node.attrs) {
let lo = field.node.attrs[0].span.lo();
let span = mk_sp(lo, field.span.hi());
return Some(self.snippet(span).into());
return Some(self.snippet(span).to_owned());
}
let context = self.get_context();
@ -1428,7 +1428,7 @@ pub fn rewrite_struct_field(
) -> Option<String> {
if contains_skip(&field.attrs) {
let snippet = context.snippet(mk_sp(field.attrs[0].span.lo(), field.span.hi()));
return Some(snippet.into());
return Some(snippet.to_owned());
}
let type_annotation_spacing = type_annotation_spacing(context.config);

View File

@ -162,7 +162,7 @@ pub fn rewrite_macro(
loop {
match parse_macro_arg(&mut parser) {
Some(arg) => arg_vec.push(arg),
None => return Some(context.snippet(mac.span).into()),
None => return Some(context.snippet(mac.span).to_owned()),
}
match parser.token {
@ -182,13 +182,13 @@ pub fn rewrite_macro(
break;
}
}
None => return Some(context.snippet(mac.span).into()),
None => return Some(context.snippet(mac.span).to_owned()),
}
}
}
return Some(context.snippet(mac.span).into());
return Some(context.snippet(mac.span).to_owned());
}
_ => return Some(context.snippet(mac.span).into()),
_ => return Some(context.snippet(mac.span).to_owned()),
}
parser.bump();

View File

@ -122,7 +122,7 @@ impl Rewrite for Pat {
rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape)
}
// FIXME(#819) format pattern macros.
PatKind::Mac(..) => Some(context.snippet(self.span).into()),
PatKind::Mac(..) => Some(context.snippet(self.span).to_owned()),
}
}
}

View File

@ -180,10 +180,10 @@ mod test {
Mismatch {
line_number: 2,
lines: vec![
Context("two".into()),
Resulting("three".into()),
Expected("trois".into()),
Context("four".into()),
Context("two".to_owned()),
Resulting("three".to_owned()),
Expected("trois".to_owned()),
Context("four".to_owned()),
],
},
]
@ -201,18 +201,18 @@ mod test {
Mismatch {
line_number: 2,
lines: vec![
Context("two".into()),
Resulting("three".into()),
Expected("trois".into()),
Context("four".into()),
Context("two".to_owned()),
Resulting("three".to_owned()),
Expected("trois".to_owned()),
Context("four".to_owned()),
],
},
Mismatch {
line_number: 5,
lines: vec![
Resulting("five".into()),
Expected("cinq".into()),
Context("six".into()),
Resulting("five".to_owned()),
Expected("cinq".to_owned()),
Context("six".to_owned()),
],
},
]
@ -229,7 +229,7 @@ mod test {
vec![
Mismatch {
line_number: 3,
lines: vec![Resulting("three".into()), Expected("trois".into())],
lines: vec![Resulting("three".to_owned()), Expected("trois".to_owned())],
},
]
);
@ -245,7 +245,7 @@ mod test {
vec![
Mismatch {
line_number: 5,
lines: vec![Context("five".into()), Expected("".into())],
lines: vec![Context("five".to_owned()), Expected("".to_owned())],
},
]
);

View File

@ -420,7 +420,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
self.push_rewrite(item.span, rewrite);
}
ast::ItemKind::GlobalAsm(..) => {
let snippet = Some(self.snippet(item.span).into());
let snippet = Some(self.snippet(item.span).to_owned());
self.push_rewrite(item.span, snippet);
}
ast::ItemKind::MacroDef(..) => {
@ -831,7 +831,7 @@ impl Rewrite for ast::Attribute {
rewrite_comment(snippet, false, doc_shape, context.config)
} else {
if contains_comment(snippet) {
return Some(snippet.into());
return Some(snippet.to_owned());
}
// 1 = `[`
let shape = shape.offset_left(prefix.len() + 1)?;
@ -1043,7 +1043,7 @@ pub fn rewrite_extern_crate(context: &RewriteContext, item: &ast::Item) -> Optio
assert!(is_extern_crate(item));
let new_str = context.snippet(item.span);
Some(if contains_comment(&new_str) {
new_str.into()
new_str.to_owned()
} else {
let no_whitespace = &new_str.split_whitespace().collect::<Vec<&str>>().join(" ");
String::from(&*Regex::new(r"\s;").unwrap().replace(no_whitespace, ";"))