Skip to content

print len of empty array crashes the compiler #16604

Closed
@asterite

Description

@asterite
fn main() {
  print!("{}", [].len());
}
$ rustc foo.rs 
foo.rs:2:16: 2:18 error: internal compiler error: borrow-vec associated with bad sty: &ty_err
foo.rs:2   print!("{}", [].len());
                        ^~
note: in expansion of format_args!
<std macros>:2:23: 2:75 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of print!
foo.rs:2:3: 2:26 note: expansion site
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'Box<Any>', ../rust/src/libsyntax/ast_util.rs:776

Here's the backtrace:

stack backtrace:
   1:        0x1054f4585 - rt::backtrace::imp::write::h0e26dd8a4a05f6efrGr
   2:        0x1054f7753 - failure::on_fail::h13923e91b81d426ekXr
   3:        0x1057c6dc5 - unwind::begin_unwind_inner::h0fb5ec3809e5b727ufe
   4:        0x10349f912 - unwind::begin_unwind::h10934101626562952781
   5:        0x10349f8a5 - diagnostic::SpanHandler::span_bug::hbc864a0f4923f842juF
   6:        0x102168765 - driver::session::Session::span_bug::h0de2235d8c3f77c3CnB
   7:        0x1024cf7f7 - middle::ty::adjust_ty::borrow_vec::h503dcb9362bdbf17orH
   8:        0x1021745f3 - middle::ty::adjust_ty::hab2c1e32ac4ff50bLkH
   9:        0x102529f77 - middle::typeck::check::regionck::constrain_regions_in_type_of_node::hd6c54389f6332b76XQP
  10:        0x102526114 - middle::typeck::check::regionck::visit_expr::h5784e905d81996ecA1O
  11:        0x10252be27 - visit::walk_expr::h5907329393784617312
  12:        0x1025277bf - middle::typeck::check::regionck::visit_expr::h5784e905d81996ecA1O
  13:        0x10252709b - middle::typeck::check::regionck::visit_expr::h5784e905d81996ecA1O
  14:        0x10252be9a - visit::walk_expr::h5907329393784617312
  15:        0x1025277bf - middle::typeck::check::regionck::visit_expr::h5784e905d81996ecA1O
  16:        0x10252bfb2 - visit::walk_expr::h5907329393784617312
  17:        0x1025277bf - middle::typeck::check::regionck::visit_expr::h5784e905d81996ecA1O
  18:        0x102528fd2 - visit::walk_block::h17786527119977375855
  19:        0x10256d871 - middle::typeck::check::check_bare_fn::h61f052d12e877ddfwBT
  20:        0x102566bcb - middle::typeck::check::check_item::h027777362fa48273EaU
  21:        0x10256d5bd - middle::typeck::check::check_item_types::h2dbd64dceacc2916NAT
  22:        0x101f95f06 - util::common::time::h7630563901268510443
  23:        0x10276aa0c - middle::typeck::check_crate::h39eae4247da0d253fel
  24:        0x102836cb0 - driver::driver::phase_3_run_analysis_passes::h751cf5e050036eb1mPz
  25:        0x102831ca3 - driver::driver::compile_input::hbc61bd8f0f430d03sBz
  26:        0x1028d99d2 - driver::run_compiler::h94bfc1a9a3bd1e6fm9C
  27:        0x1028d80b6 - driver::main_args::closure.137555
  28:        0x1028ea20b - task::TaskBuilder<S>::try_future::closure.138716
  29:        0x1028ea115 - task::TaskBuilder<S>::spawn_internal::closure.138693
  30:        0x1052d984c - task::spawn_opts::closure.8427
  31:        0x10582dd0c - rust_try_inner
  32:        0x10582dcf6 - rust_try
  33:        0x1057c419b - unwind::try::h984411f9abeb5f3dK3d
  34:        0x1057c3f3b - task::Task::run::h9b847fa38b6ea061Bad
  35:        0x1052d96aa - task::spawn_opts::closure.8372
  36:        0x1057c5d56 - thread::thread_start::h9cbcec5684f86e5dnzd
  37:     0x7fff84993899 - _pthread_body
  38:     0x7fff8499372a - _pthread_struct_init

Note that this also triggers the error:

fn main() {
  print!("{}", [1].len());
}

However, if I do this it works:

fn main() {
  print!("{}", [1i].len());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions