Skip to content

internal compiler error: encountered errors lowering pattern: #43105

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

Closed
madmalik opened this issue Jul 7, 2017 · 3 comments
Closed

internal compiler error: encountered errors lowering pattern: #43105

madmalik opened this issue Jul 7, 2017 · 3 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@madmalik
Copy link
Contributor

madmalik commented Jul 7, 2017

I encountered an internal compiler error (on stable, beta and nightly) in my code and i could reduce it to this: playground link.

const NUM: u8 = std::mem::size_of::<u8>() as u8;

fn main() {
    match 1 {
        NUM => unimplemented!(),
        _ => unimplemented!(),
    }
}

I would expect that this program won't compile because of the non-const fn in a const declaration.

Nightly rightly gives an error message to that effect and panics, stable just panics.

Stacktrace:

rustc 1.20.0-nightly (3610a70ce 2017-07-05)
error[E0015]: calls in constants are limited to constant functions, struct and enum constructors
 --> <anon>:2:17
  |
2 | const NUM: u8 = std::mem::size_of::<u8>() as u8;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: /checkout/src/librustc_const_eval/pattern.rs:282: encountered errors lowering pattern: [ConstEval(ConstEvalErr { span: <anon>:2:17: 2:42, kind: TypeckError })]
 --> <anon>:6:9
  |
6 |         NUM => unimplemented!(),
  |         ^^^

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.20.0-nightly (3610a70ce 2017-07-05) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:426:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:380
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:390
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic_new
   6: rustc::session::opt_span_bug_fmt::{{closure}}
   7: rustc::session::span_bug_fmt
   8: rustc_const_eval::pattern::Pattern::from_hir
   9: rustc_mir::hair::cx::expr::make_mirror_unadjusted
  10: rustc_mir::hair::cx::expr::<impl rustc_mir::hair::Mirror<'tcx> for &'tcx rustc::hir::Expr>::make_mirror
  11: <rustc_mir::hair::ExprRef<'tcx> as rustc_mir::build::into::EvalInto<'tcx>>::eval_into
  12: rustc_mir::build::block::<impl rustc_mir::build::Builder<'a, 'gcx, 'tcx>>::ast_block_stmts
  13: rustc_mir::build::scope::<impl rustc_mir::build::Builder<'a, 'gcx, 'tcx>>::in_scope
  14: rustc_mir::build::scope::<impl rustc_mir::build::Builder<'a, 'gcx, 'tcx>>::in_opt_scope
  15: rustc_mir::build::expr::into::<impl rustc_mir::build::Builder<'a, 'gcx, 'tcx>>::into_expr
  16: <rustc_mir::hair::ExprRef<'tcx> as rustc_mir::build::into::EvalInto<'tcx>>::eval_into
  17: rustc_mir::build::expr::into::<impl rustc_mir::build::Builder<'a, 'gcx, 'tcx>>::into_expr
  18: <rustc_mir::hair::ExprRef<'tcx> as rustc_mir::build::into::EvalInto<'tcx>>::eval_into
  19: rustc_mir::build::expr::into::<impl rustc_mir::build::Builder<'a, 'gcx, 'tcx>>::into_expr
  20: rustc_mir::transform::mir_const
  21: rustc::ty::maps::<impl rustc::ty::maps::queries::mir_const<'tcx>>::try_get
  22: rustc::ty::maps::TyCtxtAt::mir_const
  23: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_const
  24: rustc_mir::transform::mir_validated
  25: rustc::ty::maps::<impl rustc::ty::maps::queries::mir_validated<'tcx>>::try_get
  26: rustc::ty::maps::TyCtxtAt::mir_validated
  27: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_validated
  28: rustc_borrowck::borrowck::borrowck
  29: rustc::ty::maps::<impl rustc::ty::maps::queries::borrowck<'tcx>>::try_get
  30: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::borrowck
  31: rustc_borrowck::borrowck::check_crate
  32: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  33: rustc_driver::driver::phase_3_run_analysis_passes
  34: rustc_driver::driver::compile_input
  35: rustc_driver::run_compiler

@sanxiyn sanxiyn added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 7, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@arielb1 arielb1 added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 26, 2017
@arielb1
Copy link
Contributor

arielb1 commented Nov 26, 2017

No ICE in current stable

@arielb1 arielb1 removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 26, 2017
@arielb1
Copy link
Contributor

arielb1 commented Nov 26, 2017

But using a random non-const-fn ICEs:

fn xyz() -> u8 { 42 }

const NUM: u8 = xyz();

fn main() {
    match 1 {
        NUM => unimplemented!(),
        _ => unimplemented!(),
    }
}

cc @eddyb

@eddyb
Copy link
Member

eddyb commented Nov 27, 2017

Ah, TypeckError CTFE errors are supposed to be silently ignored.

topecongiro added a commit to topecongiro/rust that referenced this issue Jan 12, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jan 12, 2018
Ignore CTFE errors while lowering patterns

Closes rust-lang#43105.

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

No branches or pull requests

5 participants