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 if enum has unsized attribute. #36801

Closed
ghost opened this issue Sep 28, 2016 · 1 comment
Closed

Rustc panics if enum has unsized attribute. #36801

ghost opened this issue Sep 28, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 28, 2016

Consider this code:

#![allow(dead_code)]

fn main() {
    println!("Hello world");
}

struct StructTest {
    x: EnumTest,
}

enum EnumTest {
    A([usize]),
}

impl StructTest {
    fn test(&mut self) {
    }
}

What I get:

rustc 1.11.0 (9b21dcd 2016-08-15)
error: internal compiler error: ../src/librustc_trans/type_of.rs:178: Unexpected tail in unsized_info_ty: EnumTest for ty=StructTest
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: run with RUST_BACKTRACE=1 for a backtrace
thread 'rustc' panicked at 'Box', ../src/librustc_errors/lib.rs:619
stack backtrace:
1: 0x7fa0c066fe2f - std::sys::backtrace::tracing::imp::write::h46e546df6e4e4fe6
2: 0x7fa0c067e13b - std::panicking::default_hook::$u7b$$u7b$closure$u7d$$u7d$::h077deeda8b799591
3: 0x7fa0c067dcd8 - std::panicking::default_hook::heb8b6fd640571a4f
4: 0x7fa0c0643ade - std::panicking::rust_panic_with_hook::hd7b83626099d3416
5: 0x7fa0b91f4187 - std::panicking::begin_panic::h3e029d5f110b4661
6: 0x7fa0b91f3ad1 - rustc_errors::Handler::bug::he60f76b829c68950
7: 0x7fa0bcc0ceb4 - rustc::session::opt_span_bug_fmt::
$u7b$$u7b$closure$u7d$$u7d$::h11fa08f71c1e9d84
8: 0x7fa0bcc0ccbd - rustc::session::opt_span_bug_fmt::hdc2517bf24a762d0
9: 0x7fa0bcc27886 - rustc::session::bug_fmt::h4bff3cf11871f37a
10: 0x7fa0bf68c3e3 - rustc_trans::type_of::unsized_info_ty::h367c20592955858c
11: 0x7fa0bf5403d2 - rustc_trans::type_of::in_memory_type_of::h063fab02861e60cf
12: 0x7fa0bf53413a - rustc_trans::abi::FnType::unadjusted::$u7b$$u7b$closure$u7d$$u7d$::hc2595e37370d1c41
13: 0x7fa0bf531702 - rustc_trans::abi::FnType::unadjusted::hbb725f7f80132831
14: 0x7fa0bf53fe42 - rustc_trans::type_of::in_memory_type_of::h063fab02861e60cf
15: 0x7fa0bf5a6e6a - rustc_trans::callee::get_fn::h95e52f4d5bcb804b
16: 0x7fa0bf54a5e0 - rustc_trans::callee::Callee::def::h91a0eebd5a5325c7
17: 0x7fa0bf575b9c - rustc_trans::base::trans_item::hcfc6f2f68b9918b0
18: 0x7fa0bf58d893 - <rustc_trans..base..TransItemsWithinModVisitor<'a, 'tcx> as rustc..hir..intravisit..Visitor<'v>>::visit_item::hfffd713d2b3de363
19: 0x7fa0bf57e337 - rustc_trans::base::trans_crate::h75826f6271b49faf
20: 0x7fa0c0bc407f - rustc_driver::driver::phase_4_translate_to_llvm::hbc7e9672529bb439
21: 0x7fa0c0bc106c - rustc_driver::driver::compile_input::
$u7b$$u7b$closure$u7d$$u7d$::h7168080c5b7e33b9
22: 0x7fa0c0bbd77d - rustc_driver::driver::phase_3_run_analysis_passes::
$u7b$$u7b$closure$u7d$$u7d$::hded790081e457a76
23: 0x7fa0c0bb6f49 - rustc::ty::context::TyCtxt::create_and_enter::h7622c0f52ea2e7fe
24: 0x7fa0c0b7480f - rustc_driver::driver::compile_input::hdfe4405d66704c31
25: 0x7fa0c0b60f44 - rustc_driver::run_compiler::h581448fb74257353
26: 0x7fa0c0b5e04e - std::panicking::try::call::hf081e8ea5e252d1a
27: 0x7fa0c068c63b - __rust_try
28: 0x7fa0c068c5de - __rust_maybe_catch_panic
29: 0x7fa0c0b5eb34 - _<F as alloc..boxed..FnBox>::call_box::h2d5dcb354b3ff8db
30: 0x7fa0c067c264 - std::sys::thread::Thread::new::thread_start::hf2eed4b6f7149599
31: 0x7fa0b88e16f9 - start_thread
32: 0x7fa0c02beb5c - clone
33: 0x0 -

I expected the compiler to tell me, that
enum EnumTest { A([usize]), }

is not possible, as the size of A is not known at compile-time. Instead it panics. Test it https://play.rust-lang.org/?gist=2f36e717877a374b267eb072a0279614&version=stable&backtrace=1 in the Playground.

@apasel422
Copy link
Contributor

Duplicate of #16812.

bors added a commit that referenced this issue Oct 25, 2016
Disallow Unsized Enums

Fixes #16812.

This PR is a potential fix for #16812, an issue which is reported [again](#36801) and [again](#36975), with over a dozen duplicates by now.

This PR is mainly meant to promoted discussion about the issue and the correct way to fix it.

This is a [breaking-change] since the error is now reported during wfchecking, so that even the definition of a (potentially) unsized enum will cause an error (whereas it would previously cause an ICE at trans time if the enum was used in an unsized manner).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant