Skip to content

Commit 03dff82

Browse files
committed
Add of_trait to DefKind::Impl.
1 parent 9bb6e60 commit 03dff82

File tree

28 files changed

+68
-64
lines changed

28 files changed

+68
-64
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,13 +1182,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11821182
);
11831183
}
11841184
let parent_did = tcx.parent(method_did);
1185-
let parent_self_ty = (tcx.def_kind(parent_did)
1186-
== rustc_hir::def::DefKind::Impl)
1187-
.then_some(parent_did)
1188-
.and_then(|did| match tcx.type_of(did).kind() {
1189-
ty::Adt(def, ..) => Some(def.did()),
1190-
_ => None,
1191-
});
1185+
let parent_self_ty =
1186+
matches!(tcx.def_kind(parent_did), rustc_hir::def::DefKind::Impl { .. })
1187+
.then_some(parent_did)
1188+
.and_then(|did| match tcx.type_of(did).kind() {
1189+
ty::Adt(def, ..) => Some(def.did()),
1190+
_ => None,
1191+
});
11921192
let is_option_or_result = parent_self_ty.map_or(false, |def_id| {
11931193
matches!(tcx.get_diagnostic_name(def_id), Some(sym::Option | sym::Result))
11941194
});

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
852852

853853
let tcx = self.infcx.tcx;
854854
let region_parent = tcx.parent(region.def_id);
855-
if tcx.def_kind(region_parent) != DefKind::Impl {
855+
let DefKind::Impl { .. } = tcx.def_kind(region_parent) else {
856856
return None;
857-
}
857+
};
858858

859859
let found = tcx
860860
.any_free_region_meets(&tcx.type_of(region_parent), |r| *r == ty::ReEarlyBound(region));

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
1717

1818
pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1919
let parent_id = tcx.local_parent(def_id);
20-
tcx.def_kind(parent_id) == DefKind::Impl && tcx.constness(parent_id) == hir::Constness::Const
20+
matches!(tcx.def_kind(parent_id), DefKind::Impl { .. })
21+
&& tcx.constness(parent_id) == hir::Constness::Const
2122
}
2223

2324
/// Checks whether an item is considered to be `const`. If it is a constructor, it is const. If

compiler/rustc_hir/src/def.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ pub enum DefKind {
116116
LifetimeParam,
117117
/// A use of `global_asm!`.
118118
GlobalAsm,
119-
Impl,
119+
Impl {
120+
of_trait: bool,
121+
},
120122
Closure,
121123
Generator,
122124
}
@@ -155,7 +157,7 @@ impl DefKind {
155157
DefKind::AnonConst => "constant expression",
156158
DefKind::InlineConst => "inline constant",
157159
DefKind::Field => "field",
158-
DefKind::Impl => "implementation",
160+
DefKind::Impl { .. } => "implementation",
159161
DefKind::Closure => "closure",
160162
DefKind::Generator => "generator",
161163
DefKind::ExternCrate => "extern crate",
@@ -171,7 +173,7 @@ impl DefKind {
171173
| DefKind::AssocFn
172174
| DefKind::Enum
173175
| DefKind::OpaqueTy
174-
| DefKind::Impl
176+
| DefKind::Impl { .. }
175177
| DefKind::Use
176178
| DefKind::InlineConst
177179
| DefKind::ExternCrate => "an",
@@ -216,7 +218,7 @@ impl DefKind {
216218
| DefKind::Use
217219
| DefKind::ForeignMod
218220
| DefKind::GlobalAsm
219-
| DefKind::Impl
221+
| DefKind::Impl { .. }
220222
| DefKind::ImplTraitPlaceholder => None,
221223
}
222224
}
@@ -255,7 +257,7 @@ impl DefKind {
255257
| DefKind::ForeignMod
256258
| DefKind::OpaqueTy
257259
| DefKind::ImplTraitPlaceholder
258-
| DefKind::Impl
260+
| DefKind::Impl { .. }
259261
| DefKind::Field
260262
| DefKind::TyParam
261263
| DefKind::ConstParam

compiler/rustc_hir/src/target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Target {
116116
DefKind::Union => Target::Union,
117117
DefKind::Trait => Target::Trait,
118118
DefKind::TraitAlias => Target::TraitAlias,
119-
DefKind::Impl => Target::Impl,
119+
DefKind::Impl { .. } => Target::Impl,
120120
_ => panic!("impossible case reached"),
121121
}
122122
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,21 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
529529
check_enum(tcx, id.owner_id.def_id);
530530
}
531531
DefKind::Fn => {} // entirely within check_item_body
532-
DefKind::Impl => {
533-
let it = tcx.hir().item(id);
534-
let hir::ItemKind::Impl(impl_) = it.kind else { return };
535-
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
536-
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
537-
check_impl_items_against_trait(
538-
tcx,
539-
it.span,
540-
it.owner_id.def_id,
541-
impl_trait_ref.subst_identity(),
542-
&impl_.items,
543-
);
544-
check_on_unimplemented(tcx, it);
532+
DefKind::Impl { of_trait } => {
533+
if of_trait {
534+
let it = tcx.hir().item(id);
535+
let hir::ItemKind::Impl(impl_) = it.kind else { return };
536+
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
537+
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
538+
check_impl_items_against_trait(
539+
tcx,
540+
it.span,
541+
it.owner_id.def_id,
542+
impl_trait_ref.subst_identity(),
543+
&impl_.items,
544+
);
545+
check_on_unimplemented(tcx, it);
546+
}
545547
}
546548
}
547549
DefKind::Trait => {

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'tcx> InherentCollect<'tcx> {
177177
}
178178

179179
fn check_item(&mut self, id: hir::ItemId) {
180-
if !matches!(self.tcx.def_kind(id.owner_id), DefKind::Impl) {
180+
if !matches!(self.tcx.def_kind(id.owner_id), DefKind::Impl { of_trait: false }) {
181181
return;
182182
}
183183

compiler/rustc_hir_analysis/src/collect/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15631563
// See issue #83753. If someone writes an associated type on a non-trait, just treat it as
15641564
// there being no supertrait HRTBs.
15651565
match tcx.def_kind(def_id) {
1566-
DefKind::Trait | DefKind::TraitAlias | DefKind::Impl => {}
1566+
DefKind::Trait | DefKind::TraitAlias | DefKind::Impl { .. } => {}
15671567
_ => break None,
15681568
}
15691569

compiler/rustc_hir_analysis/src/impl_wf_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
5555
let min_specialization = tcx.features().min_specialization;
5656
let module = tcx.hir_module_items(module_def_id);
5757
for id in module.items() {
58-
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
58+
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. }) {
5959
enforce_impl_params_are_constrained(tcx, id.owner_id.def_id);
6060
if min_specialization {
6161
check_min_specialization(tcx, id.owner_id.def_id);

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
10611061
};
10621062

10631063
let parent_def_id = generics.parent.unwrap();
1064-
if tcx.def_kind(parent_def_id) == DefKind::Impl {
1064+
if let DefKind::Impl { .. } = tcx.def_kind(parent_def_id) {
10651065
let parent_ty = tcx.bound_type_of(parent_def_id).subst(tcx, substs);
10661066
match (parent_ty.kind(), &ty.kind) {
10671067
(

0 commit comments

Comments
 (0)