Skip to content

Compiler panic on fairly simple match expression #51415

Closed

Description

@mulkieran

Here's the stack trace

> make build
PKG_CONFIG_ALLOW_CROSS=1 \
RUSTFLAGS='-D warnings' \
RUST_BACKTRACE=1 \
cargo build --target "x86_64-unknown-linux-gnu"
   Compiling libstratis v0.5.3 (file:///home/mulhern/my-contributions/stratisd)
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: (MoveData { move_paths: [MovePath { place: _0 }, MovePath { place: _1 }, MovePath { place: _2 }, MovePath { place: _3 }, MovePath { place: _4 }], moves: [mp4@bb0[4], mp4@bb2[0], mp3@bb2[1], mp3@bb3[0], mp3@bb4[0], mp0@bb4[1]], loc_map: LocationMap { map: [[[], [], [], [], [mo0]], [[]], [[mo1], [mo2]], [[mo3]], [[mo4], [mo5]]] }, path_map: [[mo5], [], [], [mo2, mo3, mo4], [mo0, mo1]], rev_lookup: MovePathLookup { locals: [mp0, mp1, mp2, mp3, mp4], projections: {} }, inits: [mp1@src/engine/strat_engine/cmd.rs:54:32: 54:59 (Deep), mp2@src/engine/strat_engine/cmd.rs:54:33: 54:43 (Deep), mp3@src/engine/strat_engine/cmd.rs:54:38: 54:42 (Deep), mp4@src/engine/strat_engine/cmd.rs:54:45: 54:49 (Deep), mp0@src/engine/strat_engine/cmd.rs:54:45: 54:59 (NonPanicPathOnly)], init_loc_map: LocationMap { map: [[[], [in2], [], [in3], [in4]], [[]], [[], []], [[]], [[], []]] }, init_path_map: [[in4], [in0], [in1], [in2], [in3]] }, [IllegalMove { cannot_move_out_of: IllegalMoveOrigin { span: src/engine/strat_engine/cmd.rs:54:38: 54:42, kind: BorrowedContent } }])', libcore/result.rs:945:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: core::ops::function::Fn::call
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::result::unwrap_failed
  10: <rustc_mir::transform::elaborate_drops::ElaborateDrops as rustc_mir::transform::MirPass>::run_pass
  11: rustc_mir::transform::optimized_mir::{{closure}}
  12: rustc_mir::transform::optimized_mir
  13: rustc::dep_graph::graph::DepGraph::with_task_impl
  14: rustc_errors::Handler::track_diagnostics
  15: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  16: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::force
  17: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::try_get
  18: rustc::ty::maps::TyCtxtAt::optimized_mir
  19: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::optimized_mir
  20: rustc_metadata::encoder::<impl rustc_metadata::isolated_encoder::IsolatedEncoder<'a, 'b, 'tcx>>::encode_optimized_mir
  21: rustc_metadata::encoder::<impl rustc_metadata::isolated_encoder::IsolatedEncoder<'a, 'b, 'tcx>>::encode_info_for_closure
  22: rustc::dep_graph::graph::DepGraph::with_ignore
  23: rustc_metadata::encoder::<impl rustc_metadata::index_builder::IndexBuilder<'a, 'b, 'tcx>>::encode_info_for_expr
  24: rustc::hir::intravisit::walk_expr
  25: rustc::hir::intravisit::walk_expr
  26: rustc::hir::intravisit::walk_expr
  27: rustc::hir::intravisit::Visitor::visit_nested_body
  28: <rustc_metadata::encoder::EncodeVisitor<'a, 'b, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  29: rustc::hir::Crate::visit_all_item_likes
  30: rustc_metadata::encoder::encode_metadata
  31: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
  32: rustc::ty::context::TyCtxt::encode_metadata
  33: rustc_trans::base::write_metadata
  34: rustc::util::common::time
  35: rustc_trans::base::trans_crate
  36: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  37: rustc::util::common::time
  38: rustc_driver::driver::phase_4_translate_to_llvm
  39: rustc_driver::driver::compile_input::{{closure}}
  40: <std::thread::local::LocalKey<T>>::with
  41: <std::thread::local::LocalKey<T>>::with
  42: rustc::ty::context::TyCtxt::create_and_enter
  43: rustc_driver::driver::compile_input
  44: rustc_driver::run_compiler_impl
  45: syntax::with_globals

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

note: rustc 1.26.0 running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `libstratis`.

To learn more, run the command again with --verbose.
make: *** [Makefile:27: build] Error 101

Activity

  1. mulkieran commented on Jun 7, 2018

    @mulkieran
    ContributorAuthor

    Here's a PR with the code that caused the crash:

    stratis-storage/stratisd#983

  2. mulkieran commented on Jun 7, 2018

    @mulkieran
    ContributorAuthor

    I compile frequently, and had made only a few changes between this and the last time I had compiled. I think the crash has something to do with the implementation of verify_binaries because I had just been juggling with that. I expect it has something to do with the Some match arm.

  3. hellow554 commented on Jun 7, 2018

    @hellow554
    Contributor

    Can you provide a mcve?

  4. mulkieran commented on Jun 7, 2018

    @mulkieran
    ContributorAuthor

    What's an "mcve"?

  5. mulkieran commented on Jun 7, 2018

    @mulkieran
    ContributorAuthor

    Whoops, I thought that was an actual word, not an initialism. Giving it the 15 minute try...

  6. mulkieran commented on Jun 7, 2018

    @mulkieran
    ContributorAuthor

    Well, I make no assertions about minimality, but this code snippet does fail on the rust playground w/ all six possible configurations and it's pretty short.

    #[macro_use]
    extern crate lazy_static;
    
    use std::collections::HashMap;
    use std::path::PathBuf;
    
    lazy_static! {
        static ref BINARIES: HashMap<String, Option<PathBuf>> = [].iter().cloned().collect();
    }
    
    fn main() {
        let _ = match BINARIES.iter().find(|(_, &path)| path.is_none()) {
            None => Ok(()),
            Some((ref name, _)) => Err(name.to_string()),
        };
    }
    
  7. mulkieran commented on Jun 7, 2018

    @mulkieran
    ContributorAuthor

    Smaller:

    use std::collections::HashMap;
    use std::path::PathBuf;
    
    fn main() {
        let junk: HashMap<String, Option<PathBuf>> = HashMap::new();
        let _ = match junk.iter().find(|(_, &path)| path.is_none()) {
            None => Ok(()),
            Some((ref name, _)) => Err(name.to_string()),
        };
    }
    
  8. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Jun 7, 2018
  9. mulkieran commented on Jun 7, 2018

    @mulkieran
    ContributorAuthor

    Smidge smaller:

    use std::collections::HashMap;
    use std::path::PathBuf;
    
    fn main() {
        let junk: HashMap<String, Option<PathBuf>> = HashMap::new();
        let _ = match junk.iter().find(|(_, &path)| path.is_none()) {
            None => "none".to_string(),
            Some((ref name, _)) => name.to_string(),
        };
    }
    
  10. hellow554 commented on Jun 7, 2018

    @hellow554
    Contributor

    ICE does not happen with #![feature(nll)]

  11. hellow554 commented on Jun 7, 2018

    @hellow554
    Contributor

    You can make your example working by changing the &path to either path (match ergnomics) or ref path (explicit ref), but yes. You're right. It's an ICE, should not happen :)

  12. hellow554 commented on Jun 7, 2018

    @hellow554
    Contributor

    Worked on 1.25.0 with an explicit error message.

    error[E0658]: non-reference pattern used to match a reference (see issue #42640)
     --> src/main.rs:6:37
      |
    6 |     let _ = match junk.iter().find(|(_, path)| path.is_none()) {
      |                                     ^^^^^^^^^^^^^ help: consider using a reference: `&(_, path)`
    
  13. estebank commented on Jun 7, 2018

    @estebank
    Contributor

    I think might have been caused by the match ergonomics pr.

  14. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    C-bugCategory: This is a bug.
    on Jun 8, 2018
  15. alberdingk-thijm commented on Jun 21, 2018

    @alberdingk-thijm

    Had a similar compiler panic with this snippet of code:

    fn main() {
        let a = vec![String::from("a"), String::from("b"), String::from("c")];
        let opt = a.iter().enumerate().find(|(_, &s)| {
            *s == String::from("d")
        }).map(|(i, _)| i);
        println!("{:?}", opt);
    }
    

    Changing it to the snippet below fixes the problem, so I definitely think the match ergonomics is doing something.

    fn main() {
        let a = vec![String::from("a"), String::from("b"), String::from("c")];
        let opt = a.iter().enumerate().find(|&(_, s)| {
            *s == String::from("d")
        }).map(|(i, _)| i);
        println!("{:?}", opt);
    }
    

    See it in the playground here.

  16. nikomatsakis commented on Jun 21, 2018

    @nikomatsakis
    Contributor

    triage: P-high

    Hmm, this might be a problem with borrowck failing to catch a borrow (the NLL borrow checker seems to catch the error correctly).

  17. added
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    on Jun 21, 2018
  18. self-assigned this
    on Jun 21, 2018
  19. nikomatsakis commented on Jun 21, 2018

    @nikomatsakis
    Contributor

    The problem seems to be specific to argument patterns. This code fails to compile as expected:

    fn main() {
        let a = vec![String::from("a")];
        let opt = a.iter().enumerate().find(|param| {
            let (_, &s) = param; //~ ERROR
            *s == String::from("d")
        }).map(|(i, _)| i);
        println!("{:?}", opt);
    }
  20. added a commit that references this issue on Jun 22, 2018
    7dae5c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions