diff options
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/hir/map/mod.rs | 35 | ||||
| -rw-r--r-- | src/librustc/query/mod.rs | 5 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index d7b1676c1d4..83372dd8ade 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -79,6 +79,33 @@ impl<'hir> Entry<'hir> { } } + fn fn_sig(&self) -> Option<&'hir FnSig> { + match &self.node { + Node::Item(item) => { + match &item.kind { + ItemKind::Fn(sig, _, _) => Some(sig), + _ => None, + } + } + + Node::TraitItem(item) => { + match &item.kind { + TraitItemKind::Method(sig, _) => Some(sig), + _ => None + } + } + + Node::ImplItem(item) => { + match &item.kind { + ImplItemKind::Method(sig, _) => Some(sig), + _ => None, + } + } + + _ => None, + } + } + fn associated_body(self) -> Option<BodyId> { match self.node { Node::Item(item) => { @@ -450,6 +477,14 @@ impl<'hir> Map<'hir> { } } + pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig> { + if let Some(entry) = self.find_entry(hir_id) { + entry.fn_sig() + } else { + bug!("no entry for hir_id `{}`", hir_id) + } + } + /// Returns the `HirId` that corresponds to the definition of /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index bd7b77b0abb..9bd2a933c1c 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -329,6 +329,11 @@ rustc_queries! { desc { |tcx| "checking for unstable API usage in {}", key.describe_as_module(tcx) } } + /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`). + query check_mod_const_bodies(key: DefId) -> () { + desc { |tcx| "checking consts in {}", key.describe_as_module(tcx) } + } + /// Checks the loops in the module. query check_mod_loops(key: DefId) -> () { desc { |tcx| "checking loops in {}", key.describe_as_module(tcx) } |
