|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then; |
2 | 2 | use clippy_utils::paths; |
3 | 3 | use clippy_utils::source::{snippet, snippet_opt}; |
| 4 | +use clippy_utils::sugg::Sugg; |
4 | 5 | use clippy_utils::ty::is_type_diagnostic_item; |
5 | 6 | use clippy_utils::{is_expn_of, last_path_segment, match_def_path, match_function_call}; |
6 | 7 | use if_chain::if_chain; |
@@ -100,15 +101,15 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: & |
100 | 101 | return Some(format!("{:?}.to_string()", s.as_str())); |
101 | 102 | } |
102 | 103 | } else { |
103 | | - let snip = snippet(cx, format_args.span, "<arg>"); |
| 104 | + let sugg = Sugg::hir(cx, format_args, "<arg>"); |
104 | 105 | if let ExprKind::MethodCall(path, _, _, _) = format_args.kind { |
105 | 106 | if path.ident.name == sym!(to_string) { |
106 | | - return Some(format!("{}", snip)); |
| 107 | + return Some(format!("{}", sugg)); |
107 | 108 | } |
108 | 109 | } else if let ExprKind::Binary(..) = format_args.kind { |
109 | | - return Some(format!("{}", snip)); |
| 110 | + return Some(format!("{}", sugg)); |
110 | 111 | } |
111 | | - return Some(format!("{}.to_string()", snip)); |
| 112 | + return Some(format!("{}.to_string()", sugg.maybe_par())); |
112 | 113 | } |
113 | 114 | } |
114 | 115 | } |
@@ -136,7 +137,7 @@ fn on_new_v1<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<Strin |
136 | 137 | if let Some(s_src) = snippet_opt(cx, lit.span) { |
137 | 138 | // Simulate macro expansion, converting {{ and }} to { and }. |
138 | 139 | let s_expand = s_src.replace("{{", "{").replace("}}", "}"); |
139 | | - return Some(format!("{}.to_string()", s_expand)) |
| 140 | + return Some(format!("{}.to_string()", s_expand)); |
140 | 141 | } |
141 | 142 | } else if s.as_str().is_empty() { |
142 | 143 | return on_argumentv1_new(cx, &tup[0], arms); |
|
0 commit comments