Skip to content
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

rustc panics with 'no label after fn' when attempting to create a thread local with a generic parameter #97946

Closed
menixator opened this issue Jun 10, 2022 · 7 comments
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. glacier ICE tracked in rust-lang/glacier. 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

@menixator
Copy link

menixator commented Jun 10, 2022

Code

Playgound Permalink

struct A<T> {
    inner: T

}

impl <T> A<T>  {
    thread_local! {
        static MY_STATIC: Option<T>  = None;
    }
}


fn main() {

}

Meta

rustc --version --verbose:

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0

I checked with the following rustc beta and nightly versions as well. The issue exists in both of them.
Beta:

rustc 1.62.0-beta.4 (8fd9e5fe1 2022-06-08)
binary: rustc
commit-hash: 8fd9e5fe1ed168622450f8e79864901e64fc7fc1
commit-date: 2022-06-08
host: x86_64-unknown-linux-gnu
release: 1.62.0-beta.4
LLVM version: 14.0.4

Nightly:

rustc 1.63.0-nightly (420c970cb 2022-06-09)
binary: rustc
commit-hash: 420c970cb1edccbf60ff2aeb51ca01e2300b09ef
commit-date: 2022-06-09
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

Error output

Output and backtraces are from the stable version.

Error Output

   Compiling bug_report v0.1.0 (/tmp/bug_report)
