use rustc::ty::{self, Lift, Ty, TyCtxt, TyKind, GenericParamDefKind, TypeFoldable, ToPredicate};
use rustc::ty::subst::{Subst, InternalSubsts};
use rustc::util::nodemap::{FxHashSet, FxHashMap};
+use rustc::mir::interpret::ConstValue;
use rustc::middle::lang_items;
use rustc::infer::opaque_types::may_define_existential_type;
{
for_item(tcx, item).with_fcx(|fcx, fcx_tcx| {
let variants = lookup_fields(fcx);
- let def_id = fcx.tcx.hir().local_def_id(item.id);
+ let def_id = fcx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let packed = fcx.tcx.adt_def(def_id).repr.packed();
for variant in &variants {
}
fn check_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) {
- debug!("check_trait: {:?}", item.id);
+ debug!("check_trait: {:?}", item.hir_id);
- let trait_def_id = tcx.hir().local_def_id(item.id);
+ let trait_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id);
let trait_def = tcx.trait_def(trait_def_id);
if trait_def.is_marker {
fn check_item_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item: &hir::Item) {
for_item(tcx, item).with_fcx(|fcx, tcx| {
- let def_id = fcx.tcx.hir().local_def_id(item.id);
+ let def_id = fcx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
let sig = fcx.tcx.fn_sig(def_id);
let sig = fcx.normalize_associated_types_in(item.span, &sig);
let mut implied_bounds = vec![];
debug!("check_impl: {:?}", item);
for_item(tcx, item).with_fcx(|fcx, tcx| {
- let item_def_id = fcx.tcx.hir().local_def_id(item.id);
+ let item_def_id = fcx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
match *ast_trait_ref {
Some(ref ast_trait_ref) => {
// struct Foo<T = Vec<[u32]>> { .. }
// Here the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
for param in &generics.params {
- if let GenericParamDefKind::Type {..} = param.kind {
+ if let GenericParamDefKind::Type { .. } = param.kind {
if is_our_default(¶m) {
let ty = fcx.tcx.type_of(param.def_id);
// ignore dependent defaults -- that is, where the default of one type
// All regions are identity.
fcx.tcx.mk_param_from_def(param)
}
- GenericParamDefKind::Type {..} => {
+ GenericParamDefKind::Type { .. } => {
// If the param has a default,
if is_our_default(param) {
let default_ty = fcx.tcx.type_of(param.def_id);
// Mark unwanted params as err.
fcx.tcx.types.err.into()
}
+ GenericParamDefKind::Const => {
+ // FIXME(const_generics:defaults)
+ fcx.tcx.types.err.into()
+ }
}
});
// Now we build the substituted predicates.
fn visit_region(&mut self, _: ty::Region<'tcx>) -> bool {
true
}
+
+ fn visit_const(&mut self, c: &'tcx ty::LazyConst<'tcx>) -> bool {
+ if let ty::LazyConst::Evaluated(ty::Const {
+ val: ConstValue::Param(param),
+ ..
+ }) = c {
+ self.params.insert(param.index);
+ }
+ c.super_visit_with(self)
+ }
}
let mut param_count = CountParams::default();
let has_region = pred.visit_with(&mut param_count);
for (subst, param) in substs.iter().zip(&generics.params) {
match subst.unpack() {
ty::subst::UnpackedKind::Type(ty) => match ty.sty {
- ty::Param(..) => {},
+ ty::Param(..) => {}
// prevent `fn foo() -> Foo<u32>` from being defining
_ => {
- tcx
- .sess
+ tcx.sess
.struct_span_err(
span,
"non-defining existential type use \
),
)
.emit();
- },
- }, // match ty
+ }
+ }
+
ty::subst::UnpackedKind::Lifetime(region) => {
let param_span = tcx.def_span(param.def_id);
if let ty::ReStatic = region {
} else {
seen.entry(region).or_default().push(param_span);
}
- },
+ }
+
+ ty::subst::UnpackedKind::Const(ct) => match ct {
+ ty::LazyConst::Evaluated(ty::Const {
+ val: ConstValue::Param(_),
+ ..
+ }) => {}
+ _ => {
+ tcx.sess
+ .struct_span_err(
+ span,
+ "non-defining existential type use \
+ in defining scope",
+ )
+ .span_note(
+ tcx.def_span(param.def_id),
+ &format!(
+ "used non-generic const {} for \
+ generic parameter",
+ ty,
+ ),
+ )
+ .emit();
+ }
+ }
} // match subst
} // for (subst, param)
for (_, spans) in seen {
item: &hir::Item,
hir_generics: &hir::Generics)
{
- let item_def_id = tcx.hir().local_def_id(item.id);
+ let item_def_id = tcx.hir().local_def_id_from_hir_id(item.hir_id);
let ty = tcx.type_of(item_def_id);
if tcx.has_error_field(ty) {
return;
let parent = tcx.generics_of(generics.parent.unwrap());
let impl_params: FxHashMap<_, _> = parent.params.iter().flat_map(|param| match param.kind {
GenericParamDefKind::Lifetime => None,
- GenericParamDefKind::Type {..} => Some((param.name, param.def_id)),
+ GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {
+ Some((param.name, param.def_id))
+ }
}).collect();
for method_param in &generics.params {
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CheckTypeWellFormedVisitor<'a, 'tcx> {
fn visit_item(&mut self, i: &'tcx hir::Item) {
debug!("visit_item: {:?}", i);
- let def_id = self.tcx.hir().local_def_id(i.id);
+ let def_id = self.tcx.hir().local_def_id_from_hir_id(i.hir_id);
self.tcx.ensure().check_item_well_formed(def_id);
}
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn non_enum_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
let fields = struct_def.fields().iter().map(|field| {
- let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id(field.id));
+ let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id_from_hir_id(field.hir_id));
let field_ty = self.normalize_associated_types_in(field.span,
&field_ty);
AdtField { ty: field_ty, span: field.span }