}
}
- pub fn is_empty(&self) -> bool {
- self.pushed == 0
- }
-
/// Return the "expected type" with which this coercion was
/// constructed. This represents the "downward propagated" type
/// that was given to us at the start of typing whatever construct
/// `ItemCtxt` is parameterized by a `DefId` that it uses to satisfy
/// `get_type_parameter_bounds` requests, drawing the information from
/// the AST (`hir::Generics`), recursively.
-struct ItemCtxt<'a,'tcx:'a> {
+pub struct ItemCtxt<'a,'tcx:'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
item_def_id: DefId,
}
// Utility types and common code for the above passes.
impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
- fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
+ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
-> ItemCtxt<'a,'tcx> {
ItemCtxt {
tcx: tcx,
}
impl<'a,'tcx> ItemCtxt<'a,'tcx> {
- fn to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
+ pub fn to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
AstConv::ast_ty_to_ty(self, ast_ty)
}
}
// registered before they are used.
pub mod diagnostics;
-pub mod check;
-pub mod check_unused;
+mod check;
+mod check_unused;
mod astconv;
-pub mod collect;
+mod collect;
mod constrained_type_params;
mod impl_wf_check;
-pub mod coherence;
-pub mod variance;
+mod coherence;
+mod variance;
pub struct TypeAndSubsts<'tcx> {
pub substs: &'tcx Substs<'tcx>,
}
}
+/// A quasi-deprecated helper used in rustdoc and save-analysis to get
+/// the type from a HIR node.
+pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> {
+ // In case there are any projections etc, find the "environment"
+ // def-id that will be used to determine the traits/predicates in
+ // scope. This is derived from the enclosing item-like thing.
+ let env_node_id = tcx.hir.get_parent(hir_ty.id);
+ let env_def_id = tcx.hir.local_def_id(env_node_id);
+ let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id);
+ item_cx.to_ty(hir_ty)
+}
+
__build_diagnostic_array! { librustc_typeck, DIAGNOSTICS }