thread 'rustc' panicked at 'no label after fn', compiler/rustc_span/src/source_map.rs:958:18
stack backtrace:
   0:     0x7fc60de9e1cd - std::backtrace_rs::backtrace::libunwind::trace::h22893a5306c091b4
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fc60de9e1cd - std::backtrace_rs::backtrace::trace_unsynchronized::h29c3bc6f9e91819d
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fc60de9e1cd - std::sys_common::backtrace::_print_fmt::he497d8a0ec903793
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fc60de9e1cd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9c2a9d2774d81873
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fc60def801c - core::fmt::write::hba4337c43d992f49
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/fmt/mod.rs:1194:17
   5:     0x7fc60de8f7c1 - std::io::Write::write_fmt::heb73de6e02cfabed
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/io/mod.rs:1655:15
   6:     0x7fc60dea12b5 - std::sys_common::backtrace::_print::h63c8b24acdd8e8ce
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fc60dea12b5 - std::sys_common::backtrace::print::h426700d6240cdcc2
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fc60dea12b5 - std::panicking::default_hook::{{closure}}::hc9a76eed0b18f82b
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:295:22
   9:     0x7fc60dea0f69 - std::panicking::default_hook::h2e88d02087fae196
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:314:9
  10:     0x7fc60e6ad1d1 - rustc_driver[413d55b6344850e3]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fc60dea1a00 - std::panicking::rust_panic_with_hook::habfdcc2e90f9fd4c
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:702:17
  12:     0x7fc60dea1837 - std::panicking::begin_panic_handler::{{closure}}::he054b2a83a51d2cd
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:588:13
  13:     0x7fc60de9e684 - std::sys_common::backtrace::__rust_end_short_backtrace::ha48b94ab49b30915
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7fc60dea1569 - rust_begin_unwind
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
  15:     0x7fc60de656b3 - core::panicking::panic_fmt::h366d3a309ae17c94
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
  16:     0x7fc60def4e31 - core::panicking::panic_display::hd3e89d99fb893792
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:72:5
  17:     0x7fc60def4ddb - core::panicking::panic_str::h98ed104b0c03a108
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:56:5
  18:     0x7fc60de65526 - core::option::expect_failed::h58d487f78ae9d247
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/option.rs:1874:5
  19:     0x7fc60f87ae39 - <rustc_span[7238ca7210ca999e]::source_map::SourceMap>::generate_fn_name_span
  20:     0x7fc60eaeba2a - <rustc_resolve[7fbeee27fba9936d]::Resolver>::into_struct_error
  21:     0x7fc60eae8a5c - <rustc_resolve[7fbeee27fba9936d]::Resolver>::report_error
  22:     0x7fc60fc472f0 - <rustc_resolve[7fbeee27fba9936d]::Resolver>::resolve_path_with_ribs
  23:     0x7fc60fc554bd - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor>::smart_resolve_path_fragment
  24:     0x7fc60fc4b5b5 - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor as rustc_ast[f1ba8e19ab33c411]::visit::Visitor>::visit_ty
  25:     0x7fc60fc4cc9c - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor as rustc_ast[f1ba8e19ab33c411]::visit::Visitor>::visit_generic_arg
  26:     0x7fc60fc4b7a2 - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor as rustc_ast[f1ba8e19ab33c411]::visit::Visitor>::visit_ty
  27:     0x7fc60fc4bcc5 - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor as rustc_ast[f1ba8e19ab33c411]::visit::Visitor>::visit_fn
  28:     0x7fc60fc01bee - rustc_ast[f1ba8e19ab33c411]::visit::walk_item::<rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor>
  29:     0x7fc60fc4f492 - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor>::resolve_item
  30:     0x7fc60fc4ae25 - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor as rustc_ast[f1ba8e19ab33c411]::visit::Visitor>::visit_block
  31:     0x7fc60fc58192 - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor>::resolve_expr
  32:     0x7fc60fc4fef1 - <rustc_resolve[7fbeee27fba9936d]::late::LateResolutionVisitor>::resolve_item
  33:     0x7fc6108d4d2c - <rustc_resolve[7fbeee27fba9936d]::Resolver>::late_resolve_crate
  34:     0x7fc6108c7efb - <rustc_session[8df92abe178df33c]::session::Session>::time::<(), <rustc_resolve[7fbeee27fba9936d]::Resolver>::resolve_crate::{closure#0}>
  35:     0x7fc6105ab934 - rustc_interface[550884b2b179878f]::passes::configure_and_expand
  36:     0x7fc6105da091 - <rustc_interface[550884b2b179878f]::queries::Queries>::expansion
  37:     0x7fc61058f979 - <rustc_interface[550884b2b179878f]::interface::Compiler>::enter::<rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}::{closure#2}, core[a3420257622cd381]::result::Result<core[a3420257622cd381]::option::Option<rustc_interface[550884b2b179878f]::queries::Linker>, rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  38:     0x7fc61057503f - rustc_span[7238ca7210ca999e]::with_source_map::<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_interface[550884b2b179878f]::interface::create_compiler_and_run<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#1}>
  39:     0x7fc6105910a4 - rustc_interface[550884b2b179878f]::interface::create_compiler_and_run::<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>
  40:     0x7fc6105737c2 - <scoped_tls[7ed3ce20ede545d8]::ScopedKey<rustc_span[7238ca7210ca999e]::SessionGlobals>>::set::<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  41:     0x7fc61058938f - std[3b302b3c9093c22]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[550884b2b179878f]::util::run_in_thread_pool_with_globals<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  42:     0x7fc610574af9 - <<std[3b302b3c9093c22]::thread::Builder>::spawn_unchecked_<rustc_interface[550884b2b179878f]::util::run_in_thread_pool_with_globals<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#1} as core[a3420257622cd381]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7fc60deabbf3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha99802c2c52ada61
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
  44:     0x7fc60deabbf3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha39aea1c57e28a15
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
  45:     0x7fc60deabbf3 - std::sys::unix::thread::Thread::new::thread_start::h9f8e3d72b1f7662f
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys/unix/thread.rs:108:17
  46:     0x7fc60dc7f54d - <unknown>
  47:     0x7fc60dd04b14 - clone
  48:                0x0 - <unknown>

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.61.0 (fe5b13d68 2022-05-18) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -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 `bug_report`

Backtrace

   Compiling bug_report v0.1.0 (/tmp/bug_report)
thread 'rustc' panicked at 'no label after fn', compiler/rustc_span/src/source_map.rs:958:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::panicking::panic_display
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:72:5
   3: core::panicking::panic_str
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:56:5
   4: core::option::expect_failed
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/option.rs:1874:5
   5: <rustc_span::source_map::SourceMap>::generate_fn_name_span
   6: <rustc_resolve::Resolver>::into_struct_error
   7: <rustc_resolve::Resolver>::report_error
   8: <rustc_resolve::Resolver>::resolve_path_with_ribs
   9: <rustc_resolve::late::LateResolutionVisitor>::smart_resolve_path_fragment
  10: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_ty
  11: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_generic_arg
  12: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_ty
  13: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_fn
  14: rustc_ast::visit::walk_item::<rustc_resolve::late::LateResolutionVisitor>
  15: <rustc_resolve::late::LateResolutionVisitor>::resolve_item
  16: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_block
  17: <rustc_resolve::late::LateResolutionVisitor>::resolve_expr
  18: <rustc_resolve::late::LateResolutionVisitor>::resolve_item
  19: <rustc_resolve::Resolver>::late_resolve_crate
  20: <rustc_session::session::Session>::time::<(), <rustc_resolve::Resolver>::resolve_crate::{closure#0}>
  21: rustc_interface::passes::configure_and_expand
  22: <rustc_interface::queries::Queries>::expansion
  23: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  24: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  25: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  26: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.61.0 (fe5b13d68 2022-05-18) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -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 `bug_report`

@menixator menixator 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 10, 2022
@menixator menixator changed the title rustc panics when attempting to create a thread local with a generic parameter rustc panics with 'no label after fn' when attempting to create a thread local with a generic parameter Jun 10, 2022
@cjgillot
Copy link
Contributor

Minimal fix: replace the expect by a ? in rustc_span::source_map::generate_fn_name_span.

Better fix: remove rustc_span::source_map::generate_fn_name_span and generate_local_type_param_snippet.
We should avoid re-parsing code for diagnostics, the parser already gives us plenty of accurate spans to play with.

This function is used in 2 places: late resolution diagnostics and typechecking.
Steps:

  • in rustc_typeck::check::compare_method, replace the call to generate_fn_name_span by a call to tcx.def_ident_span(impl_def_id);
  • in rustc_resolve::late, give add a Span field to HasGenericParams::Yes, the same span as LifetimeRibKind::Generics should be used;
  • use this newly added span to suggest adding the generic parameter in rustc_resolve::late, I recommend reusing part of the code in rustc_resolve::late::diagnostics::emit_undeclared_lifetime_error (which does the same thing for lifetimes and supports for<> bounds too).

@cjgillot cjgillot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jun 10, 2022
@eggyal
Copy link
Contributor

eggyal commented Jun 10, 2022

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 11, 2022
matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 11, 2022
Alexendoo added a commit to rust-lang/glacier that referenced this issue Jun 11, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 11, 2022
@eggyal
Copy link
Contributor

eggyal commented Jun 16, 2022

Sorry, finding the "better fix" a bit more involved than originally anticipated and don't have enough time to delve into this right now. Unassigning in case someone else wants to pick it up, but also happy to return to it when I have more time.

@eggyal eggyal removed their assignment Jun 16, 2022
@RJudgeII
Copy link

@rustbot claim

@RJudgeII
Copy link

@rustbot release-assignment

@obeis
Copy link
Contributor

obeis commented Jun 18, 2022

@rustbot claim

@Alexendoo
Copy link
Member

Fixed by #98609

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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. glacier ICE tracked in rust-lang/glacier. 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

7 participants