Repository: rust-lang/rustfmt (rust)

Issue:
ICE `Request to format inverted span`
```rust
fn find_errors(mut self) {
	let errors: Vec<> = vec!{
		#[debug_format = "A({})"]
		struct A {}
	};
}
```

```
RUST_BACKTRACE=full rustfmt treereduce.out --check
thread 'main' panicked at 'Request to format inverted span: /tmp/im/treereduce.out:3:3: 3:5', src/tools/rustfmt/src/missed_spans.rs:91:9
stack backtrace:
   0:     0x7fad40b65f8a - std::backtrace_rs::backtrace::libunwind::trace::hc36a5d781c5b5ccc
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fad40b65f8a - std::backtrace_rs::backtrace::trace_unsynchronized::hdf896053c14221b1
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fad40b65f8a - std::sys_common::backtrace::_print_fmt::h39cabfaabdc86ac1
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fad40b65f8a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h03d255761b970500
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fad40bca05f - core::fmt::write::h9be633e4e0b71092
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/core/src/fmt/mod.rs:1254:17
   5:     0x7fad40b58bc5 - std::io::Write::write_fmt::hf094eaeff4c6712a
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/io/mod.rs:1698:15
   6:     0x7fad40b65d55 - std::sys_common::backtrace::_print::hb3526973e1a9ef48
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fad40b65d55 - std::sys_common::backtrace::print::h8b0ebf35d627197b
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fad40b689fe - std::panicking::default_hook::{{closure}}::h800b864dad9a2ddb
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:269:22
   9:     0x7fad40b687a5 - std::panicking::default_hook::h47199288a8f9de13
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:288:9
  10:     0x7fad40b6906e - std::panicking::rust_panic_with_hook::hb6edee1e00f0405f
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:690:13
  11:     0x7fad40b68f69 - std::panicking::begin_panic_handler::{{closure}}::h8ad86fc31155b4e5
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:581:13
  12:     0x7fad40b663f6 - std::sys_common::backtrace::__rust_end_short_backtrace::h1382820b1dda7cef
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x7fad40b68cc2 - rust_begin_unwind
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:577:5
  14:     0x7fad40bc6373 - core::panicking::panic_fmt::hf50318b79d34c964
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/core/src/panicking.rs:67:14
  15:     0x55f00e44727d - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::format_missing_indent
  16:     0x55f00e45927b - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::push_rewrite
  17:     0x55f00e45a3e5 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_attrs
  18:     0x55f00e454e21 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_item
  19:     0x55f00e38ee83 - rustfmt_nightly[2b26fbdfc5662f3a]::macros::rewrite_macro_inner
  20:     0x55f00e38ccc3 - rustfmt_nightly[2b26fbdfc5662f3a]::macros::rewrite_macro
  21:     0x55f00e49264c - rustfmt_nightly[2b26fbdfc5662f3a]::expr::format_expr
  22:     0x55f00e4a311e - rustfmt_nightly[2b26fbdfc5662f3a]::expr::rewrite_assign_rhs_expr::<rustc_ast[afc3ec1cae29e349]::ast::Expr>
  23:     0x55f00e4a4761 - rustfmt_nightly[2b26fbdfc5662f3a]::expr::rewrite_assign_rhs_with::<alloc[4793a7dc0fb9f9dd]::string::String, rustc_ast[afc3ec1cae29e349]::ast::Expr>
  24:     0x55f00e3f7586 - <rustc_ast[afc3ec1cae29e349]::ast::Local as rustfmt_nightly[2b26fbdfc5662f3a]::rewrite::Rewrite>::rewrite
  25:     0x55f00e4265b1 - rustfmt_nightly[2b26fbdfc5662f3a]::stmt::format_stmt
  26:     0x55f00e45ac4d - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::walk_stmts
  27:     0x55f00e4516b8 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_block
  28:     0x55f00e454335 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_fn
  29:     0x55f00e455532 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_item
  30:     0x55f00e44a259 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_items_with_reordering
  31:     0x55f00e45a60f - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::walk_mod_items
  32:     0x55f00e45b207 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::format_separate_mod
  33:     0x55f00e2de0c5 - rustfmt_nightly[2b26fbdfc5662f3a]::formatting::format_project::<rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>
  34:     0x55f00e2dc990 - <scoped_tls[32dd083a3f62f99a]::ScopedKey<rustc_span[ea3aeb57fd08449]::SessionGlobals>>::with::<<rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::format_input_inner::{closure#0}, core[c98013cfbe010fb2]::result::Result<rustfmt_nightly[2b26fbdfc5662f3a]::FormatReport, rustfmt_nightly[2b26fbdfc5662f3a]::ErrorKind>>
  35:     0x55f00e2d9a3f - <scoped_tls[32dd083a3f62f99a]::ScopedKey<rustc_span[ea3aeb57fd08449]::SessionGlobals>>::set::<rustc_span[ea3aeb57fd08449]::create_session_if_not_set_then<core[c98013cfbe010fb2]::result::Result<rustfmt_nightly[2b26fbdfc5662f3a]::FormatReport, rustfmt_nightly[2b26fbdfc5662f3a]::ErrorKind>, <rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}, core[c98013cfbe010fb2]::result::Result<rustfmt_nightly[2b26fbdfc5662f3a]::FormatReport, rustfmt_nightly[2b26fbdfc5662f3a]::ErrorKind>>
  36:     0x55f00e3026b0 - <rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::format
  37:     0x55f00e2f1b35 - rustfmt[e5cca7ecbdfbf507]::format_and_emit_report::<std[86a3120b066ce118]::io::stdio::Stdout>
  38:     0x55f00e300be9 - <rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::override_config::<rustfmt[e5cca7ecbdfbf507]::format::{closure#0}, ()>
  39:     0x55f00e2f0895 - rustfmt[e5cca7ecbdfbf507]::execute
  40:     0x55f00e2ee251 - rustfmt[e5cca7ecbdfbf507]::main
  41:     0x55f00e3014e3 - std[86a3120b066ce118]::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  42:     0x55f00e2ffd29 - std[86a3120b066ce118]::rt::lang_start::<()>::{closure#0}
  43:     0x7fad40b4979e - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h8fb8db51461160a5
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/core/src/ops/function.rs:287:13
  44:     0x7fad40b4979e - std::panicking::try::do_call::h8cad0bb136701789
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:485:40
  45:     0x7fad40b4979e - std::panicking::try::h3a59b3d28fab2a12
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:449:19
  46:     0x7fad40b4979e - std::panic::catch_unwind::h257e63b47d64b708
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panic.rs:140:14
  47:     0x7fad40b4979e - std::rt::lang_start_internal::{{closure}}::h6cbe6465a0c54d37
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/rt.rs:148:48
  48:     0x7fad40b4979e - std::panicking::try::do_call::h065165cc1f86d7cb
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:485:40
  49:     0x7fad40b4979e - std::panicking::try::h36cd654271848729
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:449:19
  50:     0x7fad40b4979e - std::panic::catch_unwind::h6b02c76e9346c231
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panic.rs:140:14
  51:     0x7fad40b4979e - std::rt::lang_start_internal::h6fbc0eb973b8dfa5
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/rt.rs:148:20
  52:     0x55f00e2f28d5 - main
  53:     0x7fad40766790 - <unknown>
  54:     0x7fad4076684a - __libc_start_main
  55:     0x55f00e2d5c19 - <unknown>
  56:                0x0 - <unknown>
thread 'main' panicked at 'Request to format inverted span: /tmp/im/treereduce.out:3:3: 3:5', src/tools/rustfmt/src/missed_spans.rs:91:9
stack backtrace:
   0:     0x7fad40b65f8a - std::backtrace_rs::backtrace::libunwind::trace::hc36a5d781c5b5ccc
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fad40b65f8a - std::backtrace_rs::backtrace::trace_unsynchronized::hdf896053c14221b1
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fad40b65f8a - std::sys_common::backtrace::_print_fmt::h39cabfaabdc86ac1
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fad40b65f8a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h03d255761b970500
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fad40bca05f - core::fmt::write::h9be633e4e0b71092
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/core/src/fmt/mod.rs:1254:17
   5:     0x7fad40b58bc5 - std::io::Write::write_fmt::hf094eaeff4c6712a
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/io/mod.rs:1698:15
   6:     0x7fad40b65d55 - std::sys_common::backtrace::_print::hb3526973e1a9ef48
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7fad40b65d55 - std::sys_common::backtrace::print::h8b0ebf35d627197b
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7fad40b689fe - std::panicking::default_hook::{{closure}}::h800b864dad9a2ddb
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:269:22
   9:     0x7fad40b687a5 - std::panicking::default_hook::h47199288a8f9de13
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:288:9
  10:     0x7fad40b6906e - std::panicking::rust_panic_with_hook::hb6edee1e00f0405f
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:690:13
  11:     0x7fad40b68f69 - std::panicking::begin_panic_handler::{{closure}}::h8ad86fc31155b4e5
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:581:13
  12:     0x7fad40b663f6 - std::sys_common::backtrace::__rust_end_short_backtrace::h1382820b1dda7cef
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x7fad40b68cc2 - rust_begin_unwind
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:577:5
  14:     0x7fad40bc6373 - core::panicking::panic_fmt::hf50318b79d34c964
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/core/src/panicking.rs:67:14
  15:     0x55f00e44727d - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::format_missing_indent
  16:     0x55f00e45927b - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::push_rewrite
  17:     0x55f00e45a3e5 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_attrs
  18:     0x55f00e454e21 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_item
  19:     0x55f00e38ee83 - rustfmt_nightly[2b26fbdfc5662f3a]::macros::rewrite_macro_inner
  20:     0x55f00e38ccc3 - rustfmt_nightly[2b26fbdfc5662f3a]::macros::rewrite_macro
  21:     0x55f00e49264c - rustfmt_nightly[2b26fbdfc5662f3a]::expr::format_expr
  22:     0x55f00e4a32e0 - rustfmt_nightly[2b26fbdfc5662f3a]::expr::rewrite_assign_rhs_expr::<rustc_ast[afc3ec1cae29e349]::ast::Expr>
  23:     0x55f00e4a4761 - rustfmt_nightly[2b26fbdfc5662f3a]::expr::rewrite_assign_rhs_with::<alloc[4793a7dc0fb9f9dd]::string::String, rustc_ast[afc3ec1cae29e349]::ast::Expr>
  24:     0x55f00e3f7586 - <rustc_ast[afc3ec1cae29e349]::ast::Local as rustfmt_nightly[2b26fbdfc5662f3a]::rewrite::Rewrite>::rewrite
  25:     0x55f00e4265b1 - rustfmt_nightly[2b26fbdfc5662f3a]::stmt::format_stmt
  26:     0x55f00e45ac4d - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::walk_stmts
  27:     0x55f00e4516b8 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_block
  28:     0x55f00e454335 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_fn
  29:     0x55f00e455532 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_item
  30:     0x55f00e44a259 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::visit_items_with_reordering
  31:     0x55f00e45a60f - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::walk_mod_items
  32:     0x55f00e45b207 - <rustfmt_nightly[2b26fbdfc5662f3a]::visitor::FmtVisitor>::format_separate_mod
  33:     0x55f00e2de0c5 - rustfmt_nightly[2b26fbdfc5662f3a]::formatting::format_project::<rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>
  34:     0x55f00e2dc990 - <scoped_tls[32dd083a3f62f99a]::ScopedKey<rustc_span[ea3aeb57fd08449]::SessionGlobals>>::with::<<rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::format_input_inner::{closure#0}, core[c98013cfbe010fb2]::result::Result<rustfmt_nightly[2b26fbdfc5662f3a]::FormatReport, rustfmt_nightly[2b26fbdfc5662f3a]::ErrorKind>>
  35:     0x55f00e2d9a3f - <scoped_tls[32dd083a3f62f99a]::ScopedKey<rustc_span[ea3aeb57fd08449]::SessionGlobals>>::set::<rustc_span[ea3aeb57fd08449]::create_session_if_not_set_then<core[c98013cfbe010fb2]::result::Result<rustfmt_nightly[2b26fbdfc5662f3a]::FormatReport, rustfmt_nightly[2b26fbdfc5662f3a]::ErrorKind>, <rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}, core[c98013cfbe010fb2]::result::Result<rustfmt_nightly[2b26fbdfc5662f3a]::FormatReport, rustfmt_nightly[2b26fbdfc5662f3a]::ErrorKind>>
  36:     0x55f00e3026b0 - <rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::format
  37:     0x55f00e2f1b35 - rustfmt[e5cca7ecbdfbf507]::format_and_emit_report::<std[86a3120b066ce118]::io::stdio::Stdout>
  38:     0x55f00e300be9 - <rustfmt_nightly[2b26fbdfc5662f3a]::Session<std[86a3120b066ce118]::io::stdio::Stdout>>::override_config::<rustfmt[e5cca7ecbdfbf507]::format::{closure#0}, ()>
  39:     0x55f00e2f0895 - rustfmt[e5cca7ecbdfbf507]::execute
  40:     0x55f00e2ee251 - rustfmt[e5cca7ecbdfbf507]::main
  41:     0x55f00e3014e3 - std[86a3120b066ce118]::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  42:     0x55f00e2ffd29 - std[86a3120b066ce118]::rt::lang_start::<()>::{closure#0}
  43:     0x7fad40b4979e - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h8fb8db51461160a5
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/core/src/ops/function.rs:287:13
  44:     0x7fad40b4979e - std::panicking::try::do_call::h8cad0bb136701789
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:485:40
  45:     0x7fad40b4979e - std::panicking::try::h3a59b3d28fab2a12
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:449:19
  46:     0x7fad40b4979e - std::panic::catch_unwind::h257e63b47d64b708
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panic.rs:140:14
  47:     0x7fad40b4979e - std::rt::lang_start_internal::{{closure}}::h6cbe6465a0c54d37
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/rt.rs:148:48
  48:     0x7fad40b4979e - std::panicking::try::do_call::h065165cc1f86d7cb
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:485:40
  49:     0x7fad40b4979e - std::panicking::try::h36cd654271848729
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panicking.rs:449:19
  50:     0x7fad40b4979e - std::panic::catch_unwind::h6b02c76e9346c231
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/panic.rs:140:14
  51:     0x7fad40b4979e - std::rt::lang_start_internal::h6fbc0eb973b8dfa5
                               at /rustc/3a8a131e9509c478ece1c58fe0ea2d49463d2300/library/std/src/rt.rs:148:20
  52:     0x55f00e2f28d5 - main
  53:     0x7fad40766790 - <unknown>
  54:     0x7fad4076684a - __libc_start_main
  55:     0x55f00e2d5c19 - <unknown>
  56:                0x0 - <unknown>
Diff in /tmp/im/treereduce.out at line 1:
 fn find_errors(mut self) {
-	let errors: Vec<> = vec!{
+    let errors: Vec = vec!{
 		#[debug_format = "A({})"]
 		struct A {}
 	};
```

