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

Panic in match against non-unit variant as if it were unit variant #58006

Closed
estk opened this issue Jan 30, 2019 · 2 comments
Closed

Panic in match against non-unit variant as if it were unit variant #58006

estk opened this issue Jan 30, 2019 · 2 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estk
Copy link
Contributor

estk commented Jan 30, 2019

First off, I would be interested in trying to fix this, seems simple enough. I figured I would start by filing a bug to document the issue and perhaps get some info on how best to fix this.

❯ rustc --version
rustc 1.33.0-nightly (4c2be9c97 2019-01-22)

The code:

pub enum SchemaBody {
    Group(Group),
    ...
}
impl CodeGenerator for SchemaBody {
    fn codegen(&self, ctx: &mut Context) -> TokenStream {
    match self {
        Self::Group => TokenStream::new(),
        ...
    }

The panic came from:

_ => bug!("unexpected pattern definition: {:?}", def)

The panic content:

warning: unused import: `std::str::FromStr`
 --> src/schema.rs:8:5
  |
8 | use std::str::FromStr;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

 INFO 2019-01-30T18:23:41Z: rustc::traits::fulfill: selecting trait `Binder(TraitPredicate(<proc_macro2::Ident as std::convert::AsRef<str>>))` at depth 0 yielded Err
error: internal compiler error: src/librustc_typeck/check/_match.rs:795: unexpected pattern definition: VariantCtor(DefId(0/1:1359 ~ xmlschemer[e672]::schema[0]::SchemaBody[0]::Group[0]), Fn)

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:589:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_pat_walk
  15: <core::iter::Map<I, F> as core::iter::iterator::Iterator>::fold
  16: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  17: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_match
  18: rustc_typeck::check::FnCtxt::check_expr_kind
  19: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
  20: rustc_typeck::check::FnCtxt::check_decl_initializer
  21: rustc_typeck::check::FnCtxt::check_decl_local
  22: rustc_typeck::check::FnCtxt::check_stmt
  23: rustc_typeck::check::FnCtxt::check_block_with_expected
  24: rustc_typeck::check::FnCtxt::check_expr_kind
  25: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
  26: rustc_typeck::check::FnCtxt::check_return_expr
  27: rustc_typeck::check::check_fn
  28: rustc::ty::context::GlobalCtxt::enter_local
  29: rustc_typeck::check::typeck_tables_of
  30: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  34: rustc::session::Session::track_errors
  35: rustc_typeck::check::typeck_item_bodies
  36: rustc::ty::query::__query_compute::typeck_item_bodies
  37: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_item_bodies<'tcx>>::compute
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  40: rustc::util::common::time
  41: rustc_typeck::check_crate
  42: <std::thread::local::LocalKey<T>>::with
  43: rustc::ty::context::TyCtxt::create_and_enter
  44: rustc_driver::driver::compile_input
  45: <scoped_tls::ScopedKey<T>>::set
  46: rustc_driver::run_compiler
  47: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
#0 [typeck_tables_of] processing `<schema::SchemaBody as schema::CodeGenerator>::codegen`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to previous error


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.33.0-nightly (4c2be9c97 2019-01-22) running on x86_64-apple-darwin

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

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

[2019-01-30T18:23:42Z INFO  cargo::core::compiler::job_queue] end: xmlschemer v0.1.0 (/Users/evan/rust/xmlschemer) => Target(lib)/Profile(dev) => Host
[2019-01-30T18:23:42Z DEBUG cargo] exit_with_error; err=CliError { error: Some(ProcessError { desc: "process didn\'t exit successfully: `rustc --edition=2018 --crate-name xmlschemer src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=9bdca844f3332aaa -C extra-filename=-9bdca844f3332aaa --out-dir /Users/evan/rust/xmlschemer/target/debug/deps -C incremental=/Users/evan/rust/xmlschemer/target/debug/incremental -L dependency=/Users/evan/rust/xmlschemer/target/debug/deps --extern clap=/Users/evan/rust/xmlschemer/target/debug/deps/libclap-a23f3ee74267101d.rlib --extern heck=/Users/evan/rust/xmlschemer/target/debug/deps/libheck-563b7994f02e64e3.rlib --extern if_chain=/Users/evan/rust/xmlschemer/target/debug/deps/libif_chain-6aadb789477ede7c.rlib --extern log=/Users/evan/rust/xmlschemer/target/debug/deps/liblog-45ef69e8215812e9.rlib --extern pretty_env_logger=/Users/evan/rust/xmlschemer/target/debug/deps/libpretty_env_logger-37685c937e93e60a.rlib --extern proc_macro2=/Users/evan/rust/xmlschemer/target/debug/deps/libproc_macro2-17e36e282c84be40.rlib --extern quote=/Users/evan/rust/xmlschemer/target/debug/deps/libquote-af4db6a3f849bcbe.rlib --extern rustfmt_nightly=/Users/evan/rust/xmlschemer/target/debug/deps/librustfmt_nightly-5cf5c0282729abd2.rlib --extern serde=/Users/evan/rust/xmlschemer/target/debug/deps/libserde-8e6194039e047282.rlib --extern serde_xml_rs=/Users/evan/rust/xmlschemer/target/debug/deps/libserde_xml_rs-f084d2902482aeaf.rlib --extern serde_derive=/Users/evan/rust/xmlschemer/target/debug/deps/libserde_derive-e37160e203f98c35.dylib --extern syn=/Users/evan/rust/xmlschemer/target/debug/deps/libsyn-2bf5c4461ccaa30c.rlib --extern xml=/Users/evan/rust/xmlschemer/target/debug/deps/libxml-b8b441b14c916eaf.rlib` (exit code: 101)", exit: Some(ExitStatus(ExitStatus(25856))), output: None }

stack backtrace:
   0: failure::backtrace::internal::InternalBacktrace::new::h474badb9ffce7bc7 (0x103b16f3b)
   1: <failure::backtrace::Backtrace as core::default::Default>::default::h45cb1f41e3daf8ec (0x103b17114)
   2: cargo::util::process_builder::ProcessBuilder::exec_with_streaming::h921b193535c0e9ef (0x1034fb6f5)
   3: <cargo::core::compiler::DefaultExecutor as cargo::core::compiler::Executor>::exec_and_capture_output::hf0dfafb1f405e584 (0x103732873)
   4: <F as cargo::core::compiler::job::FnBox<A, R>>::call_box::hd5b96495299b4cd2 (0x103730700)
   5: <F as cargo::core::compiler::job::FnBox<A, R>>::call_box::h05bcb4a6b3baee91 (0x103519d99)
   6: <F as cargo::core::compiler::job::FnBox<A, R>>::call_box::h05bcb4a6b3baee91 (0x103519d99)
   7: cargo::core::compiler::job::Job::run::h61355f8d9cb1d572 (0x103519e6e)
   8: crossbeam_utils::thread::ScopedThreadBuilder::spawn::{{closure}}::h8f338d85344a6ba7 (0x10374aed9)
   9: std::sys_common::backtrace::__rust_begin_short_backtrace::ha3ba31f6b7a9d297 (0x1034125fd)
  10: ___rust_maybe_catch_panic (0x103b3d7fe)
  11: <F as alloc::boxed::FnBox<A>>::call_box::hda9b9217608f805a (0x10341c889)
  12: std::sys::unix::thread::Thread::new::thread_start::h9fabc538beb0d7ac (0x103b3cdcb)
  13: __pthread_body (0x7fff78fc033c)
  14: __pthread_start (0x7fff78fc32a6)

stack backtrace:
   0: failure::backtrace::internal::InternalBacktrace::new::h474badb9ffce7bc7 (0x103b16f3b)
   1: <failure::backtrace::Backtrace as core::default::Default>::default::h45cb1f41e3daf8ec (0x103b17114)
   2: <F as cargo::core::compiler::job::FnBox<A, R>>::call_box::hd5b96495299b4cd2 (0x1037307a1)
   3: <F as cargo::core::compiler::job::FnBox<A, R>>::call_box::h05bcb4a6b3baee91 (0x103519d99)
   4: <F as cargo::core::compiler::job::FnBox<A, R>>::call_box::h05bcb4a6b3baee91 (0x103519d99)
   5: cargo::core::compiler::job::Job::run::h61355f8d9cb1d572 (0x103519e6e)
   6: crossbeam_utils::thread::ScopedThreadBuilder::spawn::{{closure}}::h8f338d85344a6ba7 (0x10374aed9)
   7: std::sys_common::backtrace::__rust_begin_short_backtrace::ha3ba31f6b7a9d297 (0x1034125fd)
   8: ___rust_maybe_catch_panic (0x103b3d7fe)
   9: <F as alloc::boxed::FnBox<A>>::call_box::hda9b9217608f805a (0x10341c889)
  10: std::sys::unix::thread::Thread::new::thread_start::h9fabc538beb0d7ac (0x103b3cdcb)
  11: __pthread_body (0x7fff78fc033c)
  12: __pthread_start (0x7fff78fc32a6)
@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 30, 2019
@jonas-schievink
Copy link
Contributor

Can you post the full code needed to reproduce this (or a minimal example)?

@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 30, 2019
@estebank estebank added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Jan 30, 2019
@estebank
Copy link
Contributor

estebank commented Jan 30, 2019

Repro:

#![feature(type_alias_enum_variants)]
pub enum Enum {
    A(usize),
}

impl Enum {
    fn foo(&self) -> () {
        match self {
            Self::A => (),
        }
    }
}

fn main() {}

Centril added a commit to Centril/rust that referenced this issue Jan 30, 2019
Don't panic when accessing enum variant ctor using `Self` in match

Fix rust-lang#58006.

r? @petrochenkov
Centril added a commit to Centril/rust that referenced this issue Jan 30, 2019
Don't panic when accessing enum variant ctor using `Self` in match

Fix rust-lang#58006.

r? @petrochenkov
Centril added a commit to Centril/rust that referenced this issue Jan 31, 2019
Don't panic when accessing enum variant ctor using `Self` in match

Fix rust-lang#58006.

r? @petrochenkov
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) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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

3 participants