Skip to content

ICE in format macro #75307

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
andrewhickman opened this issue Aug 8, 2020 · 2 comments · Fixed by #75319
Closed

ICE in format macro #75307

andrewhickman opened this issue Aug 8, 2020 · 2 comments · Fixed by #75319
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@andrewhickman
Copy link
Contributor

Code

The full repository is here, on branch ice: https://github.com/andrewhickman/rusty-git/tree/ice

I minimized the code down to one line

static REGEX: () = format!(r"{:pad$}(.*){:pad$}<{:pad$}", pad = PADDING_CHARS);

Meta

rustc --version --verbose:

rustc 1.45.2 (d3fb005a3 2020-07-31)
binary: rustc
commit-hash: d3fb005a39e62501b8b0b356166e515ae24e2e54
commit-date: 2020-07-31
host: x86_64-pc-windows-msvc
release: 1.45.2
LLVM version: 10.0

I can also reproduce the bug on stable (1.45.2), beta (2020-07-23 6f95990) and nightly (2020-08-07 09f4c9f) versions in the playground

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src\librustc_builtin_macros\format.rs:369:76
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.2 (d3fb005a3 2020-07-31) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: could not compile `rusty-git`.

To learn more, run the command again with --verbose.
Backtrace

stack backtrace:
   0:     0x7ffa24de889e - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5a3d35d079d525a9
   1:     0x7ffa24e163bc - core::fmt::write::h85be0730687abf95
   2:     0x7ffa24dda4ec - <std::io::IoSlice as core::fmt::Debug>::fmt::h5e52c4dfa40f4d90
   3:     0x7ffa24dee21b - std::panicking::take_hook::h90751056b7e26ca7
   4:     0x7ffa24dede68 - std::panicking::take_hook::h90751056b7e26ca7
   5:     0x7ffa1c081e8a - rustc_driver::report_ice::h205eed652bfde463
   6:     0x7ffa24deeaa7 - std::panicking::rust_panic_with_hook::h292b8e657da16614
   7:     0x7ffa24dee5ff - rust_begin_unwind
   8:     0x7ffa24e12d00 - core::panicking::panic_fmt::h28702f841940f05a
   9:     0x7ffa24e12c4c - core::panicking::panic::ha33891627e0f1666
  10:     0x7ffa1e371375 - <rustc_builtin_macros::deriving::generic::find_type_parameters::Visitor as rustc_ast::visit::Visitor>::visit_mac::hab0dbee5ce67f782
  11:     0x7ffa1e3c9151 - <rustc_builtin_macros::format_foreign::printf::Num as core::fmt::Debug>::fmt::h27cc766b0d6416f8
  12:     0x7ffa1e3c482d - <rustc_builtin_macros::format_foreign::printf::Num as core::fmt::Debug>::fmt::h27cc766b0d6416f8
  13:     0x7ffa1e38097c - <rustc_builtin_macros::deriving::generic::find_type_parameters::Visitor as rustc_ast::visit::Visitor>::visit_mac::hab0dbee5ce67f782
  14:     0x7ffa1f3dc82b - rustc_expand::expand::MacroExpander::fully_expand_fragment::hb75febf9ffebd59c
  15:     0x7ffa1f3db191 - rustc_expand::expand::MacroExpander::expand_crate::heedeb684ea6c8395
  16:     0x7ffa1c1d3f27 - <<serde::de::impls::range::Field as serde::de::Deserialize>::deserialize::FieldVisitor as serde::de::Visitor>::expecting::h34013356ca70ebb0
  17:     0x7ffa1c24d22f - rustc_interface::passes::BoxedResolver::to_resolver_outputs::h071f543b3f8e8576
  18:     0x7ffa1c1e42ac - <<serde::de::impls::range::Field as serde::de::Deserialize>::deserialize::FieldVisitor as serde::de::Visitor>::expecting::h34013356ca70ebb0
  19:     0x7ffa1c1d5ff6 - <<serde::de::impls::range::Field as serde::de::Deserialize>::deserialize::FieldVisitor as serde::de::Visitor>::expecting::h34013356ca70ebb0
  20:     0x7ffa1c24bef4 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::compile::h9cc3880447401cd2
  21:     0x7ffa1c2154b8 - rustc_interface::queries::Queries::expansion::h83bb5b985eb35a30
  22:     0x7ffa1c04868f - <rustc_typeck::coherence::unsafety::UnsafetyChecker as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_impl_item::h9fa5ae9e085bfbd8
  23:     0x7ffa1c09bb8e - <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt::h308f39c80603f7ee
  24:     0x7ffa1c0981f9 - <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt::h308f39c80603f7ee
  25:     0x7ffa1c09ede9 - <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt::h308f39c80603f7ee
  26:     0x7ffa1c04cb93 - <rustc_mir::dataflow::framework::direction::Backward as rustc_mir::dataflow::framework::direction::Direction>::is_forward::h989a918c4093af52
  27:     0x7ffa24dfe33a - std::sys::windows::thread::Thread::new::he9d4c6ed5e9fd093
  28:     0x7ffa9e407bd4 - BaseThreadInitThunk
  29:     0x7ffa9fc2ce51 - RtlUserThreadStart

@andrewhickman andrewhickman added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 8, 2020
@jonas-schievink jonas-schievink added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 8, 2020
@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Aug 8, 2020

Reduced format invocation:

format!(r"{}{}{}", named_arg=1);

All of using an r"" literal, having a named argument, and referencing at least 3 positional arguments seem necessary.

@JohnTitor JohnTitor added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Aug 9, 2020
@estebank estebank self-assigned this Aug 9, 2020
estebank added a commit to estebank/rust that referenced this issue Aug 9, 2020
Remove usages of `unwrap` (even when some are safe today).
@Dylan-DPC-zz Dylan-DPC-zz added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 11, 2020
@Dylan-DPC-zz
Copy link

Marking this as p-medium based on the wg-prioritization discussion

bors added a commit to rust-lang-ci/rust that referenced this issue Aug 14, 2020
Rollup of 12 pull requests

Successful merges:

 - rust-lang#74650 (Correctly parse `{} && false` in tail expression)
 - rust-lang#75319 (Fix ICE rust-lang#75307 in `format`)
 - rust-lang#75417 (Don't spill operands onto the stack in naked functions)
 - rust-lang#75452 (self-profile: Cache more query key strings when doing self-profiling.)
 - rust-lang#75459 (fix LocalInfo doc comment)
 - rust-lang#75462 (Remove unused tcx parameter)
 - rust-lang#75467 (Fix E0741 error code explanation)
 - rust-lang#75471 (Change registered "program name" for -Cllvm-args usage messages)
 - rust-lang#75477 (Expand function pointer docs)
 - rust-lang#75479 (make rustc-docs component available to rustup)
 - rust-lang#75496 (Prioritization WG: Open Zulip topics only for `I-prioritize` issues)
 - rust-lang#75500 (Disable zlib in LLVM on aarch64-apple-darwin)

Failed merges:

r? @ghost
@bors bors closed this as completed in 8c361aa Aug 14, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants