Skip to content

Code attempting to use thread_local! with generics crash the compiler #98244

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
ditsing opened this issue Jun 19, 2022 · 1 comment
Closed

Code attempting to use thread_local! with generics crash the compiler #98244

ditsing opened this issue Jun 19, 2022 · 1 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.

Comments

@ditsing
Copy link

ditsing commented Jun 19, 2022

Code

#[derive(Default)]
struct S<Command> {
    a: Command,
}

impl<Command: Default> S<Command> {
    thread_local! {static AA: S<Command> = S::default() }
}

Code can be found in this repo.
I know this is not supported. (BTW when will thread_local with generic be supported?)

Meta

rustc --version --verbose:

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: aarch64-apple-darwin
release: 1.60.0
LLVM version: 14.0.0

Error output

thread 'rustc' panicked at 'no label after fn', compiler/rustc_span/src/source_map.rs:958:18
Backtrace

   Compiling thread_local_generic v0.1.0 (/Users/ditsing/Code/thread_local_generic)
thread 'rustc' panicked at 'no label after fn', compiler/rustc_span/src/source_map.rs:958:18
stack backtrace:
   0:        0x102a13118 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h10cf06316d33e2a9
   1:        0x102a5f808 - core::fmt::write::h1faf18c959c3a8df
   2:        0x102a05104 - std::io::Write::write_fmt::h86ab231360bc97d2
   3:        0x102a16e44 - std::panicking::default_hook::{{closure}}::h36e628ffaf3cd44f
   4:        0x102a16abc - std::panicking::default_hook::h3ee1564a7544e58f
   5:        0x109dec5c4 - rustc_driver[3e35567b0507961a]::DEFAULT_HOOK::{closure#0}::{closure#0}
   6:        0x102a17634 - std::panicking::rust_panic_with_hook::h191339fbd2fe2360
   7:        0x102a17388 - std::panicking::begin_panic_handler::{{closure}}::h91c230befd9929e3
   8:        0x102a13600 - std::sys_common::backtrace::__rust_end_short_backtrace::haaaeebb1d37476b3
   9:        0x102a170c4 - _rust_begin_unwind
  10:        0x102a8d7fc - core::panicking::panic_fmt::h4fe1013b011ef602
  11:        0x102a5c7d0 - core::panicking::panic_display::hd69c75a6c3ca2e2b
  12:        0x102a5c794 - core::panicking::panic_str::hbea2142fbbd15028
  13:        0x102a8d6e0 - core::option::expect_failed::h9dfbbdbcf303c11c
  14:        0x10db8004c - <rustc_span[dd8cd730fd24a84e]::source_map::SourceMap>::generate_fn_name_span
  15:        0x10c4a28c4 - <rustc_resolve[597e1ecda5b6785]::Resolver>::into_struct_error
  16:        0x10c4a040c - <rustc_resolve[597e1ecda5b6785]::Resolver>::report_error
  17:        0x10c4be3ec - <rustc_resolve[597e1ecda5b6785]::Resolver>::resolve_ident_in_lexical_scope
  18:        0x10c4c075c - <rustc_resolve[597e1ecda5b6785]::Resolver>::resolve_path_with_ribs::{closure#1}
  19:        0x10c4bef34 - <rustc_resolve[597e1ecda5b6785]::Resolver>::resolve_path_with_ribs
  20:        0x10c4ec254 - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>::resolve_qpath_anywhere
  21:        0x10c4eaa98 - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>::smart_resolve_path_fragment
  22:        0x10c4ea930 - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>::smart_resolve_path
  23:        0x10c4de56c - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor as rustc_ast[363baa93d4e8d256]::visit::Visitor>::visit_ty
  24:        0x10c4e06b8 - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor as rustc_ast[363baa93d4e8d256]::visit::Visitor>::visit_generic_arg
  25:        0x10c4385cc - rustc_ast[363baa93d4e8d256]::visit::walk_ty::<rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>
  26:        0x10c4de670 - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor as rustc_ast[363baa93d4e8d256]::visit::Visitor>::visit_ty
  27:        0x10c4df084 - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor as rustc_ast[363baa93d4e8d256]::visit::Visitor>::visit_fn
  28:        0x10c434b7c - rustc_ast[363baa93d4e8d256]::visit::walk_item::<rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>
  29:        0x10c4e258c - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>::resolve_item
  30:        0x10c442424 - rustc_ast[363baa93d4e8d256]::visit::walk_stmt::<rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>
  31:        0x10c4ddf3c - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor as rustc_ast[363baa93d4e8d256]::visit::Visitor>::visit_block
  32:        0x10c4e7c54 - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>::with_optional_trait_ref::<(), <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>::resolve_implementation::{closure#0}::{closure#0}::{closure#0}>
  33:        0x10c4e34ec - <rustc_resolve[597e1ecda5b6785]::late::LateResolutionVisitor>::resolve_item
  34:        0x10c4adddc - <rustc_resolve[597e1ecda5b6785]::Resolver>::late_resolve_crate
  35:        0x10c453940 - <rustc_session[d383daeae0c11292]::session::Session>::time::<(), <rustc_resolve[597e1ecda5b6785]::Resolver>::resolve_crate::{closure#0}>
  36:        0x109ecdf84 - rustc_interface[2280aded15839b11]::passes::configure_and_expand
  37:        0x109eb6684 - <rustc_interface[2280aded15839b11]::queries::Queries>::expansion
  38:        0x109d932dc - rustc_interface[2280aded15839b11]::interface::create_compiler_and_run::<core[e180da0f2c78f25f]::result::Result<(), rustc_errors[677d6d214e1093d1]::ErrorReported>, rustc_driver[3e35567b0507961a]::run_compiler::{closure#1}>
  39:        0x109d7acb0 - std[8541ff70ccfedbb0]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2280aded15839b11]::util::run_in_thread_pool_with_globals<rustc_interface[2280aded15839b11]::interface::run_compiler<core[e180da0f2c78f25f]::result::Result<(), rustc_errors[677d6d214e1093d1]::ErrorReported>, rustc_driver[3e35567b0507961a]::run_compiler::{closure#1}>::{closure#0}, core[e180da0f2c78f25f]::result::Result<(), rustc_errors[677d6d214e1093d1]::ErrorReported>>::{closure#0}, core[e180da0f2c78f25f]::result::Result<(), rustc_errors[677d6d214e1093d1]::ErrorReported>>
  40:        0x109df4648 - <<std[8541ff70ccfedbb0]::thread::Builder>::spawn_unchecked_<rustc_interface[2280aded15839b11]::util::run_in_thread_pool_with_globals<rustc_interface[2280aded15839b11]::interface::run_compiler<core[e180da0f2c78f25f]::result::Result<(), rustc_errors[677d6d214e1093d1]::ErrorReported>, rustc_driver[3e35567b0507961a]::run_compiler::{closure#1}>::{closure#0}, core[e180da0f2c78f25f]::result::Result<(), rustc_errors[677d6d214e1093d1]::ErrorReported>>::{closure#0}, core[e180da0f2c78f25f]::result::Result<(), rustc_errors[677d6d214e1093d1]::ErrorReported>>::{closure#1} as core[e180da0f2c78f25f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:        0x102a22b70 - std::sys::unix::thread::Thread::new::thread_start::h8ccdabc567c5eee0
  42:        0x1a577c26c - __pthread_deallocate

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.60.0 (7737e0b5c 2022-04-04) running on aarch64-apple-darwin

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

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

query stack during panic:
end of query stack
error: could not compile `thread_local_generic`

@ditsing ditsing 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 Jun 19, 2022
@ditsing
Copy link
Author

ditsing commented Jun 19, 2022

Oops this is the same as #97946.

@ditsing ditsing closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2022
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

No branches or pull requests

1 participant