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

error: internal compiler error: src/librustc_const_eval/pattern.rs:283: encountered errors lowering pattern #42285

Closed
U007D opened this issue May 28, 2017 · 4 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@U007D
Copy link

U007D commented May 28, 2017

I was trying to do something admittedly a little weird. 1) match foo.into() { } where foo is Into<String>. 2) Declare a const empty string to avoid creating a local temporary to match against (defined in a different module): pub const EMPTY_STRING: String = String::new();.

The offending code:

pub struct HexByteString(String);

impl HexByteString {
    pub fn new<T: Into<String>>(init_value: T) -> Result<HexByteString> {
        match init_value.into() {
            consts::EMPTY_STRING => Err(Error::EmptyValue(msgs::ERR_EMPTY_VALUE.to_string())),
            s @ _ => Ok(HexByteString(s)),
        }
    }
}
@kennytm
Copy link
Member

kennytm commented May 28, 2017

Reduced:

const EMPTY_STRING: String = String::new();

fn main() {
    let init_value = "".to_owned();
    if let EMPTY_STRING = init_value {}
}

ICE happens since 1.18 (no ICE on 1.17, only compile-error).


Probably related to #38180, ICE on valid code:

#![feature(const_fn)]

#[derive(PartialEq, Eq)]
struct S;

const fn new() -> S { S }

const ES: S = new();

fn main() {
    match S {
        ES => {}
    }
}
Backtrace
rustc 1.19.0-nightly (28fd1e519 2017-05-27)
error: internal compiler error: /checkout/src/librustc_const_eval/_match.rs:246: bad constructor ConstantValue(Struct({})) for adt S

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 'Box<Any>', /checkout/src/librustc_errors/lib.rs:473
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:355
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:365
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:549
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::bug
   7: rustc::session::opt_span_bug_fmt::{{closure}}
   8: rustc::session::opt_span_bug_fmt
   9: rustc::session::bug_fmt
  10: rustc_const_eval::_match::Constructor::variant_index_for_adt
  11: rustc_const_eval::_match::constructor_sub_pattern_tys
  12: rustc_const_eval::_match::is_useful_specialized
  13: rustc_const_eval::_match::is_useful::{{closure}}
  14: <core::option::Option<T>>::map
  15: rustc_const_eval::_match::is_useful
  16: rustc_const_eval::check_match::MatchVisitor::check_match::{{closure}}
  17: <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  18: <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  19: <rustc_const_eval::check_match::OuterVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn
  20: rustc::hir::intravisit::walk_item
  21: rustc_const_eval::check_match::check_crate
  22: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  23: rustc_driver::driver::phase_3_run_analysis_passes
  24: rustc_driver::driver::compile_input
  25: rustc_driver::run_compiler

@Mark-Simulacrum
Copy link
Member

Bisected to 23de823 -- #41408, cc @eddyb

@eddyb
Copy link
Member

eddyb commented May 28, 2017

People keep using const fn and expecting it to work with patterns. The lack of an ICE before was purely an accident. I've tried to fix this but the only real solution in sight is actually miri.
I hear @oli-obk is working on it, though!

@Mark-Simulacrum Mark-Simulacrum added A-const-fn I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels May 29, 2017
@Mark-Simulacrum
Copy link
Member

Same problem as #38180.

@RalfJung RalfJung added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants