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

ICE returning arrays with length specified by an associated constant #28267

Closed
dcrewi opened this issue Sep 6, 2015 · 9 comments
Closed

ICE returning arrays with length specified by an associated constant #28267

dcrewi opened this issue Sep 6, 2015 · 9 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@dcrewi
Copy link
Contributor

dcrewi commented Sep 6, 2015

code

#![feature(associated_consts)]

trait Trait {
    const SIZE: usize;
}

pub fn cause_compiler_to_panic<T: Trait>() -> [u8; T::SIZE] {
    unimplemented!()
}

compiler output

$ RUST_BACKTRACE=1 rustc --crate-type rlib compiler_panic.rs
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/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'no path elem for NodeTyParam(TyParam { ident: T#0, id: 12, bounds: [TraitTyParamBound(PolyTraitRef { bound_lifetimes: [], trait_ref: TraitRef { path: path(Trait), ref_id: 13 }, span: compiler_panic.rs:15:35: 15:40 }, None)], default: None, span: compiler_panic.rs:15:32: 15:33 })', src/librustc/front/map/mod.rs:488

stack backtrace:
   1:     0x7f49381bbc99 - sys::backtrace::tracing::imp::write::hbc14f1d64893fa38REs
   2:     0x7f49381c2946 - panicking::on_panic::h2f9a11502875a3547ox
   3:     0x7f493818641e - rt::unwind::begin_unwind_inner::h9f15d88ec266cbe3DRw
   4:     0x7f4938187167 - rt::unwind::begin_unwind_fmt::h7bb2b8a52c6074abJQw
   5:     0x7f49360c9214 - front::map::Map<'ast>::get_path_elem::h810c6a17cb85afb1jeb
   6:     0x7f493637aee7 - front::map::Map<'ast>::with_path_next::h6183113809238491628
   7:     0x7f49362268f9 - middle::ty::ctxt<'tcx>::item_path_str::h29769059e7d6586b5Vb
   8:     0x7f49362256bb - middle::def_id::DefId.fmt..Debug::fmt::h6e39007ab82770f3Oap
   9:     0x7f4938232e65 - fmt::write::ha67db0db2f6a096ce8Q
  10:     0x7f493820f7a0 - fmt::builders::DebugTuple<'a, 'b>::field::h2ce8d9f33236cafaDwQ
  11:     0x7f49361b5115 - middle::def::Def...std..fmt..Debug::fmt::h938391f0b3e7112dsJn
  12:     0x7f4938232e65 - fmt::write::ha67db0db2f6a096ce8Q
  13:     0x7f493820f274 - fmt::builders::DebugStruct<'a, 'b>::field::haef609d3419cdbd2JrQ
  14:     0x7f49362265b1 - fmt::_&'a T.Debug::fmt::h17657018559682767623
  15:     0x7f4938232e65 - fmt::write::ha67db0db2f6a096ce8Q
  16:     0x7f49381870ea - rt::unwind::begin_unwind_fmt::h7bb2b8a52c6074abJQw
  17:     0x7f49361c70c5 - middle::const_eval::eval_const_expr_partial::hbec1acc1da716a81GTk
  18:     0x7f493754f37c - astconv::ast_ty_to_ty::h7a1c0c0cca136ce6Cjx
  19:     0x7f493759718d - astconv::convert_ty_with_lifetime_elision::h62c494c14aa9de2fthw
  20:     0x7f493759fc8e - astconv::ty_of_method_or_bare_fn::hcabe6144b8119a6eHBx
  21:     0x7f49375c1a60 - collect::type_scheme_of_item::he0f646ae1f45c0d9X9z
  22:     0x7f49375b9e29 - collect::convert_typed_item::hed81c40d50d02aa4HeA
  23:     0x7f49375a55ce - collect::convert_item::h415e2accc707fad518y
  24:     0x7f49375a2577 - collect::collect_item_types::h2934ed33155c9781xky
  25:     0x7f49375edc2b - check_crate::hfe64eeb39daabb000BE
  26:     0x7f49386f027d - driver::phase_3_run_analysis_passes::closure.21698
  27:     0x7f49386d28a3 - middle::ty::ctxt<'tcx>::create_and_enter::h17134548426382567756
  28:     0x7f49386cdd7e - driver::phase_3_run_analysis_passes::h13764670269333747744
  29:     0x7f49386ad6fd - driver::compile_input::h3c82c6370b45f42aYba
  30:     0x7f49388154fb - run_compiler::h551ac01c07dc0a95eqc
  31:     0x7f4938812e17 - boxed::F.FnBox<A>::call_box::h12386432182602546056
  32:     0x7f4938812884 - rt::unwind::try::try_fn::h15469726732675206848
  33:     0x7f49381c24e8 - __rust_try
  34:     0x7f49381ae5e2 - rt::unwind::try::inner_try::h58375fb23cadeb38wNw
  35:     0x7f4938812a18 - boxed::F.FnBox<A>::call_box::h11817215854212583186
  36:     0x7f49381c1933 - sys::thread::Thread::new::thread_start::h255e2285f2cbfbcekXv
  37:     0x7f49324c86a9 - start_thread
  38:     0x7f4937e40eec - clone
  39:                0x0 - <unknown>

