diff options
| author | Ralf Jung <post@ralfj.de> | 2025-01-04 11:30:31 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-01-04 11:35:31 +0100 |
| commit | be65012aa34aa3b8d27e0e372b9eb86743d5aa8f (patch) | |
| tree | dc1f494a710d956e2ea18047b87a81225857db00 /compiler/rustc_trait_selection/src | |
| parent | c528b8c67895bfe7fdcdfeb56ec5bf6ef928dcd7 (diff) | |
| download | rust-be65012aa34aa3b8d27e0e372b9eb86743d5aa8f.tar.gz rust-be65012aa34aa3b8d27e0e372b9eb86743d5aa8f.zip | |
turn hir::ItemKind::Fn into a named-field variant
Diffstat (limited to 'compiler/rustc_trait_selection/src')
7 files changed, 27 insertions, 15 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index ee5ce19cb4d..d71938b40fe 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -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, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index b97f3dc303b..2cfccc57c97 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -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(..), .. }), ) diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs index 08775df5ac9..36270e0da78 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs @@ -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), .. }) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 885b606326c..f9a30408326 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -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, _), .. diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs index a401fcf3505..51efe39a7bc 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs @@ -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") } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 1b8b35f18df..e052634ad4c 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -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) diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 700c79a7065..a8fddff4e4a 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -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, .. }) |
