]> git.lizzy.rs Git - rust.git/commitdiff
expose a method for converting `hir::Ty` to `Ty<'tcx>`
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 3 May 2017 15:28:22 +0000 (11:28 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 4 May 2017 01:12:00 +0000 (21:12 -0400)
Also, remove a lot of `pub` things from `librustc_typeck`.

src/librustc_typeck/check/coercion.rs
src/librustc_typeck/collect.rs
src/librustc_typeck/lib.rs

index 61d04876bfeb51cfd59fc7967c3bd6df2b528039..b0b57aee5b2537c1652ef0e7dc7b72e26f7795cd 100644 (file)
@@ -965,10 +965,6 @@ fn make(expected_ty: Ty<'tcx>, expressions: Expressions<'gcx, 'exprs, E>) -> Sel
         }
     }
 
-    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
index 0d75a1ecf3d8f30c31ca61195df08f05c0db6f7e..7d1a6894a822270d03d2e51db550352ab15733b1 100644 (file)
@@ -116,7 +116,7 @@ pub fn provide(providers: &mut Providers) {
 /// `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,
 }
@@ -180,7 +180,7 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
 // 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,
@@ -190,7 +190,7 @@ fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
 }
 
 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)
     }
 }
index 94b4bfade9498e0ac764b19da57b5ceecd284267..8bfa38f765ebd501665fdea2f3830c822a5e9ef5 100644 (file)
 // 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>,
@@ -337,4 +337,16 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, '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 }