- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Description
The span of this error is useful:
error[E0282]: type annotations needed
  |
# |     println!("{:?}", []);
  |                      ^^ cannot infer type
  |
However, in a slightly more complicated println, the same error points at the entire macro invocation:
error[E0282]: type annotations needed
  |
# |     println!("{:?} {a} {a:?}", [], a = 1 + 1);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
  |
It should have just pointed at [] (or perhaps {:?}), rather than the entire macro call.
The simple println results in this case in format_args lowering:
rust/compiler/rustc_ast_lowering/src/format.rs
Lines 513 to 520 in cb0d6e7
| } else if use_simple_array { | |
| // Generate: | |
| // &[ | |
| // <core::fmt::Argument>::new_display(&arg0), | |
| // <core::fmt::Argument>::new_lower_hex(&arg1), | |
| // <core::fmt::Argument>::new_debug(&arg2), | |
| // … | |
| // ] | 
The more complicated println results in this case in format_args lowering:
rust/compiler/rustc_ast_lowering/src/format.rs
Lines 538 to 547 in cb0d6e7
| } else { | |
| // Generate: | |
| // &match (&arg0, &arg1, &…) { | |
| // args => [ | |
| // <core::fmt::Argument>::new_display(args.0), | |
| // <core::fmt::Argument>::new_lower_hex(args.1), | |
| // <core::fmt::Argument>::new_debug(args.0), | |
| // … | |
| // ] | |
| // } | 
It'd be nice if both cases would cause any type/trait errors to be reported on the argument (or placeholders), instead of on the span of the entire macro invocation.
I'm not sure if this requires changes in rustc_ast_lowering, or in the code that reports the type errors.