Skip to content

Commit 5efc86a

Browse files
committed
expose a method for converting hir::Ty to Ty<'tcx>
Also, remove a lot of `pub` things from `librustc_typeck`.
1 parent ed1f26d commit 5efc86a

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/librustc_typeck/check/coercion.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,10 +965,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
965965
}
966966
}
967967

968-
pub fn is_empty(&self) -> bool {
969-
self.pushed == 0
970-
}
971-
972968
/// Return the "expected type" with which this coercion was
973969
/// constructed. This represents the "downward propagated" type
974970
/// that was given to us at the start of typing whatever construct

src/librustc_typeck/collect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn provide(providers: &mut Providers) {
116116
/// `ItemCtxt` is parameterized by a `DefId` that it uses to satisfy
117117
/// `get_type_parameter_bounds` requests, drawing the information from
118118
/// the AST (`hir::Generics`), recursively.
119-
struct ItemCtxt<'a,'tcx:'a> {
119+
pub struct ItemCtxt<'a,'tcx:'a> {
120120
tcx: TyCtxt<'a, 'tcx, 'tcx>,
121121
item_def_id: DefId,
122122
}
@@ -180,7 +180,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
180180
// Utility types and common code for the above passes.
181181

182182
impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
183-
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
183+
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
184184
-> ItemCtxt<'a,'tcx> {
185185
ItemCtxt {
186186
tcx: tcx,
@@ -190,7 +190,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
190190
}
191191

192192
impl<'a,'tcx> ItemCtxt<'a,'tcx> {
193-
fn to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
193+
pub fn to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
194194
AstConv::ast_ty_to_ty(self, ast_ty)
195195
}
196196
}

src/librustc_typeck/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ use std::iter;
122122
// registered before they are used.
123123
pub mod diagnostics;
124124

125-
pub mod check;
126-
pub mod check_unused;
125+
mod check;
126+
mod check_unused;
127127
mod astconv;
128-
pub mod collect;
128+
mod collect;
129129
mod constrained_type_params;
130130
mod impl_wf_check;
131-
pub mod coherence;
132-
pub mod variance;
131+
mod coherence;
132+
mod variance;
133133

134134
pub struct TypeAndSubsts<'tcx> {
135135
pub substs: &'tcx Substs<'tcx>,
@@ -337,4 +337,16 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
337337
}
338338
}
339339

340+
/// A quasi-deprecated helper used in rustdoc and save-analysis to get
341+
/// the type from a HIR node.
342+
pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> {
343+
// In case there are any projections etc, find the "environment"
344+
// def-id that will be used to determine the traits/predicates in
345+
// scope. This is derived from the enclosing item-like thing.
346+
let env_node_id = tcx.hir.get_parent(hir_ty.id);
347+
let env_def_id = tcx.hir.local_def_id(env_node_id);
348+
let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id);
349+
item_cx.to_ty(hir_ty)
350+
}
351+
340352
__build_diagnostic_array! { librustc_typeck, DIAGNOSTICS }

0 commit comments

Comments
 (0)