Skip to content

Commit

Permalink
bug-out asyncness query on non-local funtions
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Sep 24, 2019
1 parent 726fe3b commit a744fd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3351,16 +3351,17 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {

/// Check if a function is async.
fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
let node = tcx.hir().get(hir_id);
if let Some(fn_like) = hir::map::blocks::FnLikeNode::from_node(node) {
fn_like.asyncness()
} else {
hir::IsAsync::NotAsync
}
} else {
hir::IsAsync::NotAsync
}
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap_or_else(|| {
bug!("asyncness: expected local `DefId`, got `{:?}`", def_id)
});

let node = tcx.hir().get(hir_id);

let fn_like = hir::map::blocks::FnLikeNode::from_node(node).unwrap_or_else(|| {
bug!("asyncness: expected fn-like node but got `{:?}`", def_id);
});

fn_like.asyncness()
}


Expand Down
3 changes: 2 additions & 1 deletion src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,8 @@ impl<'a, 'tcx> CrateMetadata {
match self.entry(id).kind {
EntryKind::Fn(data) => data.decode(self).asyncness,
EntryKind::Method(data) => data.decode(self).fn_data.asyncness,
_ => hir::IsAsync::NotAsync,
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
_ => bug!("asyncness: expect functions entry."),
}
}

Expand Down

0 comments on commit a744fd0

Please sign in to comment.