Merge implementations of HIR fn_decl and fn_sig.
This commit is contained in:
parent
a785176741
commit
20012ea4eb
@ -3216,7 +3216,7 @@ pub fn span(&self) -> Span {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fn_decl(&self) -> Option<&FnDecl<'hir>> {
|
pub fn fn_decl(self) -> Option<&'hir FnDecl<'hir>> {
|
||||||
match self {
|
match self {
|
||||||
OwnerNode::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
|
OwnerNode::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
|
||||||
| OwnerNode::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
|
| OwnerNode::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
|
||||||
@ -3400,19 +3400,20 @@ pub fn ident(&self) -> Option<Ident> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fn_decl(&self) -> Option<&'hir FnDecl<'hir>> {
|
pub fn fn_decl(self) -> Option<&'hir FnDecl<'hir>> {
|
||||||
match self {
|
match self {
|
||||||
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
|
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
|
||||||
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
|
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
|
||||||
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl),
|
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl),
|
||||||
Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
|
Node::Expr(Expr { kind: ExprKind::Closure(Closure { fn_decl, .. }), .. })
|
||||||
|
| Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
|
||||||
Some(fn_decl)
|
Some(fn_decl)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fn_sig(&self) -> Option<&'hir FnSig<'hir>> {
|
pub fn fn_sig(self) -> Option<&'hir FnSig<'hir>> {
|
||||||
match self {
|
match self {
|
||||||
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
|
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
|
||||||
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
|
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
|
||||||
|
@ -17,28 +17,6 @@
|
|||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
|
|
||||||
match node {
|
|
||||||
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
|
|
||||||
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
|
|
||||||
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => Some(&sig.decl),
|
|
||||||
Node::Expr(Expr { kind: ExprKind::Closure(Closure { fn_decl, .. }), .. })
|
|
||||||
| Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, ..), .. }) => {
|
|
||||||
Some(fn_decl)
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
|
|
||||||
match &node {
|
|
||||||
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
|
|
||||||
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
|
|
||||||
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => Some(sig),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
|
pub fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
|
||||||
match node {
|
match node {
|
||||||
@ -384,7 +362,7 @@ pub fn body(self, id: BodyId) -> &'hir Body<'hir> {
|
|||||||
|
|
||||||
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
||||||
if let Some(node) = self.find(hir_id) {
|
if let Some(node) = self.find(hir_id) {
|
||||||
fn_decl(node)
|
node.fn_decl()
|
||||||
} else {
|
} else {
|
||||||
bug!("no node for hir_id `{}`", hir_id)
|
bug!("no node for hir_id `{}`", hir_id)
|
||||||
}
|
}
|
||||||
@ -392,7 +370,7 @@ pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
|||||||
|
|
||||||
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
|
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
|
||||||
if let Some(node) = self.find(hir_id) {
|
if let Some(node) = self.find(hir_id) {
|
||||||
fn_sig(node)
|
node.fn_sig()
|
||||||
} else {
|
} else {
|
||||||
bug!("no node for hir_id `{}`", hir_id)
|
bug!("no node for hir_id `{}`", hir_id)
|
||||||
}
|
}
|
||||||
|
@ -541,7 +541,7 @@ fn fn_sig_and_body<'tcx>(
|
|||||||
// to HIR for it.
|
// to HIR for it.
|
||||||
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
|
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
|
||||||
let fn_body_id = hir::map::associated_body(hir_node).expect("HIR node is a function with body");
|
let fn_body_id = hir::map::associated_body(hir_node).expect("HIR node is a function with body");
|
||||||
(hir::map::fn_sig(hir_node), tcx.hir().body(fn_body_id))
|
(hir_node.fn_sig(), tcx.hir().body(fn_body_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_body_span<'tcx>(
|
fn get_body_span<'tcx>(
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
MultiSpan,
|
MultiSpan,
|
||||||
};
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::hir::map::fn_sig;
|
|
||||||
use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
|
use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::def_id::DefId;
|
use rustc_span::def_id::DefId;
|
||||||
@ -368,7 +367,7 @@ fn get_type_or_const_args_suggestions_from_param_names(
|
|||||||
&self,
|
&self,
|
||||||
num_params_to_take: usize,
|
num_params_to_take: usize,
|
||||||
) -> String {
|
) -> String {
|
||||||
let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(fn_sig);
|
let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(hir::Node::fn_sig);
|
||||||
let is_used_in_input = |def_id| {
|
let is_used_in_input = |def_id| {
|
||||||
fn_sig.map_or(false, |fn_sig| {
|
fn_sig.map_or(false, |fn_sig| {
|
||||||
fn_sig.decl.inputs.iter().any(|ty| match ty.kind {
|
fn_sig.decl.inputs.iter().any(|ty| match ty.kind {
|
||||||
|
Loading…
Reference in New Issue
Block a user