Rollup merge of #72600 - Aaron1011:fix/anon-const-encoding, r=varkor

Properly encode AnonConst into crate metadata

Fixes #68104

Previous, we were encoding AnonConst as a regular Const, causing us to
treat them differently after being deserialized in another compilation
session.
This commit is contained in:
Ralf Jung 2020-06-20 16:39:45 +02:00 committed by GitHub
commit 5431ef6530
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 3 deletions

View File

@ -565,6 +565,7 @@ impl MetadataBlob {
impl EntryKind {
fn def_kind(&self) -> DefKind {
match *self {
EntryKind::AnonConst(..) => DefKind::AnonConst,
EntryKind::Const(..) => DefKind::Const,
EntryKind::AssocConst(..) => DefKind::AssocConst,
EntryKind::ImmStatic
@ -1121,7 +1122,8 @@ fn get_promoted_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> IndexVec<Promoted
fn mir_const_qualif(&self, id: DefIndex) -> mir::ConstQualifs {
match self.kind(id) {
EntryKind::Const(qualif, _)
EntryKind::AnonConst(qualif, _)
| EntryKind::Const(qualif, _)
| EntryKind::AssocConst(
AssocContainer::ImplDefault
| AssocContainer::ImplFinal
@ -1340,7 +1342,9 @@ fn exported_symbols(
fn get_rendered_const(&self, id: DefIndex) -> String {
match self.kind(id) {
EntryKind::Const(_, data) | EntryKind::AssocConst(_, _, data) => data.decode(self).0,
EntryKind::AnonConst(_, data)
| EntryKind::Const(_, data)
| EntryKind::AssocConst(_, _, data) => data.decode(self).0,
_ => bug!(),
}
}

View File

@ -1358,7 +1358,7 @@ fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) {
let const_data = self.encode_rendered_const_for_body(body_id);
let qualifs = self.tcx.mir_const_qualif(def_id);
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Const(qualifs, const_data));
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data));
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
self.encode_item_type(def_id.to_def_id());

View File

@ -281,6 +281,7 @@ fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> {
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
enum EntryKind {
AnonConst(mir::ConstQualifs, Lazy<RenderedConst>),
Const(mir::ConstQualifs, Lazy<RenderedConst>),
ImmStatic,
MutStatic,

View File

@ -0,0 +1,9 @@
#![feature(const_generics)]
pub struct Num<const N: usize>;
// Braces around const expression causes crash
impl Num<{5}> {
pub fn five(&self) {
}
}

View File

@ -0,0 +1,14 @@
// aux-build:impl-const.rs
// run-pass
#![feature(const_generics)]
#![allow(incomplete_features)]
extern crate impl_const;
use impl_const::*;
pub fn main() {
let n = Num::<5>;
n.five();
}