Skip to content

Commit 8a3872e

Browse files
committed
review comments
1 parent cfa0b07 commit 8a3872e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/librustc_typeck/check/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,12 @@ fn diagnostic_only_typeck_tables_of<'tcx>(
953953
tcx: TyCtxt<'tcx>,
954954
def_id: DefId,
955955
) -> &ty::TypeckTables<'tcx> {
956-
let fallback = move || tcx.types.err;
956+
assert!(def_id.is_local());
957+
let fallback = move || {
958+
let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id).unwrap());
959+
tcx.sess.delay_span_bug(span, "diagnostic only typeck table used");
960+
tcx.types.err
961+
};
957962
typeck_tables_of_with_fallback(tcx, def_id, fallback)
958963
}
959964

src/librustc_typeck/collect.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
177177
| hir::ItemKind::Enum(_, generics)
178178
| hir::ItemKind::Struct(_, generics) => (&generics.params[..], true),
179179
hir::ItemKind::TyAlias(_, generics) => (&generics.params[..], false),
180-
// hir::ItemKind::Static(ty, ..) => {
181-
// hir::ItemKind::Fn(..) |
182-
// hir::ItemKind::Const(..) => {} // We handle these elsewhere to suggest appropriate type.
180+
// `static`, `fn` and `const` are handled elsewhere to suggest appropriate type.
183181
_ => return,
184182
};
185183

@@ -1276,7 +1274,7 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
12761274
}
12771275
TraitItemKind::Const(ref ty, body_id) => body_id
12781276
.and_then(|body_id| {
1279-
if is_infer_ty(ty) {
1277+
if is_suggestable_infer_ty(ty) {
12801278
Some(infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident))
12811279
} else {
12821280
None
@@ -1295,7 +1293,7 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
12951293
tcx.mk_fn_def(def_id, substs)
12961294
}
12971295
ImplItemKind::Const(ref ty, body_id) => {
1298-
if is_infer_ty(ty) {
1296+
if is_suggestable_infer_ty(ty) {
12991297
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
13001298
} else {
13011299
icx.to_ty(ty)
@@ -1320,7 +1318,7 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
13201318
Node::Item(item) => {
13211319
match item.kind {
13221320
ItemKind::Static(ref ty, .., body_id) | ItemKind::Const(ref ty, body_id) => {
1323-
if is_infer_ty(ty) {
1321+
if is_suggestable_infer_ty(ty) {
13241322
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
13251323
} else {
13261324
icx.to_ty(ty)
@@ -1792,10 +1790,12 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
17921790
}
17931791
}
17941792

1795-
crate fn is_infer_ty(ty: &hir::Ty<'_>) -> bool {
1793+
/// Whether `ty` is a type with `_` placeholders that can be infered. Used in diagnostics only to
1794+
/// use inference to provide suggestions for the appropriate type if possible.
1795+
fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool {
17961796
match &ty.kind {
17971797
hir::TyKind::Infer => true,
1798-
hir::TyKind::Slice(ty) | hir::TyKind::Array(ty, _) => is_infer_ty(ty),
1798+
hir::TyKind::Slice(ty) | hir::TyKind::Array(ty, _) => is_suggestable_infer_ty(ty),
17991799
hir::TyKind::Tup(tys)
18001800
if !tys.is_empty()
18011801
&& tys.iter().any(|ty| match ty.kind {
@@ -1811,7 +1811,7 @@ crate fn is_infer_ty(ty: &hir::Ty<'_>) -> bool {
18111811

18121812
pub fn get_infer_ret_ty(output: &'hir hir::FunctionRetTy<'hir>) -> Option<&'hir hir::Ty<'hir>> {
18131813
if let hir::FunctionRetTy::Return(ref ty) = output {
1814-
if is_infer_ty(ty) {
1814+
if is_suggestable_infer_ty(ty) {
18151815
return Some(&**ty);
18161816
}
18171817
}

0 commit comments

Comments
 (0)