///////////////////////////////////////////////////////////////////////////
/// Context specific to some particular item. This is what implements
-/// AstConv. It has information about the predicates that are defined
+/// `AstConv`. It has information about the predicates that are defined
/// on the trait. Unfortunately, this predicate information is
/// available in various different forms at various points in the
/// process. So we can't just store a pointer to e.g., the AST or the
self.tcx.type_of(def_id);
}
hir::GenericParamKind::Type { .. } => {}
+ hir::GenericParamKind::Const { .. } => {
+ let def_id = self.tcx.hir().local_def_id(param.id);
+ self.tcx.type_of(def_id);
+ }
}
}
intravisit::walk_generics(self, generics);
}
impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
- /// Find bounds from `hir::Generics`. This requires scanning through the
+ /// Finds bounds from `hir::Generics`. This requires scanning through the
/// AST. We do this to avoid having to convert *all* the bounds, which
/// would create artificial cycles. Instead we can only convert the
/// bounds for a type parameter `X` if `X::Foo` is used.
}
/// Tests whether this is the AST for a reference to the type
-/// parameter with id `param_id`. We use this so as to avoid running
+/// parameter with ID `param_id`. We use this so as to avoid running
/// `ast_ty_to_ty`, because we want to avoid triggering an all-out
/// conversion of the type to avoid inducing unnecessary cycles.
fn is_param<'a, 'tcx>(
tcx.alloc_adt_def(def_id, kind, variants, repr)
}
-/// Ensures that the super-predicates of the trait with def-id
+/// Ensures that the super-predicates of the trait with `DefId`
/// trait_def_id are converted and stored. This also ensures that
/// the transitive super-predicates are converted;
fn super_predicates_of<'a, 'tcx>(
i += 1;
Some(ty_param)
}
+ GenericParamKind::Const { .. } => {
+ if param.name.ident().name == keywords::SelfUpper.name() {
+ span_bug!(
+ param.span,
+ "`Self` should not be the name of a regular parameter",
+ );
+ }
+
+ tcx.sess.struct_span_err(
+ param.span,
+ "const generics in any position are currently unsupported",
+ ).emit();
+ tcx.sess.abort_if_errors();
+ bug!();
+ }
_ => None,
}),
);
}) => {
if gen.is_some() {
let hir_id = tcx.hir().node_to_hir_id(node_id);
- return tcx.typeck_tables_of(def_id).node_id_to_type(hir_id);
+ return tcx.typeck_tables_of(def_id).node_type(hir_id);
}
let substs = ty::ClosureSubsts {
},
Node::GenericParam(param) => match ¶m.kind {
- hir::GenericParamKind::Type {
- default: Some(ref ty),
- ..
- } => icx.to_ty(ty),
+ hir::GenericParamKind::Type { default: Some(ref ty), .. } |
+ hir::GenericParamKind::Const { ref ty, .. } => {
+ icx.to_ty(ty)
+ }
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
},
}
/// Returns the early-bound lifetimes declared in this generics
-/// listing. For anything other than fns/methods, this is just all
+/// listing. For anything other than fns/methods, this is just all
/// the lifetimes that are declared. For fns or methods, we have to
/// screen out those that do not appear in any where-clauses etc using
/// `resolve_lifetime::early_bound_lifetimes`.
})
}
+/// Returns a list of type predicates for the definition with ID `def_id`, including inferred
+/// lifetime constraints. This includes all predicates returned by `explicit_predicates_of`, plus
+/// inferred constraints concerning which regions outlive other regions.
fn predicates_defined_on<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
result
}
+/// Returns a list of all type predicates (explicit and implicit) for the definition with
+/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
+/// `Self: Trait` predicates for traits.
fn predicates_of<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
result
}
+/// Returns a list of user-specified type predicates for the definition with ID `def_id`.
+/// N.B., this does not include any implied/inferred constraints.
fn explicit_predicates_of<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
}
/// Converts a specific `GenericBound` from the AST into a set of
-/// predicates that apply to the self-type. A vector is returned
-/// because this can be anywhere from zero predicates (`T : ?Sized` adds no
-/// predicates) to one (`T : Foo`) to many (`T : Bar<X=i32>` adds `T : Bar`
+/// predicates that apply to the self type. A vector is returned
+/// because this can be anywhere from zero predicates (`T: ?Sized` adds no
+/// predicates) to one (`T: Foo`) to many (`T: Bar<X=i32>` adds `T: Bar`
/// and `<T as Bar>::X == i32`).
fn predicates_from_bound<'tcx>(
astconv: &dyn AstConv<'tcx, 'tcx>,