verbose compiler info

$ rustc --version --verbose
rustc 1.4.0-dev (205c356ac 2015-09-05)
binary: rustc
commit-hash: 205c356ace559f511d5b7e51fd6b8c46bb4cc1ea
commit-date: 2015-09-05
host: x86_64-unknown-linux-gnu
release: 1.4.0-dev

other thoughts

I would have expected the accepted way to write the array size would be <T as Trait>::SIZE, but that fails to compile with this error message:

compiler_panic.rs:7:52: 7:70 error: array length constant evaluation error: non-constant path in constant expr [E0250]
compiler_panic.rs:7 pub fn cause_compiler_to_panic<T: Trait>() -> [u8; <T as Trait>::SIZE] {
                                                                       ^~~~~~~~~~~~~~~~~~
compiler_panic.rs:7:52: 7:70 help: run `rustc --explain E0250` to see a detailed explanation
error: aborting due to previous error
@alexispurslane
Copy link
Contributor

That's strange. And the file that it talks about, src/librustc/front/map/mod.rs doesn't even exist.

@alexispurslane
Copy link
Contributor

Although I can understand the second error (non-constant path in constant expr).

@jdm
Copy link
Contributor

jdm commented Sep 6, 2015

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 6, 2015
@Thiez
Copy link
Contributor

Thiez commented Sep 6, 2015

It's not just with ::SIZE, using pub fn cause_compiler_to_panic<T: Trait>() -> [u8; T::FOO] { ICE's just as hard, and I never even defined FOO.

@arielb1
Copy link
Contributor

arielb1 commented Sep 6, 2015

I think we have to fix <DefId as Debug> globally to stop crashing like that.

@arielb1
Copy link
Contributor

arielb1 commented Sep 6, 2015

Anyway, paths with type parameters (e.g. T::SIZE, <T as Trait>::SIZE) are not supported in array lengths.

@arielb1
Copy link
Contributor

arielb1 commented Sep 6, 2015

rustc encountered an ICE while trying to display an ICE

the inner ICE is:

thread 'rustc' panicked at 'path not fully resolved: PathResolution { base_def: DefTyParam(FnSpace, 0, DefId { krate: 0, node: 12 => cause_compiler_to_panic::T }, T(66)), last_private: LastMod(AllPublic), depth: 1 }', ../src/librustc/middle/def.rs:81

This looks like a dupe of something.

@nagisa
Copy link
Member

nagisa commented Sep 6, 2015

Dupe, dupe, dupe, semi-dupe, semi-dupe.

@alexcrichton
Copy link
Member

Closing as a dupe of #25145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

7 participants