Skip to content

rustc panic when using multiple #[default] tags #118119

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
TheEppicJR opened this issue Nov 21, 2023 · 0 comments · Fixed by #118131
Closed

rustc panic when using multiple #[default] tags #118119

TheEppicJR opened this issue Nov 21, 2023 · 0 comments · Fixed by #118131
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

@TheEppicJR
Copy link

Code

I was trying to verify the assumption about the #[default] tag in this comment, I ran cargo test with my changes to the macro and it worked successfully, then I added another #[default] tag (line 205 in tests/sample.rs) and ran cargo test again and rustc panicked. This is the exactly what was ran when the panic occurred.

Meta

rustc --version --verbose:

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: aarch64-apple-darwin
release: 1.72.0
LLVM version: 16.0.5

Error output

thread 'rustc' panicked at 'assertion failed: !parts.is_empty()', /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/compiler/rustc_errors/src/diagnostic.rs:622:9
stack backtrace:
   0:        0x100cfe3c0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h523fafbfdb8f0857
   1:        0x100d52450 - core::fmt::write::hf94a55b5a3abd106
   2:        0x100cf3d38 - std::io::Write::write_fmt::hc7c6bf1da111b052
   3:        0x100cfe218 - std::sys_common::backtrace::print::h68ede8fb1e716cba
   4:        0x100d00d94 - std::panicking::default_hook::{{closure}}::hba2205c2705c60bb
   5:        0x100d00b24 - std::panicking::default_hook::h9d927e01472bad1a
   6:        0x109245034 - rustc_driver_impl[e09643758e6f6376]::install_ice_hook::{closure#0}
   7:        0x100d01514 - std::panicking::rust_panic_with_hook::h8654c51ef9980a29
   8:        0x100d012ac - std::panicking::begin_panic_handler::{{closure}}::hd188a636b3b90298
   9:        0x100cfe7a0 - std::sys_common::backtrace::__rust_end_short_backtrace::hc331d455ac21f427
  10:        0x100d01054 - _rust_begin_unwind
  11:        0x100d7d444 - core::panicking::panic_fmt::h4f2054f72ff905b1
  12:        0x100d7d4b4 - core::panicking::panic::h4d2ee9cac0d6e9c1
  13:        0x10bd8a610 - <rustc_errors[ab8c5e7fbe90f582]::diagnostic::Diagnostic>::multipart_suggestion_with_style::<rustc_error_messages[e77c466ec3cc6779]::SubdiagnosticMessage>
  14:        0x10be10838 - <rustc_builtin_macros[56a8028b834a18f7]::errors::MultipleDefaults as rustc_errors[ab8c5e7fbe90f582]::diagnostic_builder::IntoDiagnostic>::into_diagnostic
  15:        0x10bda384c - <rustc_session[81931be3b0b4dc13]::parse::ParseSess>::emit_err::<rustc_builtin_macros[56a8028b834a18f7]::errors::MultipleDefaults>
  16:        0x10bdff49c - rustc_builtin_macros[56a8028b834a18f7]::deriving::default::expand_deriving_default::{closure#0}
  17:        0x10be22e90 - <rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::MethodDef>::expand_static_enum_method_body
  18:        0x10bd831b8 - <core[f9d6478373b114c5]::iter::adapters::map::Map<core[f9d6478373b114c5]::slice::iter::Iter<rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::MethodDef>, <rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::TraitDef>::expand_enum_def::{closure#1}> as core[f9d6478373b114c5]::iter::traits::iterator::Iterator>::fold::<(), core[f9d6478373b114c5]::iter::traits::iterator::Iterator::for_each::call<rustc_ast[b522d8ec668849e9]::ptr::P<rustc_ast[b522d8ec668849e9]::ast::Item<rustc_ast[b522d8ec668849e9]::ast::AssocItemKind>>, <alloc[bcdadf72caaa217a]::vec::Vec<rustc_ast[b522d8ec668849e9]::ptr::P<rustc_ast[b522d8ec668849e9]::ast::Item<rustc_ast[b522d8ec668849e9]::ast::AssocItemKind>>>>::extend_trusted<core[f9d6478373b114c5]::iter::adapters::map::Map<core[f9d6478373b114c5]::slice::iter::Iter<rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::MethodDef>, <rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::TraitDef>::expand_enum_def::{closure#1}>>::{closure#0}>::{closure#0}>
  19:        0x10bd677d8 - <alloc[bcdadf72caaa217a]::vec::Vec<rustc_ast[b522d8ec668849e9]::ptr::P<rustc_ast[b522d8ec668849e9]::ast::Item<rustc_ast[b522d8ec668849e9]::ast::AssocItemKind>>> as alloc[bcdadf72caaa217a]::vec::spec_from_iter::SpecFromIter<rustc_ast[b522d8ec668849e9]::ptr::P<rustc_ast[b522d8ec668849e9]::ast::Item<rustc_ast[b522d8ec668849e9]::ast::AssocItemKind>>, core[f9d6478373b114c5]::iter::adapters::map::Map<core[f9d6478373b114c5]::slice::iter::Iter<rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::MethodDef>, <rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::TraitDef>::expand_enum_def::{closure#1}>>>::from_iter
  20:        0x10be1c5cc - <rustc_builtin_macros[56a8028b834a18f7]::deriving::generic::TraitDef>::expand_ext
  21:        0x10bdfe800 - rustc_builtin_macros[56a8028b834a18f7]::deriving::default::expand_deriving_default
  22:        0x10bdb1734 - <rustc_builtin_macros[56a8028b834a18f7]::deriving::BuiltinDerive as rustc_expand[8ba1771b01b55d53]::base::MultiItemModifier>::expand
  23:        0x10c9fe288 - <rustc_expand[8ba1771b01b55d53]::expand::MacroExpander>::fully_expand_fragment
  24:        0x10c9fcc9c - <rustc_expand[8ba1771b01b55d53]::expand::MacroExpander>::expand_crate
  25:        0x1093598e0 - <rustc_session[81931be3b0b4dc13]::session::Session>::time::<rustc_ast[b522d8ec668849e9]::ast::Crate, rustc_interface[a43b58d3432b23e3]::passes::configure_and_expand::{closure#1}>
  26:        0x1093cc724 - rustc_interface[a43b58d3432b23e3]::passes::resolver_for_lowering
  27:        0x10c3dfddc - rustc_query_impl[bcaa985f447c9306]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bcaa985f447c9306]::query_impl::resolver_for_lowering::dynamic_query::{closure#2}::{closure#0}, rustc_middle[bded664fc7f58a73]::query::erase::Erased<[u8; 8usize]>>
  28:        0x10c534cac - <rustc_query_impl[bcaa985f447c9306]::query_impl::resolver_for_lowering::dynamic_query::{closure#2} as core[f9d6478373b114c5]::ops::function::FnOnce<(rustc_middle[bded664fc7f58a73]::ty::context::TyCtxt, ())>>::call_once
  29:        0x10c35b7c4 - rustc_query_system[b4230c255e5b9403]::query::plumbing::try_execute_query::<rustc_query_impl[bcaa985f447c9306]::DynamicConfig<rustc_query_system[b4230c255e5b9403]::query::caches::SingleCache<rustc_middle[bded664fc7f58a73]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[bcaa985f447c9306]::plumbing::QueryCtxt, true>
  30:        0x10c4c4160 - rustc_query_impl[bcaa985f447c9306]::query_impl::resolver_for_lowering::get_query_incr::__rust_end_short_backtrace
  31:        0x109278aa8 - <rustc_middle[bded664fc7f58a73]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[e09643758e6f6376]::run_compiler::{closure#1}::{closure#2}::{closure#2}, &rustc_data_structures[4c9820f8e66966d8]::steal::Steal<(rustc_middle[bded664fc7f58a73]::ty::ResolverAstLowering, alloc[bcdadf72caaa217a]::rc::Rc<rustc_ast[b522d8ec668849e9]::ast::Crate>)>>
  32:        0x109249fd0 - <rustc_interface[a43b58d3432b23e3]::interface::Compiler>::enter::<rustc_driver_impl[e09643758e6f6376]::run_compiler::{closure#1}::{closure#2}, core[f9d6478373b114c5]::result::Result<core[f9d6478373b114c5]::option::Option<rustc_interface[a43b58d3432b23e3]::queries::Linker>, rustc_span[ba98f16c60603a35]::ErrorGuaranteed>>
  33:        0x109277a58 - rustc_span[ba98f16c60603a35]::set_source_map::<core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>, rustc_interface[a43b58d3432b23e3]::interface::run_compiler<core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>, rustc_driver_impl[e09643758e6f6376]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  34:        0x10928a310 - std[5f883c90b3b6ecb9]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a43b58d3432b23e3]::util::run_in_thread_pool_with_globals<rustc_interface[a43b58d3432b23e3]::interface::run_compiler<core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>, rustc_driver_impl[e09643758e6f6376]::run_compiler::{closure#1}>::{closure#0}, core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>>
  35:        0x10928af08 - <<std[5f883c90b3b6ecb9]::thread::Builder>::spawn_unchecked_<rustc_interface[a43b58d3432b23e3]::util::run_in_thread_pool_with_globals<rustc_interface[a43b58d3432b23e3]::interface::run_compiler<core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>, rustc_driver_impl[e09643758e6f6376]::run_compiler::{closure#1}>::{closure#0}, core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f9d6478373b114c5]::result::Result<(), rustc_span[ba98f16c60603a35]::ErrorGuaranteed>>::{closure#1} as core[f9d6478373b114c5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:        0x100d09d58 - std::sys::unix::thread::Thread::new::thread_start::h143a83d9ede86d5c
  37:        0x1a05d906c - __pthread_deallocate

error: 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.72.0 (5680fa18f 2023-08-23) running on aarch64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

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

query stack during panic:
#0 [resolver_for_lowering] getting the resolver for lowering
end of query stack
error: could not compile `primitive_enum` (test "sample")
Backtrace

<backtrace>

@TheEppicJR TheEppicJR 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 Nov 21, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 21, 2023
@clubby789 clubby789 removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 21, 2023
@bors bors closed this as completed in 82538b7 Nov 23, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 23, 2023
Rollup merge of rust-lang#118131 - lukas-code:multi-default, r=wesleywiser

improve tool-only help for multiple `#[default]` variants

When defining an enum with multiple `#[default]` variants, we emit a tool-only suggestion for every `#[default]`ed variant to remove all other `#[default]`s. This PR improves the suggestion to correctly handle the cases where one variant has multiple `#[default]`s and where different `#[default]`s have the same span due to macro expansions.

fixes rust-lang#118119
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.

3 participants