about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/item.rs
diff options
context:
space:
mode:
authorCameron Steffen <cam.steffen94@gmail.com>2025-08-05 15:59:44 -0500
committerCameron Steffen <cam.steffen94@gmail.com>2025-09-12 15:14:15 -0500
commit88a8bfcaf0398011b621a981483c288d1e3b64e2 (patch)
treefad6716666fc9403c734082e8c4168f5305aca62 /compiler/rustc_ast_lowering/src/item.rs
parent5590e55b03722fb7da2d965478deb4b5d62bf97a (diff)
downloadrust-88a8bfcaf0398011b621a981483c288d1e3b64e2.tar.gz
rust-88a8bfcaf0398011b621a981483c288d1e3b64e2.zip
Introduce hir::ImplItemImplKind
Diffstat (limited to 'compiler/rustc_ast_lowering/src/item.rs')
-rw-r--r--compiler/rustc_ast_lowering/src/item.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index bb559bd8921..53351f91c46 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -5,7 +5,9 @@ use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
 use rustc_hir::attrs::AttributeKind;
 use rustc_hir::def::{DefKind, PerNS, Res};
 use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
-use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin, Target, find_attr};
+use rustc_hir::{
+    self as hir, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target, find_attr,
+};
 use rustc_index::{IndexSlice, IndexVec};
 use rustc_middle::span_bug;
 use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
@@ -1117,20 +1119,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
             }
         };
 
+        let span = self.lower_span(i.span);
         let item = hir::ImplItem {
             owner_id: hir_id.expect_owner(),
             ident: self.lower_ident(ident),
             generics,
+            impl_kind: if is_in_trait_impl {
+                ImplItemImplKind::Trait {
+                    defaultness,
+                    trait_item_def_id: self
+                        .resolver
+                        .get_partial_res(i.id)
+                        .and_then(|r| r.expect_full_res().opt_def_id())
+                        .ok_or_else(|| {
+                            self.dcx().span_delayed_bug(
+                                span,
+                                "could not resolve trait item being implemented",
+                            )
+                        }),
+                }
+            } else {
+                ImplItemImplKind::Inherent { vis_span: self.lower_span(i.vis.span) }
+            },
             kind,
-            vis_span: self.lower_span(i.vis.span),
-            span: self.lower_span(i.span),
-            defaultness,
+            span,
             has_delayed_lints: !self.delayed_lints.is_empty(),
-            trait_item_def_id: self
-                .resolver
-                .get_partial_res(i.id)
-                .map(|r| r.expect_full_res().opt_def_id())
-                .unwrap_or(None),
         };
         self.arena.alloc(item)
     }