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 on nightly when calling method on an enum #39544

Closed
drbawb opened this issue Feb 4, 2017 · 5 comments
Closed

ICE on nightly when calling method on an enum #39544

drbawb opened this issue Feb 4, 2017 · 5 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@drbawb
Copy link

drbawb commented Feb 4, 2017

I'm trying to use the multipart crate (v0.9) which has an enum and an impl:

pub enum SaveDir {
    Temp(TempDir),
    Perm(PathBuf),
}

impl SaveDir {
 pub fn keep(&mut self) {
        use self::SaveDir::*;
        *self = match mem::replace(self, Perm(PathBuf::new())) {
            Temp(tempdir) => Perm(tempdir.into_path()),
            old_self => old_self,
        };
    }
}

Calling the #keep() method in my own code results in an ICE:

$ rustc -V
rustc 1.16.0-nightly (24055d0f2 2017-01-31)

$ cargo build

   Compiling aqua-web v0.1.0 (file:///C:/Users/drbawb/dev/rust/aqua/aqua-web)
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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'assertion failed: !self.is_enum()', C:\bot\slave\nightly-dist-rustc-win-msvc-64\build\src\librustc\ty/mod.rs:1473
stack backtrace:
   0:     0x7ffaccff0a18 - std::panicking::Location::line::ha91c35bc276d0b51
   1:     0x7ffaccfefea2 - std::panicking::Location::line::ha91c35bc276d0b51
   2:     0x7ffaccff38dd - std::panicking::rust_panic_with_hook::h9cf2c5a21e80091a
   3:     0x7ffab9072793 - <unknown>
   4:     0x7ffab920706a - rustc::middle::mem_categorization::cmt_::get_field::h9f2d931f17fc448b
   5:     0x7ffae0b074c5 - rustc_borrowck::borrowck::BorrowckCtxt::bckerr_to_diag::h2d7af69a90ae95ba
   6:     0x7ffae0b03326 - rustc_borrowck::borrowck::BorrowckCtxt::report::hbef36ce271ed8d47
   7:     0x7ffae0acefd0 - <rustc_borrowck::borrowck::gather_loans::GatherLoanCtxt<'a, 'tcx> as rustc::middle::expr_use_visitor::Delegate<'tcx>>::decl_without_init::h7e93ca90da0aab5f
   8:     0x7ffae0acdb62 - <rustc_borrowck::borrowck::gather_loans::GatherLoanCtxt<'a, 'tcx> as rustc::middle::expr_use_visitor::Delegate<'tcx>>::borrow::h3a777fcf8d947b45
   9:     0x7ffab91e968f - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  10:     0x7ffab91e9ace - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  11:     0x7ffab91e9891 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  12:     0x7ffab91e9f74 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  13:     0x7ffab91eb540 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  14:     0x7ffab91e98b3 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  15:     0x7ffab91eb540 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  16:     0x7ffab91e98b3 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  17:     0x7ffab91e9f74 - rustc::middle::expr_use_visitor::ExprUseVisitor::walk_expr::h40c0cf34345c8812
  18:     0x7ffab91e8e7b - rustc::middle::expr_use_visitor::ExprUseVisitor::consume_body::hcdc8c8f5b35232c5
  19:     0x7ffae0aca119 - <rustc::mir::Operand<'tcx> as rustc_borrowck::borrowck::mir::abs_domain::Lift>::lift::h707cd2026e8d8954
  20:     0x7ffae0b000d1 - rustc_borrowck::borrowck::check_crate::h8fccd59355eb5e14
  21:     0x7ffae0afdb3b - rustc_borrowck::borrowck::check_crate::h8fccd59355eb5e14
  22:     0x7ffae0afb38b - <rustc_borrowck::borrowck::BorrowckCtxt<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn::h7b19d6cf263b349a
  23:     0x7ffae0afb93b - <rustc_borrowck::borrowck::BorrowckCtxt<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_impl_item::h934600d3986e7c8d
  24:     0x7ffae0afc511 - rustc_borrowck::borrowck::check_crate::h8fccd59355eb5e14
  25:     0x7ffae268836c - rustc_driver::driver::count_nodes::h80b2ce48c34d37f0
  26:     0x7ffae25d621f - <unknown>
  27:     0x7ffae2661308 - rustc_driver::driver::compile_input::h332507cf263d70da
  28:     0x7ffae26b2cab - rustc_driver::run_compiler::hcb93be779576dd68
  29:     0x7ffae258f0be - <unknown>
  30:     0x7ffaccff6981 - _rust_maybe_catch_panic
  31:     0x7ffae25bc7b6 - <unknown>
  32:     0x7ffaccfedeee - std::sys::imp::thread::Thread::new::h3473f0391636b6af
  33:     0x7ffb029c8101 - BaseThreadInitThunk

error: Could not compile `aqua-web`.

To learn more, run the command again with --verbose.
@arielb1
Copy link
Contributor

arielb1 commented Feb 4, 2017

Could you provide some code that reproduces the ICE?

@drbawb
Copy link
Author

drbawb commented Feb 4, 2017

I pushed a branch of my project demonstrating the issue on github: drbawb/aqua@8e28dc4
(You only need to build the aqua-web crate to get the ICE, which has much fewer dependencies than the main crate.)

I'll try to work on a more minimal repro than that, but hopefully it's a start.

@drbawb
Copy link
Author

drbawb commented Feb 5, 2017

Here is a gist to a self-contained test case:
https://gist.github.com/anonymous/17b5375c5584e8c7ea7e476d012a750a

Here is a playground link:
https://is.gd/E9LEfQ

This seems to be related to calling a mutable method on the enum through an immutable binding. Interestingly on the playground it only causes the ICE on nightly, it seems to compile fine on Stable. (Well it doesn't ICE, it does return an error about the mutable binding.)

@codyps
Copy link
Contributor

codyps commented Feb 5, 2017

minimized https://is.gd/GaakiA:

enum X {
    Y
}

struct Z {
    x: X
}

fn main() {
    let z = Z { x: X::Y };
    let _ = &mut z.x;
}

Probably introduced by #39139

@arielb1 arielb1 added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 6, 2017
@estebank
Copy link
Contributor

estebank commented Feb 6, 2017

@arielb1 @jmesmon I'll take a look at it later today. The fix should be small enough.

This line should have a check for is_enum. That'll fix the compiler error. In order to provide the same diagnostic messages for enums, get_field will have to be changed to identify the variant being passed.

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 7, 2017
Fix ICE when accessing mutably an immutable enum

Fix rust-lang#39544.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 7, 2017
Fix ICE when accessing mutably an immutable enum

Fix rust-lang#39544.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 8, 2017
Fix ICE when accessing mutably an immutable enum

Fix rust-lang#39544.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 9, 2017
Fix ICE when accessing mutably an immutable enum

Fix rust-lang#39544.
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) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants