]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/format.rs
Always include a position span in rustc_parse_format::Argument
[rust.git] / clippy_lints / src / format.rs
index 3084c70589fa331fe89206432622d0ead7fe36fc..925a8cb8deed94ff792f3f4a7ce144ec5b2486c5 100644 (file)
@@ -9,7 +9,7 @@
 use rustc_middle::ty;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::symbol::kw;
-use rustc_span::{sym, BytePos, Span};
+use rustc_span::{sym, Span};
 
 declare_clippy_lint! {
     /// ### What it does
@@ -82,25 +82,10 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
                 then {
                     let is_new_string = match value.kind {
                         ExprKind::Binary(..) => true,
-                        ExprKind::MethodCall(path, ..) => path.ident.name.as_str() == "to_string",
+                        ExprKind::MethodCall(path, ..) => path.ident.name == sym::to_string,
                         _ => false,
                     };
-                    let sugg = if format_args.format_string_span.contains(value.span) {
-                        // Implicit argument. e.g. `format!("{x}")` span points to `{x}`
-                        let spdata = value.span.data();
-                        let span = Span::new(
-                            spdata.lo + BytePos(1),
-                            spdata.hi - BytePos(1),
-                            spdata.ctxt,
-                            spdata.parent
-                        );
-                        let snip = snippet_with_applicability(cx, span, "..", &mut applicability);
-                        if is_new_string {
-                            snip.into()
-                        } else {
-                            format!("{snip}.to_string()")
-                        }
-                    } else if is_new_string {
+                    let sugg = if is_new_string {
                         snippet_with_applicability(cx, value.span, "..", &mut applicability).into_owned()
                     } else {
                         let sugg = Sugg::hir_with_applicability(cx, value, "<arg>", &mut applicability);