Pull request:
Prevent ICE when formatting item-only `vec!{}`
Prevent ICE when formatting item-only `vec!{}`

Fixes #5735

Attempting to format invocations of macros which are considered "forced bracket macros" (currently only `vec!`), but are invoked with braces instead of brackets, and contain only items in their token trees, currently triggers an ICE in rustfmt. This is because the function that handles formatting macro invocations containing only items, `rewrite_macro_with_items`, assumes that the forced delimiter style of the macro being formatted is the same as the delimiter style in the macro's source text when attempting to locate the span after the macro's opening delimiter. This leads to the construction of an invalid span, triggering the ICE.

The fix here is to pass the old delimiter style to `rewrite_macro_with_items` as well, so that it can successfully locate the span.

----

Hi rustfmt'ers! I'm back again with another ICE fix. Some notes for the reviewer:

- With how I've implemented this fix, the original reproducing case
```rust
fn find_errors(mut self) {
	let errors: Vec<> = vec!{
		#[debug_format = "A({})"]
		struct A {}
	};
}
```
will be formatted into
```rust
fn find_errors(mut self) {
    let errors: Vec = vec![
        #[debug_format = "A({})"]
        struct A {}
    ];
}
```
I understand that the team's stance is that braced macro invocations should generally be left unformatted. However, the current behaviour of `rustfmt` on braced `vec!` invocations is to format them. That is, before this PR, `rustfmt` will turn `vec!{1, struct X {} }` into `vec![1, struct X {}];`.
My PR doesn't change this behaviour. It just extends a similar behaviour to `vec!` invocations that contain only items. So with my PR, whereas formatting `vec!{ struct X {} }` would previously have triggered an ICE, it's now formatted into 
```rust
vec![
    struct X {}
];
```
I'm not entirely sure that this is the 'right' direction to go in, but the alternative of leaving braced, item-only `vec!` invocations unformatted seemed about equally surprising to me from a user perspective. Any feedback here is appreciated, and I'm happy to tweak the implementation to whatever behaviour the team thinks is best.

