Skip to content

Incorrect fix for to_string_in_format_args #9540

Closed
@nyurik

Description

@nyurik

I just discovered another bug in the format args parser FormatArgsExpn::parse while creating more tests for #9233.

Add this test case to the tests/ui/format_args.rs main() to see it fail:

print!("error: something failed at {}", (Location::caller().to_string()));
//                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  (does not include parens)

The resulting format_args.args[0].param.value has a span does NOT include the surrounding parenthesis, which means that it suggest this:

Auto-fix is incorrectly suggesting this:

error: `to_string` applied to a type that implements `Display` in `print!` args
  --> $DIR/format_args.rs:86:64
   |
LL |     print!("error: something failed at {}", (Location::caller().to_string()));
   |                                                                ^^^^^^^^^^^^^ help: remove this

which results in an incompilabre

print!("error: something failed at {}", (Location::caller());  // <-- missing closing parenthesis

cc: @Alexendoo

Metadata

Metadata

Assignees

Labels

I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions