Include const generic arguments in metadata.
This commit is contained in:
parent
446e5e57b6
commit
eb68bbb2b0
@ -5,7 +5,7 @@ use rustc::middle::cstore::{LinkagePreference, NativeLibrary,
|
||||
EncodedMetadata, ForeignModule};
|
||||
use rustc::hir::def::CtorKind;
|
||||
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc::hir::GenericParamKind;
|
||||
use rustc::hir::{GenericParamKind, AnonConst};
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_index::vec::IndexVec;
|
||||
@ -1711,6 +1711,11 @@ impl Visitor<'tcx> for EncodeContext<'tcx> {
|
||||
intravisit::walk_expr(self, ex);
|
||||
self.encode_info_for_expr(ex);
|
||||
}
|
||||
fn visit_anon_const(&mut self, c: &'tcx AnonConst) {
|
||||
intravisit::walk_anon_const(self, c);
|
||||
let def_id = self.tcx.hir().local_def_id(c.hir_id);
|
||||
self.record(def_id, EncodeContext::encode_info_for_anon_const, def_id);
|
||||
}
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item) {
|
||||
intravisit::walk_item(self, item);
|
||||
let def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
@ -1728,25 +1733,10 @@ impl Visitor<'tcx> for EncodeContext<'tcx> {
|
||||
EncodeContext::encode_info_for_foreign_item,
|
||||
(def_id, ni));
|
||||
}
|
||||
fn visit_variant(&mut self,
|
||||
v: &'tcx hir::Variant,
|
||||
g: &'tcx hir::Generics,
|
||||
id: hir::HirId) {
|
||||
intravisit::walk_variant(self, v, g, id);
|
||||
|
||||
if let Some(ref discr) = v.disr_expr {
|
||||
let def_id = self.tcx.hir().local_def_id(discr.hir_id);
|
||||
self.record(def_id, EncodeContext::encode_info_for_anon_const, def_id);
|
||||
}
|
||||
}
|
||||
fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
|
||||
intravisit::walk_generics(self, generics);
|
||||
self.encode_info_for_generics(generics);
|
||||
}
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
|
||||
intravisit::walk_ty(self, ty);
|
||||
self.encode_info_for_ty(ty);
|
||||
}
|
||||
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef) {
|
||||
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id);
|
||||
self.record(def_id, EncodeContext::encode_info_for_macro_def, macro_def);
|
||||
@ -1784,16 +1774,6 @@ impl EncodeContext<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_info_for_ty(&mut self, ty: &hir::Ty) {
|
||||
match ty.kind {
|
||||
hir::TyKind::Array(_, ref length) => {
|
||||
let def_id = self.tcx.hir().local_def_id(length.hir_id);
|
||||
self.record(def_id, EncodeContext::encode_info_for_anon_const, def_id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_info_for_expr(&mut self, expr: &hir::Expr) {
|
||||
match expr.kind {
|
||||
hir::ExprKind::Closure(..) => {
|
||||
|
@ -0,0 +1,9 @@
|
||||
#![feature(const_generics)]
|
||||
|
||||
pub struct Struct<const N: usize>(pub [u8; N]);
|
||||
|
||||
pub type Alias = Struct<2>;
|
||||
|
||||
pub fn function(value: Struct<3>) -> u8 {
|
||||
value.0[0]
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
// aux-build:const_generic_lib.rs
|
||||
|
||||
extern crate const_generic_lib;
|
||||
|
||||
fn main() {
|
||||
let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
|
||||
//~^ ERROR mismatched types
|
||||
let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
|
||||
//~^ ERROR mismatched types
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/const-argument-cross-crate-mismatch.rs:6:41
|
||||
|
|
||||
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3usize`, found `2usize`
|
||||
|
|
||||
= note: expected type `const_generic_lib::Struct<3usize>`
|
||||
found type `const_generic_lib::Struct<_: usize>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/const-argument-cross-crate-mismatch.rs:8:39
|
||||
|
|
||||
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2usize`, found `3usize`
|
||||
|
|
||||
= note: expected type `const_generic_lib::Struct<2usize>`
|
||||
found type `const_generic_lib::Struct<_: usize>`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
12
src/test/ui/const-generics/const-argument-cross-crate.rs
Normal file
12
src/test/ui/const-generics/const-argument-cross-crate.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// run-pass
|
||||
// aux-build:const_generic_lib.rs
|
||||
|
||||
extern crate const_generic_lib;
|
||||
|
||||
struct Container(const_generic_lib::Alias);
|
||||
|
||||
fn main() {
|
||||
let res = const_generic_lib::function(const_generic_lib::Struct([14u8, 1u8, 2u8]));
|
||||
assert_eq!(res, 14u8);
|
||||
let _ = Container(const_generic_lib::Struct([0u8, 1u8]));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user