- I've also included a small refactoring commit of some redundancy I noticed while working in `macros.rs`. I'm happy to split that off into a separate PR if that's what people prefer.

- Clippy isn't happy that I've added another parameter to `rewrite_macro_with_items`, pushing it over the threshold of 7 parameters. I didn't see a way to cleanly keep it below the threshold while still passing in the original delimiter style, but as usual any suggestions are appreciated.

Patch:
diff --git a/src/macros.rs b/src/macros.rs
index b6a49536..8047ab03 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -255,6 +255,7 @@ fn rewrite_macro_inner(
             &macro_name,
             shape,
             style,
+            original_style,
             position,
             mac.span(),
         );
@@ -295,20 +296,19 @@ fn rewrite_macro_inner(
                 // If we are rewriting `vec!` macro or other special macros,
                 // then we can rewrite this as a usual array literal.
                 // Otherwise, we must preserve the original existence of trailing comma.
-                let macro_name = &macro_name.as_str();
                 let mut force_trailing_comma = if trailing_comma {
                     Some(SeparatorTactic::Always)
                 } else {
                     Some(SeparatorTactic::Never)
                 };
-                if FORCED_BRACKET_MACROS.contains(macro_name) && !is_nested_macro {
+                if is_forced_bracket && !is_nested_macro {
                     context.leave_macro();
                     if context.use_block_indent() {
                         force_trailing_comma = Some(SeparatorTactic::Vertical);
                     };
                 }
                 let rewrite = rewrite_array(
-                    macro_name,
+                    &macro_name,
                     arg_vec.iter(),
                     mac.span(),
                     context,
@@ -1402,15 +1402,19 @@ fn rewrite_macro_with_items(
     macro_name: &str,
     shape: Shape,
     style: Delimiter,
+    original_style: Delimiter,
     position: MacroPosition,
     span: Span,
 ) -> Option<String> {
-    let (opener, closer) = match style {
-        Delimiter::Parenthesis => ("(", ")"),
-        Delimiter::Bracket => ("[", "]"),
-        Delimiter::Brace => (" {", "}"),
-        _ => return None,
+    let style_to_delims = |style| match style {
+        Delimiter::Parenthesis => Some(("(", ")")),
+        Delimiter::Bracket => Some(("[", "]")),
+        Delimiter::Brace => Some((" {", "}")),
+        _ => None,
     };
+
+    let (opener, closer) = style_to_delims(style)?;
+    let (original_opener, _) = style_to_delims(original_style)?;
     let trailing_semicolon = match style {
         Delimiter::Parenthesis | Delimiter::Bracket if position == MacroPosition::Item => ";",
         _ => "",
@@ -1418,7 +1422,13 @@ fn rewrite_macro_with_items(
 
     let mut visitor = FmtVisitor::from_context(context);
     visitor.block_indent = shape.indent.block_indent(context.config);
-    visitor.last_pos = context.snippet_provider.span_after(span, opener.trim());
+
+    // The current opener may be different from the original opener. This can happen
+    // if our macro is a forced bracket macro originally written with non-bracket
+    // delimiters. We need to use the original opener to locate the span after it.
+    visitor.last_pos = context
+        .snippet_provider
+        .span_after(span, original_opener.trim());
     for item in items {
         let item = match item {
             MacroArg::Item(item) => item,


Test patch:
diff --git a/tests/source/issue_5735.rs b/tests/source/issue_5735.rs
new file mode 100644
index 00000000..7708d028
--- /dev/null
+++ b/tests/source/issue_5735.rs
@@ -0,0 +1,6 @@
+fn find_errors(mut self) {
+	let errors: Vec<> = vec!{
+		#[debug_format = "A({})"]
+		struct A {}
+	};
+}
diff --git a/tests/target/issue_5735.rs b/tests/target/issue_5735.rs
new file mode 100644
index 00000000..2d137630
--- /dev/null
+++ b/tests/target/issue_5735.rs
@@ -0,0 +1,6 @@
+fn find_errors(mut self) {
+    let errors: Vec = vec![
+        #[debug_format = "A({})"]
+        struct A {}
+    ];
+}