Change:
I'm seeing an internal compiler error on the following input (found by ): The error happens on and , but not on . <details<summaryNightly backtrace</summary</details
triage: P-high, assigning to self.
(This ended up being a great motivation for me to tie off some work I've been doing...)
ICE was introduced between nightly 2020-01-15 and 2010-01-16. Here are the merges from that time period: ( is independently working to identify which one is the culprit.)
Okay finished: searched nightlies: from nightly-2020-01-15 to nightly-2020-01-22 regressed nightly: nightly-2020-01-16 searched commits: from to regressed commit:
Looks like the problem was injected by PR
reassigning to
The following also causes an ICE: (Same reason, but different message.)
Fixed by

Discussion:
/// Error type for `tcx.lit_to_const`. #[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable)] pub enum LitToConstError { <ins> /// The literal's inferred type did not match the expected `ty` in the input. /// This is used for graceful error handling (`delay_span_bug`) in /// type checking (`AstConv::ast_const_to_const`). TypeError, </ins> UnparseableFloat, Reported, }

use rustc::mir::interpret::{ truncate, Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar, }; <del> use rustc::ty::{self, layout::Size, ParamEnv, TyCtxt}; </del> <ins> use rustc::ty::{self, layout::Size, ParamEnv, TyCtxt, TyS}; </ins> use rustc_span::symbol::Symbol; use syntax::ast;

Ok(ConstValue::Scalar(Scalar::from_uint(result, width))) }; <del> let lit = match *lit { ast::LitKind::Str(ref s, _) => { </del> <ins> let lit = match (lit, &ty.kind) { (ast::LitKind::Str(s, _), ty::Ref(_, TyS { kind: ty::Str, .. }, _)) => { </ins> let s = s.as_str(); let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes()); let allocation = tcx.intern_const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: s.len() } } <del> ast::LitKind::ByteStr(ref data) => { if let ty::Ref(_, ref_ty, _) = ty.kind { match ref_ty.kind { ty::Slice(_) => { let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>); let allocation = tcx.intern_const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: data.len() } } ty::Array(_, _) => { let id = tcx.allocate_bytes(data); ConstValue::Scalar(Scalar::Ptr(id.into())) } _ => { bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty) } } } else { bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty) } </del> <ins> (ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Slice(_), .. }, _)) => { let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>); let allocation = tcx.intern_const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: data.len() } } (ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Array(_, _), .. }, _)) => { let id = tcx.allocate_bytes(data); ConstValue::Scalar(Scalar::Ptr(id.into())) } (ast::LitKind::Byte(n), ty::Uint(ast::UintTy::U8)) => { ConstValue::Scalar(Scalar::from_uint(*n, Size::from_bytes(1))) </ins> } <del> ast::LitKind::Byte(n) => ConstValue::Scalar(Scalar::from_uint(n, Size::from_bytes(1))), ast::LitKind::Int(n, _) if neg => { let n = n as i128; let n = n.overflowing_neg().0; trunc(n as u128)? </del> <ins> (ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => { trunc(if neg { (*n as i128).overflowing_neg().0 as u128 } else { *n })? </ins> } <del> ast::LitKind::Int(n, _) => trunc(n)?, ast::LitKind::Float(n, _) => { let fty = match ty.kind { ty::Float(fty) => fty, _ => bug!(), }; parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)? </del> <ins> (ast::LitKind::Float(n, _), ty::Float(fty)) => { parse_float(*n, *fty, neg).map_err(|_| LitToConstError::UnparseableFloat)? </ins> } <del> ast::LitKind::Bool(b) => ConstValue::Scalar(Scalar::from_bool(b)), ast::LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)), ast::LitKind::Err(_) => return Err(LitToConstError::Reported), </del> <ins> (ast::LitKind::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)), (ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)), (ast::LitKind::Err(_), _) => return Err(LitToConstError::Reported), _ => return Err(LitToConstError::TypeError), </ins> }; Ok(ty::Const::from_value(tcx, lit, ty)) }

// create a dummy value and continue compiling Const::from_bits(self.tcx, 0, self.param_env.and(ty)) } <ins> Err(LitToConstError::TypeError) => bug!("const_eval_literal: had type error"), </ins> } }

PatKind::Wild } Err(LitToConstError::Reported) => PatKind::Wild, <ins> Err(LitToConstError::TypeError) => bug!("lower_lit: had type error"), </ins> } } }

// mir. if let Ok(c) = tcx.at(expr.span).lit_to_const(lit_input) { return c; <ins> } else { tcx.sess.delay_span_bug(expr.span, "ast_const_to_const: couldn't lit_to_const"); </ins> } }

<ins> // This is a regression test for #69310, which was injected by #68118. // The issue here was that as a performance optimization, // we call the query `lit_to_const(input);`. // However, the literal `input.lit` would not be of the type expected by `input.ty`. // As a result, we immediately called `bug!(...)` instead of bubbling up the problem // so that it could be handled by the caller of `lit_to_const` (`ast_const_to_const`). fn main() {} const A: [(); 0.1] = [()]; //~ ERROR mismatched types const B: [(); b"a"] = [()]; //~ ERROR mismatched types </ins>

<ins> error[E0308]: mismatched types --> $DIR/issue-69310-array-size-lit-wrong-ty.rs:10:15 | LL | const A: [(); 0.1] = [()]; |               ^^^ expected `usize`, found floating-point number error[E0308]: mismatched types --> $DIR/issue-69310-array-size-lit-wrong-ty.rs:11:15 | LL | const B: [(); b"a"] = [()]; |               ^^^^ expected `usize`, found `&[u8; 1]` error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. </ins>