turn hir::ItemKind::Fn into a named-field variant
This commit is contained in:
parent
c528b8c678
commit
be65012aa3
65 changed files with 158 additions and 111 deletions
|
@ -1978,7 +1978,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
return None;
|
||||
};
|
||||
let tykind = match self.tcx.hir_node_by_def_id(trace.cause.body_id) {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) => {
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Fn { body: body_id, .. }, ..
|
||||
}) => {
|
||||
let body = hir.body(*body_id);
|
||||
struct LetVisitor {
|
||||
span: Span,
|
||||
|
|
|
@ -630,7 +630,7 @@ impl<T> Trait<T> for X {
|
|||
let callable_scope = matches!(
|
||||
body_owner,
|
||||
Some(
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { .. }, .. })
|
||||
| hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. })
|
||||
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
|
||||
)
|
||||
|
|
|
@ -817,7 +817,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
pat.walk(&mut find_compatible_candidates);
|
||||
}
|
||||
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body), .. })
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { body, .. }, .. })
|
||||
| hir::Node::ImplItem(hir::ImplItem {
|
||||
kind: hir::ImplItemKind::Fn(_, body), ..
|
||||
})
|
||||
|
|
|
@ -913,7 +913,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
let hir_id = self.tcx.local_def_id_to_hir_id(obligation.cause.body_id);
|
||||
let body_id = match self.tcx.hir_node(hir_id) {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) => body_id,
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Fn { body: body_id, .. }, ..
|
||||
}) => body_id,
|
||||
_ => return false,
|
||||
};
|
||||
let ControlFlow::Break(expr) = (FindMethodSubexprOfTry { search_span: span })
|
||||
|
@ -2910,7 +2912,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
})
|
||||
.collect::<Option<Vec<ArgKind>>>()?,
|
||||
),
|
||||
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref sig, ..), .. })
|
||||
Node::Item(&hir::Item { kind: hir::ItemKind::Fn { ref sig, .. }, .. })
|
||||
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(ref sig, _), .. })
|
||||
| Node::TraitItem(&hir::TraitItem {
|
||||
kind: hir::TraitItemKind::Fn(ref sig, _), ..
|
||||
|
|
|
@ -91,7 +91,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
/// to be the enclosing (async) block/function/closure
|
||||
fn describe_enclosure(&self, def_id: LocalDefId) -> Option<&'static str> {
|
||||
match self.tcx.hir_node_by_def_id(def_id) {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. }) => Some("a function"),
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { .. }, .. }) => Some("a function"),
|
||||
hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. }) => {
|
||||
Some("a trait method")
|
||||
}
|
||||
|
|
|
@ -311,7 +311,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
..
|
||||
})
|
||||
| hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Fn(fn_sig, generics, _), ..
|
||||
kind: hir::ItemKind::Fn { sig: fn_sig, generics, .. },
|
||||
..
|
||||
}) if projection.is_some() => {
|
||||
// Missing restriction on associated type of type parameter (unmet projection).
|
||||
suggest_restriction(
|
||||
|
@ -355,7 +356,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
| hir::ItemKind::Union(_, generics)
|
||||
| hir::ItemKind::Trait(_, _, generics, ..)
|
||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||
| hir::ItemKind::Fn(_, generics, _)
|
||||
| hir::ItemKind::Fn { generics, .. }
|
||||
| hir::ItemKind::TyAlias(_, generics)
|
||||
| hir::ItemKind::Const(_, generics, _)
|
||||
| hir::ItemKind::TraitAlias(generics, _),
|
||||
|
@ -420,7 +421,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
| hir::ItemKind::Union(_, generics)
|
||||
| hir::ItemKind::Trait(_, _, generics, ..)
|
||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||
| hir::ItemKind::Fn(_, generics, _)
|
||||
| hir::ItemKind::Fn { generics, .. }
|
||||
| hir::ItemKind::TyAlias(_, generics)
|
||||
| hir::ItemKind::Const(_, generics, _)
|
||||
| hir::ItemKind::TraitAlias(generics, _),
|
||||
|
@ -846,7 +847,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
};
|
||||
name.to_string()
|
||||
}
|
||||
Some(hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(..), .. })) => {
|
||||
Some(hir::Node::Item(hir::Item {
|
||||
ident, kind: hir::ItemKind::Fn { .. }, ..
|
||||
})) => {
|
||||
err.span_label(ident.span, "consider calling this function");
|
||||
ident.to_string()
|
||||
}
|
||||
|
@ -1711,7 +1714,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
) -> bool {
|
||||
let hir = self.tcx.hir();
|
||||
let node = self.tcx.hir_node_by_def_id(obligation.cause.body_id);
|
||||
if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) = node
|
||||
if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn {sig, body: body_id, .. }, .. }) = node
|
||||
&& let hir::ExprKind::Block(blk, _) = &hir.body(*body_id).value.kind
|
||||
&& sig.decl.output.span().overlaps(span)
|
||||
&& blk.expr.is_none()
|
||||
|
@ -1745,7 +1748,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub(super) fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span> {
|
||||
let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. }) =
|
||||
let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { sig, .. }, .. }) =
|
||||
self.tcx.hir_node_by_def_id(obligation.cause.body_id)
|
||||
else {
|
||||
return None;
|
||||
|
@ -1859,7 +1862,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
|
||||
let hir = self.tcx.hir();
|
||||
let node = self.tcx.hir_node_by_def_id(obligation.cause.body_id);
|
||||
if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) = node {
|
||||
if let hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Fn { body: body_id, .. }, ..
|
||||
}) = node
|
||||
{
|
||||
let body = hir.body(*body_id);
|
||||
// Point at all the `return`s in the function as they have failed trait bounds.
|
||||
let mut visitor = ReturnsVisitor::default();
|
||||
|
@ -4737,7 +4743,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
node: hir::Node<'hir>,
|
||||
) -> Option<(&'hir hir::FnDecl<'hir>, hir::BodyId)> {
|
||||
match node {
|
||||
hir::Node::Item(item) if let hir::ItemKind::Fn(sig, _, body_id) = item.kind => {
|
||||
hir::Node::Item(item)
|
||||
if let hir::ItemKind::Fn { sig, body: body_id, .. } = item.kind =>
|
||||
{
|
||||
Some((sig.decl, body_id))
|
||||
}
|
||||
hir::Node::ImplItem(item)
|
||||
|
|
|
@ -520,7 +520,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
|
|||
let is_impl = matches!(&node, hir::Node::ImplItem(_));
|
||||
let (generics, parent_generics) = match node {
|
||||
hir::Node::Item(&hir::Item {
|
||||
kind: hir::ItemKind::Fn(_, ref generics, ..),
|
||||
kind: hir::ItemKind::Fn { ref generics, .. },
|
||||
..
|
||||
})
|
||||
| hir::Node::TraitItem(&hir::TraitItem { ref generics, .. })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue