Change:
fresh clone of using local Rust and Cargo latest nightly (also occurs in beta-1.25.0), MSVC x64 with Visual Studio 2017 In : set and to Rustup's proxies set (happens only in debug mode) set (specific value doesn't appear to affect the issue) run It gets to this point and ICEs: I grepped the error message () and it points to which appears to be associated with incremental compilation, which makes sense because this only triggers when building in debug mode and setting avoids the ICE. cc rust-lang/cargo
There's a very high chance that this is fixed by
I'll try to build the latest master and see what happens.
Nope, just changed the file the error is emitted from. I have the backtrace here if you like but it's more than 100 frames deep so I don't know how much context you need.
Thanks. I'll have a look. No need for a backtrace
Repro: The problem is that statics don't have allocations (because it makes no sense for them to have usable memory during const evaluation). This is easy to fix :)

Discussion:
pub const ALLOC_DISCRIMINANT: usize = 0; pub const FN_DISCRIMINANT: usize = 1; <ins> pub const EXTERN_STATIC_DISCRIMINANT: usize = 2; pub const SHORTHAND_START: usize = 3; </ins> pub fn specialized_encode_alloc_id< 'a, 'tcx,

trace!("encoding {:?} with {:#?}", alloc_id, alloc); ALLOC_DISCRIMINANT.encode(encoder)?; alloc.encode(encoder)?; <ins> // encode whether this allocation is the root allocation of a static </ins> tcx.interpret_interner .get_corresponding_static_def_id(alloc_id) .encode(encoder)?;

trace!("encoding {:?} with {:#?}", alloc_id, fn_instance); FN_DISCRIMINANT.encode(encoder)?; fn_instance.encode(encoder)?; <ins> } else if let Some(did) = tcx.interpret_interner.get_corresponding_static_def_id(alloc_id) { // extern "C" statics don't have allocations, just encode its def_id EXTERN_STATIC_DISCRIMINANT.encode(encoder)?; did.encode(encoder)?; </ins> } else { bug!("alloc id without corresponding allocation: {}", alloc_id); }

cache(decoder, pos, id); Ok(id) }, <ins> EXTERN_STATIC_DISCRIMINANT => { trace!("creating extern static alloc id at {}", pos); let did = DefId::decode(decoder)?; let alloc_id = tcx.interpret_interner.reserve(); tcx.interpret_interner.cache(did, alloc_id); Ok(alloc_id) }, </ins> shorthand => { trace!("loading shorthand {}", shorthand); short(decoder, shorthand)

// of the metadata file, because that would end up making our indices // not special. It is essentially impossible for that to happen, // but let's make sure <del> assert!(pos != interpret::ALLOC_DISCRIMINANT && pos != interpret::FN_DISCRIMINANT); </del> <ins> assert!(pos >= interpret::SHORTHAND_START); </ins> entry.insert(pos); None },

Entry::Occupied(entry) => Some(entry.get().clone()), Entry::Vacant(entry) => { // ensure that we don't place any AllocIds at the very beginning <del> // of the metadata file, because that would end up making our 0 and 1 indices </del> <ins> // of the metadata file, because that would end up making our indices </ins> // not special. This is essentially impossible, but let's make sure <del> assert!(pos != 0 && pos != 1); </del> <ins> assert!(pos >= interpret::SHORTHAND_START); </ins> entry.insert(pos); None },

<ins> // Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // https://github.com/rust-lang/rust/issues/49153 // revisions:rpass1 rpass2 extern "C" { pub static __ImageBase: u8; } pub static FOO: &'static u8 = unsafe { &__ImageBase }; fn main() {} </ins>