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

Properly encode AnonConst into crate metadata #72600

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,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
Expand Down Expand Up @@ -1121,7 +1122,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

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
Expand Down Expand Up @@ -1341,7 +1343,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

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!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ impl EncodeContext<'tcx> {
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());
Expand Down
1 change: 1 addition & 0 deletions src/librustc_metadata/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ define_tables! {

#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
enum EntryKind {
AnonConst(mir::ConstQualifs, Lazy<RenderedConst>),
Const(mir::ConstQualifs, Lazy<RenderedConst>),
ImmStatic,
MutStatic,
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/const-generics/auxiliary/impl-const.rs
Original file line number Diff line number Diff line change
@@ -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) {
}
}
14 changes: 14 additions & 0 deletions src/test/ui/const-generics/issue-68104-print-stack-overflow.rs
Original file line number Diff line number Diff line change
@@ -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();
}