Skip to content

Commit a744fd0

Browse files
committed
bug-out asyncness query on non-local funtions
1 parent 726fe3b commit a744fd0

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/librustc/ty/mod.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -3351,16 +3351,17 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
33513351

33523352
/// Check if a function is async.
33533353
fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
3354-
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
3355-
let node = tcx.hir().get(hir_id);
3356-
if let Some(fn_like) = hir::map::blocks::FnLikeNode::from_node(node) {
3357-
fn_like.asyncness()
3358-
} else {
3359-
hir::IsAsync::NotAsync
3360-
}
3361-
} else {
3362-
hir::IsAsync::NotAsync
3363-
}
3354+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap_or_else(|| {
3355+
bug!("asyncness: expected local `DefId`, got `{:?}`", def_id)
3356+
});
3357+
3358+
let node = tcx.hir().get(hir_id);
3359+
3360+
let fn_like = hir::map::blocks::FnLikeNode::from_node(node).unwrap_or_else(|| {
3361+
bug!("asyncness: expected fn-like node but got `{:?}`", def_id);
3362+
});
3363+
3364+
fn_like.asyncness()
33643365
}
33653366

33663367

src/librustc_metadata/decoder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,8 @@ impl<'a, 'tcx> CrateMetadata {
12121212
match self.entry(id).kind {
12131213
EntryKind::Fn(data) => data.decode(self).asyncness,
12141214
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
1215-
_ => hir::IsAsync::NotAsync,
1215+
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
1216+
_ => bug!("asyncness: expect functions entry."),
12161217
}
12171218
}
12181219

0 commit comments

Comments
 (0)