Skip to content

match_default_bindings ICE #46197

Closed
Closed
@CAD97

Description

@CAD97

playground link

A bit of history on running into this and trying to make the small reproduction case (Reddit)

#![feature(match_default_bindings)]
#![crate_type="lib"]

enum StringFragment {
    #[allow(dead_code)]
    String(String),
}

pub struct StringFragments {
    fragments: Vec<StringFragment>,
}

impl StringFragments {
    pub fn ice(&mut self) {
        #[allow(unused_variables, unused_mut)]
        match self.fragments.last_mut() {
            Some(StringFragment::String(mut string)) => {}
            _ => {}
        }
    }
}

The above ICEs on a cargo build or cargo test, but not a cargo check. Changing fn ice to have a generic argument (such as fn ice<D: Default>) makes cargo check ICE as well.

This seems to have something to do with the ref/mut quality of the string binding in the match. Qualifying ref mut string or leaving off both qualifiers works fine (including when the branch has actual code using the &mut String and isn't just a stub).

Backtrace:

note: rustc 1.23.0-nightly (63739ab7b 2017-11-21) running on x86_64-pc-windows-msvc

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: (MoveData { move_paths: [MovePath { lvalue: _0 }, MovePath { lvalue: _1 }, MovePath { first_child: mp8, lvalue: _2 }, MovePath { lvalue: _3 }, MovePath { lvalue: _4 }, MovePath { lvalue: _5 }, MovePath { lvalue: _6 }, MovePath { lvalue: _7 }, MovePath { parent: mp2, first_child: mp9, lvalue: (_2 as Some) }, MovePath { parent: mp8, lvalue: ((_2 as Some).0: &'<empty> mut StringFragment) }], moves: [mp5@bb0[5], mp5@bb1[1], mp3@bb1[2], mp3@bb2[0], mp6@bb8[0], mp6@bb9[0], mp2@bb9[1], mp4@bb9[2]], loc_map: LocationMap { map: [[[], [], [], [], [], [mo0]], [[], [mo1], [mo2]], [[mo3], [], []], [[], []], [[]], [[]], [[]], [[], [], [], []], [[mo4]], [[mo5], [mo6], [mo7], []]] }, path_map: [[], [], [mo6], [mo2, mo3], [mo7], [mo0, mo1], [mo4, mo5], [], [], []], rev_lookup: MovePathLookup { locals: [mp0, mp1, mp2, mp3, mp4, mp5, mp6, mp7], projections: {(mp2, Downcast(std::option::Option, 1)): mp8, (mp8, Field(field[0], AbstractType)): mp9} } }, [IllegalMove { cannot_move_out_of: IllegalMoveOrigin { span: src\lib.rs:16:41: 16:51, kind: BorrowedContent } }])', src\libcore\result.rs:906:4
stack backtrace:
   0:     0x7ff96ba03bb3 - _rdl_shrink_in_place
   1:     0x7ff96ba15173 - std::panicking::Location::column::h71b638b1102d8ec2
   2:     0x7ff96ba14d6b - std::panicking::Location::column::h71b638b1102d8ec2
   3:     0x7ff96ba15745 - std::panicking::rust_panic_with_hook::h86332471201f0504
   4:     0x7ff96ba155d0 - std::panicking::begin_panic_fmt::hcfe94f6ff6902731
   5:     0x7ff96ba154b1 - std::panicking::begin_panic_fmt::hcfe94f6ff6902731
   6:     0x7ff96ba15429 - rust_begin_unwind
   7:     0x7ff96ba2534c - core::panicking::panic_fmt::h24a4546a238be7cd
   8:     0x7ff9663695ab - <&'tcx rustc::ty::TyS<'tcx> as rustc_mir::dataflow::move_paths::abs_domain::Lift>::lift::h26c24aab0cd7f71e
   9:     0x7ff966312974 - <rustc_mir::transform::elaborate_drops::ElaborateDrops as rustc_mir::transform::MirPass>::run_pass::h2bb8d8ca88d9e5d0
  10:     0x7ff9663a916e - <rustc_mir::transform::MirSource as core::fmt::Debug>::fmt::he26a1325d68947ee
  11:     0x7ff9663a357d - rustc_mir::transform::optimized_mir::h40cc8885a4442fd4
  12:     0x7ff94f908f2c - rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::ensure::h3173ff6543b9bdfd
  13:     0x7ff94fb0ab07 - rustc::dep_graph::graph::DepGraph::in_ignore::h8c023ef9813636cc
  14:     0x7ff94f7cf077 - rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::adjustment::Adjustment<'tcx>>::fmt::h67cf830736da1c27
  15:     0x7ff94fcc3747 - <rustc::ty::_match::Match<'a, 'gcx, 'tcx> as rustc::ty::relate::TypeRelation<'a, 'gcx, 'tcx>>::tys::he01b853877be8f34
  16:     0x7ff94f908fd6 - rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::ensure::h3173ff6543b9bdfd
  17:     0x7ff94f909785 - rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::try_get::h7c0aec52fecd18d5
  18:     0x7ff94fa84f1f - rustc::ty::maps::TyCtxtAt::optimized_mir::h8343d36f33df4668
  19:     0x7ff94fcdb3f4 - rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::instance_mir::h9790ccd9ba9c9c25
  20:     0x7ff98cdd02ae - rustc_trans_utils::collector::collect_crate_translation_items::ha0f6f364e0b9f2de
  21:     0x7ff98cdcf505 - rustc_trans_utils::collector::collect_crate_translation_items::ha0f6f364e0b9f2de
  22:     0x7ff95fff2a43 - <rustc_trans::time_graph::TimelineId as core::fmt::Debug>::fmt::h1b359c509c114fb7
  23:     0x7ff95ff2adad - rustc_trans::base::trans_crate::hc4cd45f03351b78f
  24:     0x7ff94fadf2ce - rustc::dep_graph::graph::DepGraph::in_ignore::h8c023ef9813636cc
  25:     0x7ff94f7fc5a8 - rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::adjustment::Adjustment<'tcx>>::fmt::h67cf830736da1c27
  26:     0x7ff94fc9cca7 - <rustc::ty::_match::Match<'a, 'gcx, 'tcx> as rustc::ty::relate::TypeRelation<'a, 'gcx, 'tcx>>::tys::he01b853877be8f34
  27:     0x7ff94f9a34f7 - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::ensure::hc5d2d7a98a7d9015
  28:     0x7ff94f9a3d56 - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get::h559d3f156ba76ac1
  29:     0x7ff94fa8c178 - rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items::h943415d2dcd98d7d
  30:     0x7ff94fcdedd2 - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items::h3a36d944c492e2a0
  31:     0x7ff95ff27e50 - rustc_trans::base::trans_crate::hc4cd45f03351b78f
  32:     0x7ff95ffb775a - <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate::h55c38da8b7c81be6
  33:     0x7ff97ecc78b8 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h8f7593c47a7a42c2
  34:     0x7ff97ec6594c - rustc_driver::driver::default_provide_extern::h369421b1cc050ae1
  35:     0x7ff97ecb60e3 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h8f7593c47a7a42c2
  36:     0x7ff97ecb2366 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h8f7593c47a7a42c2
  37:     0x7ff97ecb3e19 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h8f7593c47a7a42c2
  38:     0x7ff97ec1a4bc - <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt::hb25b55ed7fdedd90
  39:     0x7ff97ec5e789 - rustc_driver::driver::compile_input::h6611ae9238b378aa
  40:     0x7ff97eca2b46 - rustc_driver::run_compiler::hdefd8f8859fdcc80
  41:     0x7ff97ebfc07d - <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt::hb25b55ed7fdedd90
  42:     0x7ff96ba19171 - _rust_maybe_catch_panic
  43:     0x7ff97ec96331 - <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_impl_item::h96d7e57ed143e192
  44:     0x7ff96ba1320b - std::sys::imp::thread::Thread::new::h213e202edcaf2262
  45:     0x7ff9b89b1fe3 - BaseThreadInitThunk

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions