Skip to content

rustc panics unexpectedly when passing phantomdata to hierarchical trait arguments #39539

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
iankronquist opened this issue Feb 4, 2017 · 2 comments

Comments

@iankronquist
Copy link

iankronquist commented Feb 4, 2017

rustc panics unexpectedly when passing phantomdata to hierarchical trait arguments

I tried this code:

// wonderful tutorial: http://os.phil-opp.com/modifying-page-tables.html
// It's a really slick way to use Rust's type system to express the page
// tables.

use std::marker::PhantomData;
use std::boxed::Box;

pub trait PageTableLevel {}

trait HierarchicalLevel: PageTableLevel {
    type NextLevel: PageTableLevel;
}

pub struct PageTable<L: PageTableLevel> {
    level: PhantomData<L>,
}

impl<L: HierarchicalLevel> PageTable<L> {
    pub fn next_layer_create(&mut self, index: usize) -> Option<&mut PageTable<L::NextLevel>>
    {
        let address = allocate_page(L::NextLevel);
        None
    }
}

pub fn allocate_page(level: PageTableLevel) -> u64 {
    let page: &PageTable<PageTableLevel> = Box::new(Default::default);
    page as u64
}


I expected to see this happen: It shouldn't compile, and should give me lots of red errors and yellow warnings.

Instead, this happened: rustc panics.

Meta

rustc --version --verbose: rustc 1.16.0-nightly (1a2ed98 2017-01-13)
binary: rustc
commit-hash: 1a2ed98
commit-date: 2017-01-13
host: x86_64-unknown-linux-gnu
release: 1.16.0-nightly
LLVM version: 3.9

Backtrace:

error: main function not found

error: internal compiler error: /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:4376: unexpected definition: AssociatedTy(DefId { krate: CrateNum(0), node: DefIndex(7) => repro/4089d7c8b778d88cec885baf7b69e6df-exe::HierarchicalLevel[0]::NextLevel[0] })

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<Any>', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_errors/lib.rs:423
stack backtrace:
   1:     0x7f0dbe5680fc - std::sys::imp::backtrace::tracing::imp::write::h9c41d2f69e5caabf
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7f0dbe57657e - std::panicking::default_hook::{{closure}}::h1f61f3c769fffe7a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:351
   3:     0x7f0dbe576123 - std::panicking::default_hook::hd5bda4e453dfb4be
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:361
   4:     0x7f0dbe576a1b - std::panicking::rust_panic_with_hook::hffbc74969c7b5d87
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:555
   5:     0x7f0db6b81a57 - std::panicking::begin_panic::h74ad4f050841c998
   6:     0x7f0db6b971c9 - rustc_errors::Handler::bug::h7088c6afc4a008fb
   7:     0x7f0dbb8b87fa - rustc::session::opt_span_bug_fmt::{{closure}}::h8e30a0fda5e6d8ea
   8:     0x7f0dbb8b8605 - rustc::session::opt_span_bug_fmt::h4fd6d943719c63ae
   9:     0x7f0dbb8b8262 - rustc::session::bug_fmt::he01375c3004c5cfe
  10:     0x7f0dbca204e3 - rustc_typeck::check::FnCtxt::instantiate_value_path::hfcd1421ef04f3e81
  11:     0x7f0dbca0d858 - rustc_typeck::check::FnCtxt::check_expr_kind::h7172316f2afc3db4
  12:     0x7f0dbca0c05d - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h58cbaadb2bb31008
  13:     0x7f0dbca00af6 - rustc_typeck::check::FnCtxt::check_argument_types::h222b4f6520160c8e
  14:     0x7f0dbc9da3b1 - rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::confirm_builtin_call::h49b04582f1c761e4
  15:     0x7f0dbc9d9266 - rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_call::h388fc4549b25dc5a
  16:     0x7f0dbca0d244 - rustc_typeck::check::FnCtxt::check_expr_kind::h7172316f2afc3db4
  17:     0x7f0dbca0c05d - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h58cbaadb2bb31008
  18:     0x7f0dbca1e8fd - rustc_typeck::check::FnCtxt::check_decl_initializer::h406e808c34510780
  19:     0x7f0dbca1ea04 - rustc_typeck::check::FnCtxt::check_decl_local::ha21dda48446cfd7f
  20:     0x7f0dbca1ed36 - rustc_typeck::check::FnCtxt::check_stmt::h5f0c409d0347ada0
  21:     0x7f0dbca1f08e - rustc_typeck::check::FnCtxt::check_block_with_expected::h5fabdeff5662cd10
  22:     0x7f0dbca0c4c7 - rustc_typeck::check::FnCtxt::check_expr_kind::h7172316f2afc3db4
  23:     0x7f0dbca0c05d - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h58cbaadb2bb31008
  24:     0x7f0dbc9f1eb1 - rustc_typeck::check::check_fn::h7512874de533d1c6
  25:     0x7f0dbc9f0ec4 - rustc_typeck::check::check_bare_fn::hff8cbad9cd9ca12c
  26:     0x7f0dbc9f3920 - rustc_typeck::check::check_item_body::h2a877e8ee0d16484
  27:     0x7f0dbc9ee08a - rustc_typeck::check::check_item_bodies::hf9c5a615b1a27ce2
  28:     0x7f0dbca60217 - rustc_typeck::check_crate::h93455a3168487f9e
  29:     0x7f0dbe91fc87 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::haccf5097991f72ff
  30:     0x7f0dbe8812b9 - rustc::ty::context::TyCtxt::create_and_enter::hc186c58b8fad7ff4
  31:     0x7f0dbe8ffe20 - rustc_driver::driver::compile_input::h44853ffed84a12cb
  32:     0x7f0dbe9450a2 - rustc_driver::run_compiler::hdc4bb0fcf7d0917a
  33:     0x7f0dbe849b4b - std::panicking::try::do_call::ha583797d32a865bd
  34:     0x7f0dbe57f89a - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  35:     0x7f0dbe873852 - <F as alloc::boxed::FnBox<A>>::call_box::h6903719257a678be
  36:     0x7f0dbe5753d4 - std::sys::imp::thread::Thread::new::thread_start::h76badbf9b0ecaf58
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:615
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84
  37:     0x7f0db632c453 - start_thread
  38:     0x7f0dbe2397de - __GI___clone
  39:                0x0 - <unknown>
@iankronquist iankronquist changed the title rustc panics unexpectedly when phantomdata to hierarchical trait arguments rustc panics unexpectedly when passing phantomdata to hierarchical trait arguments Feb 4, 2017
@petrochenkov
Copy link
Contributor

This looks like a duplicate of #38919 and should be fixed in #39019.
Could you check the code on the latest nightly?

@iankronquist
Copy link
Author

Looks like it's been fixed.

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

2 participants