Skip to content

Commit

Permalink
Remove get_parent_fn_decl; it's redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 20, 2024
1 parent b92758a commit addd931
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
13 changes: 2 additions & 11 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,15 +1774,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// that highlight errors inline.
let mut sp = blk.span;
let mut fn_span = None;
if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) {
if let Some((fn_def_id, decl, _)) = self.get_fn_decl(blk.hir_id) {
let ret_sp = decl.output.span();
if let Some(block_sp) = self.parent_item_span(blk.hir_id) {
// HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the
// output would otherwise be incorrect and even misleading. Make sure
// the span we're aiming at correspond to a `fn` body.
if block_sp == blk.span {
sp = ret_sp;
fn_span = Some(ident.span);
fn_span = self.tcx.def_ident_span(fn_def_id);
}
}
}
Expand Down Expand Up @@ -1897,15 +1897,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None
}

/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
pub(crate) fn get_parent_fn_decl(
&self,
blk_id: HirId,
) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> {
let parent = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(blk_id).def_id);
self.get_node_fn_decl(parent).map(|(_, fn_decl, ident, _)| (fn_decl, ident))
}

/// If `expr` is a `match` expression that has only one non-`!` arm, use that arm's tail
/// expression's `Span`, otherwise return `expr.span`. This is done to give better errors
/// when given code like the following:
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl<'hir> Map<'hir> {
self.body_const_context(self.enclosing_body_owner(hir_id)).is_some()
}

/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
/// Retrieves the `HirId` for `id`'s enclosing method's body, unless there's a
/// `while` or `loop` before reaching it, as block tail returns are not
/// available in them.
///
Expand Down

0 comments on commit addd931

Please sign in to comment.