File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -865,9 +865,14 @@ pub trait LintContext: Sized {
865865
866866 if let Some ( positional_arg_to_replace) = position_sp_to_replace {
867867 let name = if is_formatting_arg { named_arg_name + "$" } else { named_arg_name } ;
868-
868+ let span_to_replace = if let Ok ( positional_arg_content) =
869+ self . sess ( ) . source_map ( ) . span_to_snippet ( positional_arg_to_replace) && positional_arg_content. starts_with ( ":" ) {
870+ positional_arg_to_replace. shrink_to_lo ( )
871+ } else {
872+ positional_arg_to_replace
873+ } ;
869874 db. span_suggestion_verbose (
870- positional_arg_to_replace ,
875+ span_to_replace ,
871876 "use the named argument by name to avoid ambiguity" ,
872877 name,
873878 Applicability :: MaybeIncorrect ,
Original file line number Diff line number Diff line change 1+ // When build the suggesttion take in consideration the `:?`
2+ // https://github.com/rust-lang/rust/issues/100648
3+ #![ deny( warnings) ]
4+
5+ fn main ( ) {
6+ println ! ( "hello {:?}" , world = "world" ) ;
7+ //~^ ERROR named argument `world` is not used by name
8+ //~| HELP use the named argument by name to avoid ambiguity
9+ //~| SUGGESTION world
10+ }
Original file line number Diff line number Diff line change 1+ error: named argument `world` is not used by name
2+ --> $DIR/sugg_with_positional_args_and_debug_fmt.rs:6:28
3+ |
4+ LL | println!("hello {:?}", world = "world");
5+ | ---- ^^^^^ this named argument is referred to by position in formatting string
6+ | |
7+ | this formatting argument uses named argument `world` by position
8+ |
9+ note: the lint level is defined here
10+ --> $DIR/sugg_with_positional_args_and_debug_fmt.rs:3:9
11+ |
12+ LL | #![deny(warnings)]
13+ | ^^^^^^^^
14+ = note: `#[deny(named_arguments_used_positionally)]` implied by `#[deny(warnings)]`
15+ help: use the named argument by name to avoid ambiguity
16+ |
17+ LL | println!("hello {world:?}", world = "world");
18+ | +++++
19+
20+ error: aborting due to previous error
21+
You can’t perform that action at this time.
0 commit comments