Skip to content

Compiler Panic on specific macro expansion #103222

New issue

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

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

Already on GitHub? Sign in to your account

Closed
blaine-dodson opened this issue Oct 19, 2022 · 3 comments · Fixed by #103224
Closed

Compiler Panic on specific macro expansion #103222

blaine-dodson opened this issue Oct 19, 2022 · 3 comments · Fixed by #103224
Labels
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.

Comments

@blaine-dodson
Copy link

Code

macro_rules! inst {
    ($name:ident ( $exe:expr;)) => {
        Instruction {
            execute: $exe,
        }
    };
}

struct Instruction {
    execute: fn(),
}

fn main() {
    let _i = inst!(
        INST ( || { Err(()) }; )
    );
}

Meta

rustc --version --verbose:

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-pc-windows-msvc
release: 1.63.0
LLVM version: 14.0.5

Error output

> rustc .\src\main.rs
...

error: internal compiler error: compiler\rustc_codegen_llvm\src\context.rs:975:13: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout
  --> .\src\main.rs:14:1
   |
14 | fn main() {
   | ^^^^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f\compiler\rustc_errors\src\lib.rs:1331:9

... backtrace here ...

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

stack backtrace:
   0:     0x7ffaf4379eff - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he6ddce8c3451a57e
   1:     0x7ffaf43b50ea - core::fmt::write::h365ccbbdf4748102
   2:     0x7ffaf436c2c9 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h29d49dd5c0747aeb
   3:     0x7ffaf437d7eb - std::panicking::default_hook::hb4271f543ae89c34
   4:     0x7ffaf437d46b - std::panicking::default_hook::hb4271f543ae89c34
   5:     0x7ffae33d7b76 - rustc_driver[183ba813ad9b9dae]::pretty::print_after_hir_lowering
   6:     0x7ffaf437df92 - std::panicking::rust_panic_with_hook::he1475943c7445074
   7:     0x7ffae3543835 - <rustc_codegen_llvm[1e06b400de6132fd]::llvm_::archive_ro::ArchiveRO as core[e6ecc7be13daddac]::ops::drop::Drop>::drop
   8:     0x7ffae3542e29 - <rustc_codegen_llvm[1e06b400de6132fd]::llvm_::archive_ro::ArchiveRO as core[e6ecc7be13daddac]::ops::drop::Drop>::drop
   9:     0x7ffae7e2d079 - _rust_realloc
  10:     0x7ffae358ca09 - <rustc_codegen_llvm[1e06b400de6132fd]::llvm_::ffi::coverageinfo::CounterMappingRegion as core[e6ecc7be13daddac]::fmt::Debug>::fmt
  11:     0x7ffae358c9a1 - <rustc_codegen_llvm[1e06b400de6132fd]::llvm_::ffi::coverageinfo::CounterMappingRegion as core[e6ecc7be13daddac]::fmt::Debug>::fmt
  12:     0x7ffae358c362 - <rustc_codegen_llvm[1e06b400de6132fd]::llvm_::ffi::coverageinfo::CounterMappingRegion as core[e6ecc7be13daddac]::fmt::Debug>::fmt
  13:     0x7ffae35e859c - <rustc_target[a8fc8fc8f2adb8e6]::abi::TyAndLayout<rustc_middle[859f69f7102253e7]::ty::Ty> as rustc_codegen_llvm[1e06b400de6132fd]::type_of::LayoutLlvmExt>::pointee_info_at
  14:     0x7ffae35e83bc - <rustc_target[a8fc8fc8f2adb8e6]::abi::TyAndLayout<rustc_middle[859f69f7102253e7]::ty::Ty> as rustc_codegen_llvm[1e06b400de6132fd]::type_of::LayoutLlvmExt>::pointee_info_at
  15:     0x7ffae7e2d10a - _rust_realloc
  16:     0x7ffae3602505 - <rustc_codegen_llvm[1e06b400de6132fd]::builder::Builder as rustc_codegen_ssa[c26d335c855d8e25]::traits::builder::BuilderMethods>::va_arg
  17:     0x7ffae35ee7de - <rustc_target[a8fc8fc8f2adb8e6]::abi::TyAndLayout<rustc_middle[859f69f7102253e7]::ty::Ty> as rustc_codegen_llvm[1e06b400de6132fd]::type_of::LayoutLlvmExt>::pointee_info_at
  18:     0x7ffae35f9756 - <rustc_target[a8fc8fc8f2adb8e6]::abi::TyAndLayout<rustc_middle[859f69f7102253e7]::ty::Ty> as rustc_codegen_llvm[1e06b400de6132fd]::type_of::LayoutLlvmExt>::pointee_info_at
  19:     0x7ffae35ebe85 - <rustc_target[a8fc8fc8f2adb8e6]::abi::TyAndLayout<rustc_middle[859f69f7102253e7]::ty::Ty> as rustc_codegen_llvm[1e06b400de6132fd]::type_of::LayoutLlvmExt>::pointee_info_at
  20:     0x7ffae362e633 - <rustc_codegen_llvm[1e06b400de6132fd]::back::write::DiagnosticHandlers as core[e6ecc7be13daddac]::ops::drop::Drop>::drop
  21:     0x7ffae3661a46 - <rustc_codegen_llvm[1e06b400de6132fd]::debuginfo::utils::FatPtrKind as core[e6ecc7be13daddac]::fmt::Debug>::fmt
  22:     0x7ffae353ae32 - rustc_interface[fd4bce9b80171ecf]::passes::analysis
  23:     0x7ffae35902c5 - <rustc_codegen_llvm[1e06b400de6132fd]::llvm_::ffi::coverageinfo::CounterMappingRegion as core[e6ecc7be13daddac]::fmt::Debug>::fmt
  24:     0x7ffae3619481 - <rustc_codegen_llvm[1e06b400de6132fd]::base::ValueIter as core[e6ecc7be13daddac]::iter::traits::iterator::Iterator>::next
  25:     0x7ffae35b4ac1 - rustc_codegen_llvm[1e06b400de6132fd]::llvm_util::target_features
  26:     0x7ffae3618e68 - <rustc_codegen_llvm[1e06b400de6132fd]::base::ValueIter as core[e6ecc7be13daddac]::iter::traits::iterator::Iterator>::next
  27:     0x7ffae356d63d - <rustc_codegen_llvm[1e06b400de6132fd]::LlvmCodegenBackend as rustc_codegen_ssa[c26d335c855d8e25]::traits::backend::CodegenBackend>::codegen_crate
  28:     0x7ffae34d6262 - rustc_interface[fd4bce9b80171ecf]::passes::analysis
  29:     0x7ffae34d4440 - <rustc_interface[fd4bce9b80171ecf]::passes::LintStoreExpandImpl as rustc_expand[e217e340a00cf420]::base::LintStoreExpand>::pre_expansion_lint
  30:     0x7ffae349e900 - <rustc_interface[fd4bce9b80171ecf]::queries::Queries>::ongoing_codegen
  31:     0x7ffae3364edb - <rustc_ast_passes[79adae6e0e894ada]::node_count::NodeCounter as rustc_ast[a6530cc9c718edce]::visit::Visitor>::visit_ident
  32:     0x7ffae33e6425 - <rustc_driver[183ba813ad9b9dae]::Compilation as core[e6ecc7be13daddac]::fmt::Debug>::fmt
  33:     0x7ffae33660ed - <rustc_ast_passes[79adae6e0e894ada]::node_count::NodeCounter as rustc_ast[a6530cc9c718edce]::visit::Visitor>::visit_ident
  34:     0x7ffae33ce416 - <rustc_metadata[96069ccbf5a419d0]::rmeta::encoder::EncodeContext as rustc_serialize[2ae8dcffef6f4bd]::serialize::Encoder>::emit_raw_bytes
  35:     0x7ffae33901d8 - <rustc_driver[183ba813ad9b9dae]::args::Error as core[e6ecc7be13daddac]::fmt::Debug>::fmt
  36:     0x7ffaf438f2bc - std::sys::windows::thread::Thread::new::h91dd265f074e3962
  37:     0x7ffb46107034 - BaseThreadInitThunk
  38:     0x7ffb479826a1 - RtlUserThreadStart

@blaine-dodson blaine-dodson 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 Oct 19, 2022
@blaine-dodson blaine-dodson changed the title compiler\rustc_codegen_llvm\src\context.rs:975:13: failed to get layout for [type error] Compiler Panic on specific macro expansion Oct 19, 2022
@blaine-dodson
Copy link
Author

Also on latest stable.

Meta

rustc --version --verbose:

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-pc-windows-msvc
release: 1.64.0
LLVM version: 14.0.6

Error

> rustc .\src\main.rs
warning: field `execute` is never read
  --> .\src\main.rs:10:5
   |
9  | struct Instruction {
   |        ----------- field in this struct
10 |     execute: fn(),
   |     ^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler\rustc_codegen_llvm\src\context.rs:974:13: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout
  --> .\src\main.rs:13:1
   |
13 | fn main() {
   | ^^^^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52\compiler\rustc_errors\src\lib.rs:1332:9
stack backtrace:
   0:     0x7ffaea079fbf - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf958371dc84a30d1
   1:     0x7ffaea0b4b5a - core::fmt::write::h8bc5f8dfcde4777f
   2:     0x7ffaea06c749 - <std::io::IoSlice as core::fmt::Debug>::fmt::hab1bb118c5bfde47
   3:     0x7ffaea07d8bb - std::panicking::default_hook::hcfea80c086f9466a
   4:     0x7ffaea07d535 - std::panicking::default_hook::hcfea80c086f9466a
   5:     0x7ffae547c404 - rustc_driver[a0a607043376aa59]::pretty::print_after_hir_lowering
   6:     0x7ffaea07e062 - std::panicking::rust_panic_with_hook::h43b18a7cf7089063
   7:     0x7ffae5571203 - rustc_codegen_llvm[293115cdcc5d4626]::llvm_::last_error
   8:     0x7ffae5570e99 - rustc_codegen_llvm[293115cdcc5d4626]::llvm_::last_error
   9:     0x7ffae5557f59 - <rustc_data_structures[34e88743362a5251]::profiling::EventFilter as core[f4e460384c48c425]::fmt::UpperHex>::fmt
  10:     0x7ffae55985e9 - <rustc_codegen_llvm[293115cdcc5d4626]::debuginfo::utils::FatPtrKind as core[f4e460384c48c425]::fmt::Debug>::fmt
::fmt::Debug>::fmt
  12:     0x7ffae55968d2 - <rustc_codegen_llvm[293115cdcc5d4626]::debuginfo::utils::FatPtrKind as core[f4e460384c48c425]::fmt::Debug>::fmt
  13:     0x7ffae55583f2 - <rustc_data_structures[34e88743362a5251]::profiling::EventFilter as core[f4e460384c48c425]::fmt::UpperHex>::fmt
  14:     0x7ffae5558298 - <rustc_data_structures[34e88743362a5251]::profiling::EventFilter as core[f4e460384c48c425]::fmt::UpperHex>::fmt
  15:     0x7ffae5558256 - <rustc_data_structures[34e88743362a5251]::profiling::EventFilter as core[f4e460384c48c425]::fmt::UpperHex>::fmt
  16:     0x7ffae5589d7f - <rustc_codegen_llvm[293115cdcc5d4626]::builder::Builder as rustc_codegen_ssa[4b4bd3c4a79f8ce6]::traits::builder::BuilderMethods>::va_arg
  17:     0x7ffae5583ff8 - <rustc_target[2fd88d7eff8074c7]::abi::TyAndLayout<rustc_middle[345e23a01d15c30c]::ty::Ty> as rustc_codegen_llvm[293115cdcc5d4626]::type_of::LayoutLlvmExt>::pointee_info_at
  18:     0x7ffae3db2851 - <rustc_codegen_llvm[293115cdcc5d4626]::llvm_::OperandBundleDef as core[f4e460384c48c425]::ops::drop::Drop>::drop
  19:     0x7ffae3de88cb - <rustc_codegen_llvm[293115cdcc5d4626]::context::CodegenCx as rustc_codegen_ssa[4b4bd3c4a79f8ce6]::traits::type_::LayoutTypeMethods>::fn_decl_backend_type
  20:     0x7ffae3d8efad - <rustc_codegen_llvm[293115cdcc5d4626]::llvm_::ffi::Metadata as core[f4e460384c48c425]::cmp::PartialEq>::eq
  21:     0x7ffae2e976e0 - rustc_interface[e31b1d572a2c621e]::passes::analysis
  22:     0x7ffae2eb3eb9 - <rustc_codegen_llvm[293115cdcc5d4626]::base::ValueIter as core[f4e460384c48c425]::iter::traits::iterator::Iterator>::next
  23:     0x7ffae2ead307 - <rustc_codegen_llvm[293115cdcc5d4626]::LlvmCodegenBackend as rustc_codegen_ssa[4b4bd3c4a79f8ce6]::traits::backend::CodegenBackend>::codegen_crate
  24:     0x7ffae2e751c0 - rustc_interface[e31b1d572a2c621e]::proc_macro_decls::provide
  25:     0x7ffae2e84c1b - <rustc_interface[e31b1d572a2c621e]::passes::LintStoreExpandImpl as rustc_expand[7e539c7dccfd7e8f]::base::LintStoreExpand>::pre_expansion_lint
  26:     0x7ffae2e6e649 - <rustc_interface[e31b1d572a2c621e]::queries::Queries>::ongoing_codegen
  27:     0x7ffae2e2bdbc - <unknown>
  28:     0x7ffae2e23110 - <unknown>
  29:     0x7ffae2e2cdf0 - <unknown>
  30:     0x7ffae2e58cb9 - rustc_driver[a0a607043376aa59]::args::arg_expand_all
  31:     0x7ffae2e483bd - <unknown>
  32:     0x7ffaea08ebdc - std::sys::windows::thread::Thread::new::hdf946fbfa5577747
  33:     0x7ffb46107034 - BaseThreadInitThunk
  34:     0x7ffb479826a1 - RtlUserThreadStart

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.64.0 (a55dd71d5 2022-09-19) running on x86_64-pc-windows-msvc

query stack during panic:
end of query stack
error: aborting due to previous error; 1 warning emitted

@blaine-dodson
Copy link
Author

Also on nightly.

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (a24a020e6 2022-10-18)
binary: rustc
commit-hash: a24a020e6d926dffe6b472fc647978f92269504e
commit-date: 2022-10-18
host: x86_64-pc-windows-msvc
release: 1.66.0-nightly
LLVM version: 15.0.2

Error

PS C:\Users\adodson\dev\test-bug> rustc .\src\main.rs
warning: field `execute` is never read
  --> .\src\main.rs:10:5
   |
9  | struct Instruction {
   |        ----------- field in this struct
10 |     execute: fn(),
   |     ^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_hir_analysis\src\check\expr.rs:352:39

error: internal compiler error: `InferCtxt` incorrectly tainted by errors
  |
  = note: delayed at compiler\rustc_infer\src\infer\mod.rs:1256:27

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_hir_analysis\src\check\coercion.rs:1469:42

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_infer\src\infer\sub.rs:123:31

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_hir_analysis\src\check\fallback.rs:109:58

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/a24a020e6d926dffe6b472fc647978f92269504e\compiler\rustc_middle\src\ty\relate.rs:419:59

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_mir_build\src\build\mod.rs:621:18

error: internal compiler error: PromoteTemps: MIR had errors
  --> .\src\main.rs:13:1
   |
13 | fn main() {
   | ^^^^^^^^^
   |
   = note: delayed at compiler\rustc_const_eval\src\transform\promote_consts.rs:53:22

error: internal compiler error: broken MIR in DefId(0:6 ~ main[2af6]::main) ("return type"): bad type [type error]
  --> .\src\main.rs:13:1
   |
13 | fn main() {
   | ^^^^^^^^^
   |
   = note: delayed at compiler\rustc_borrowck\src\type_check\mod.rs:520:13

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_borrowck\src\type_check\mod.rs:797:20

error: internal compiler error: broken MIR in DefId(0:6 ~ main[2af6]::main) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: .\src\main.rs:13:1: 13:10 (#0), scope: scope[0] } }): bad type [type error]
  --> .\src\main.rs:13:1
   |
13 | fn main() {
   | ^^^^^^^^^
   |
   = note: delayed at compiler\rustc_borrowck\src\type_check\mod.rs:520:13

error: internal compiler error: PromoteTemps: MIR had errors
  --> .\src\main.rs:15:16
   |
15 |         INST ( || {}; )
   |                ^^
   |
   = note: delayed at compiler\rustc_const_eval\src\transform\promote_consts.rs:53:22

error: internal compiler error: broken MIR in DefId(0:7 ~ main[2af6]::main::{closure#0}) ("return type"): bad type [type error]
  --> .\src\main.rs:15:16
   |
15 |         INST ( || {}; )
   |                ^^
   |
   = note: delayed at compiler\rustc_borrowck\src\type_check\mod.rs:520:13

error: internal compiler error: broken MIR in DefId(0:7 ~ main[2af6]::main::{closure#0}) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: .\src\main.rs:15:16: 15:18 (#0), scope: scope[0] } }): bad type [type error]
  --> .\src\main.rs:15:16
   |
15 |         INST ( || {}; )
   |                ^^
   |
   = note: delayed at compiler\rustc_borrowck\src\type_check\mod.rs:520:13

thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1550:13
stack backtrace:
   0:     0x7ffb00b397f2 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h53c4ea2e5298ee7b
   1:     0x7ffb00b750fb - core::fmt::write::h4929c0534d871047
   2:     0x7ffb00b2be1a - <std::io::IoSlice as core::fmt::Debug>::fmt::hea1586eafdc30c79
   3:     0x7ffb00b3953b - std::sys::common::alloc::realloc_fallback::h441a327114321be3
   4:     0x7ffb00b3ce99 - std::panicking::default_hook::h66f001930739e8fd
   5:     0x7ffb00b3cb1a - std::panicking::default_hook::h66f001930739e8fd
   6:     0x7ffae580086b - rustc_driver[1077fc6396368dcf]::describe_lints
   7:     0x7ffb00b3d7f0 - std::panicking::rust_panic_with_hook::h059540785d16ed47
   8:     0x7ffae7bac033 - <rustc_hir[c703180ab4123f64]::target::Target as rustc_errors[77b34b757f114d60]::diagnostic::IntoDiagnosticArg>::into_diagnostic_arg
   9:     0x7ffae7baa819 - <rustc_hir[c703180ab4123f64]::target::Target as rustc_errors[77b34b757f114d60]::diagnostic::IntoDiagnosticArg>::into_diagnostic_arg
  10:     0x7ffae7b9bec9 - <rustc_errors[77b34b757f114d60]::emitter::DisplaySuggestion as core[a02b6f37981f1b5f]::fmt::Debug>::fmt
  11:     0x7ffae7b93b69 - <getopts[69c649ba10df24e4]::Fail as core[a02b6f37981f1b5f]::fmt::Debug>::fmt
  12:     0x7ffae3ef68e3 - <rustc_errors[77b34b757f114d60]::HandlerInner>::emit_diagnostic
  13:     0x7ffae3ef582d - <rustc_errors[77b34b757f114d60]::Handler>::flush_delayed
  14:     0x7ffae30753d0 - <rustc_interface[69d3caabc375c611]::passes::LintStoreExpandImpl as rustc_expand[c0c33283810bd582]::base::LintStoreExpand>::pre_expansion_lint
  15:     0x7ffae305a47c - <rustc_interface[69d3caabc375c611]::queries::Queries>::ongoing_codegen
  16:     0x7ffae30135d9 - <unknown>
  17:     0x7ffae304788a - <rustc_middle[49f1884e63a0b2fb]::ty::SymbolName as core[a02b6f37981f1b5f]::fmt::Display>::fmt
  18:     0x7ffae3015412 - <unknown>
  19:     0x7ffae30471b7 - rustc_driver[1077fc6396368dcf]::args::arg_expand_all
  20:     0x7ffae3038899 - <unknown>
  21:     0x7ffae3030900 - <unknown>
  22:     0x7ffb00b4e53c - std::sys::windows::thread::Thread::new::h5087fa34a1aa6292
  23:     0x7ffb46107034 - BaseThreadInitThunk
  24:     0x7ffb479826a1 - RtlUserThreadStart

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.66.0-nightly (a24a020e6 2022-10-18) running on x86_64-pc-windows-msvc

query stack during panic:
end of query stack
error: aborting due to 15 previous errors; 1 warning emitted

@compiler-errors
Copy link
Member

This regressed way back in #88546. Its approach is a bit flawed, because it assumes that within parentheses it's never valid to have a closure followed by a semicolon. Let me see if there's a way around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants