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
(

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
838838
| DefKind::ForeignMod
839839
| DefKind::OpaqueTy
840840
| DefKind::ImplTraitPlaceholder
841-
| DefKind::Impl
841+
| DefKind::Impl { .. }
842842
| DefKind::Field => true,
843843
DefKind::TyParam
844844
| DefKind::ConstParam
@@ -873,7 +873,7 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
873873
| DefKind::ImplTraitPlaceholder
874874
| DefKind::Enum
875875
| DefKind::Union
876-
| DefKind::Impl
876+
| DefKind::Impl { .. }
877877
| DefKind::Trait
878878
| DefKind::TraitAlias
879879
| DefKind::Macro(..)
@@ -951,7 +951,7 @@ fn should_encode_variances(def_kind: DefKind) -> bool {
951951
| DefKind::Const
952952
| DefKind::ForeignMod
953953
| DefKind::TyAlias
954-
| DefKind::Impl
954+
| DefKind::Impl { .. }
955955
| DefKind::Trait
956956
| DefKind::TraitAlias
957957
| DefKind::Macro(..)
@@ -988,7 +988,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
988988
| DefKind::InlineConst
989989
| DefKind::OpaqueTy
990990
| DefKind::ImplTraitPlaceholder
991-
| DefKind::Impl
991+
| DefKind::Impl { .. }
992992
| DefKind::Field
993993
| DefKind::TyParam
994994
| DefKind::Closure
@@ -1018,7 +1018,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
10181018
| DefKind::TyAlias
10191019
| DefKind::OpaqueTy
10201020
| DefKind::ForeignTy
1021-
| DefKind::Impl
1021+
| DefKind::Impl { .. }
10221022
| DefKind::AssocFn
10231023
| DefKind::AssocConst
10241024
| DefKind::Closure
@@ -1081,7 +1081,7 @@ fn should_encode_const(def_kind: DefKind) -> bool {
10811081
| DefKind::OpaqueTy
10821082
| DefKind::ImplTraitPlaceholder
10831083
| DefKind::ForeignTy
1084-
| DefKind::Impl
1084+
| DefKind::Impl { .. }
10851085
| DefKind::AssocFn
10861086
| DefKind::Closure
10871087
| DefKind::Generator
@@ -1860,7 +1860,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18601860
FxHashMap::default();
18611861

18621862
for id in tcx.hir().items() {
1863-
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
1863+
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. }) {
18641864
if let Some(trait_ref) = tcx.impl_trait_ref(id.owner_id) {
18651865
let trait_ref = trait_ref.subst_identity();
18661866

@@ -2261,7 +2261,7 @@ pub fn provide(providers: &mut Providers) {
22612261

22622262
let mut trait_impls = Vec::new();
22632263
for id in tcx.hir().items() {
2264-
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl)
2264+
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
22652265
&& tcx.impl_trait_ref(id.owner_id).is_some()
22662266
{
22672267
trait_impls.push(id.owner_id.to_def_id())

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ fixed_size_enum! {
136136
( Field )
137137
( LifetimeParam )
138138
( GlobalAsm )
139-
( Impl )
139+
( Impl { of_trait: false } )
140+
( Impl { of_trait: true } )
140141
( Closure )
141142
( Generator )
142143
( Static(ast::Mutability::Not) )

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'hir> Map<'hir> {
203203
ItemKind::Use(..) => DefKind::Use,
204204
ItemKind::ForeignMod { .. } => DefKind::ForeignMod,
205205
ItemKind::GlobalAsm(..) => DefKind::GlobalAsm,
206-
ItemKind::Impl { .. } => DefKind::Impl,
206+
ItemKind::Impl(impl_) => DefKind::Impl { of_trait: impl_.of_trait.is_some() },
207207
},
208208
Node::ForeignItem(item) => match item.kind {
209209
ForeignItemKind::Fn(..) => DefKind::Fn,

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ impl<'tcx> TyCtxt<'tcx> {
24272427
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
24282428
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
24292429
let parent = self.parent(def_id);
2430-
if let DefKind::Impl = self.def_kind(parent) {
2430+
if let DefKind::Impl { .. } = self.def_kind(parent) {
24312431
return Some(parent);
24322432
}
24332433
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'tcx> TyCtxt<'tcx> {
167167
| DefKind::Fn
168168
| DefKind::AssocFn
169169
| DefKind::AssocConst
170-
| DefKind::Impl,
170+
| DefKind::Impl { .. },
171171
def_id,
172172
) => Some(def_id),
173173
Res::Err => None,

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ impl<'v> RootCollector<'_, 'v> {
12381238
collect_const_value(self.tcx, val, &mut self.output);
12391239
}
12401240
}
1241-
DefKind::Impl => {
1241+
DefKind::Impl { .. } => {
12421242
if self.mode == MonoItemCollectionMode::Eager {
12431243
let item = self.tcx.hir().item(id);
12441244
create_mono_items_for_default_impls(self.tcx, item, self.output);

compiler/rustc_monomorphize/src/polymorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn mark_used_by_default_parameters<'tcx>(
172172
| DefKind::Field
173173
| DefKind::LifetimeParam
174174
| DefKind::GlobalAsm
175-
| DefKind::Impl => {
175+
| DefKind::Impl { .. } => {
176176
for param in &generics.params {
177177
debug!(?param, "(other)");
178178
if let ty::GenericParamDefKind::Lifetime = param.kind {

compiler/rustc_passes/src/dead.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,8 @@ fn check_item<'tcx>(
526526
}
527527
}
528528
}
529-
DefKind::Impl => {
530-
let of_trait = tcx.impl_trait_ref(id.owner_id);
531-
532-
if of_trait.is_some() {
529+
DefKind::Impl { of_trait } => {
530+
if of_trait {
533531
worklist.push(id.owner_id.def_id);
534532
}
535533

@@ -541,7 +539,7 @@ fn check_item<'tcx>(
541539

542540
// And we access the Map here to get HirId from LocalDefId
543541
for id in local_def_ids {
544-
if of_trait.is_some() || has_allow_dead_code_or_lang_attr(tcx, id) {
542+
if of_trait || has_allow_dead_code_or_lang_attr(tcx, id) {
545543
worklist.push(id);
546544
}
547545
}

compiler/rustc_passes/src/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: DefId) {
145145

146146
// Don't run unused pass for #[derive()]
147147
let parent = tcx.local_parent(local_def_id);
148-
if let DefKind::Impl = tcx.def_kind(parent)
148+
if let DefKind::Impl { .. } = tcx.def_kind(parent)
149149
&& tcx.has_attr(parent.to_def_id(), sym::automatically_derived)
150150
{
151151
return;

compiler/rustc_passes/src/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ fn check_item<'tcx>(
320320
worklist.push(id.owner_id.def_id);
321321
}
322322

323-
if !matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
323+
if !matches!(tcx.def_kind(id.owner_id), DefKind::Impl { of_trait: true }) {
324324
return;
325325
}
326326

compiler/rustc_privacy/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
593593
| DefKind::InlineConst
594594
| DefKind::Field
595595
| DefKind::GlobalAsm
596-
| DefKind::Impl
596+
| DefKind::Impl { .. }
597597
| DefKind::Closure
598598
| DefKind::Generator => (),
599599
}
@@ -1997,7 +1997,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
19971997
// Subitems of inherent impls have their own publicity.
19981998
// A trait impl is public when both its type and its trait are public
19991999
// Subitems of trait impls have inherited publicity.
2000-
DefKind::Impl => {
2000+
DefKind::Impl { .. } => {
20012001
let item = tcx.hir().item(id);
20022002
if let hir::ItemKind::Impl(ref impl_) = item.kind {
20032003
let impl_vis =

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
987987
| DefKind::LifetimeParam
988988
| DefKind::GlobalAsm
989989
| DefKind::Closure
990-
| DefKind::Impl
990+
| DefKind::Impl { .. }
991991
| DefKind::Generator,
992992
_,
993993
)

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ impl<'tcx> SaveContext<'tcx> {
733733
| HirDefKind::Use
734734
| HirDefKind::Field
735735
| HirDefKind::GlobalAsm
736-
| HirDefKind::Impl
736+
| HirDefKind::Impl { .. }
737737
| HirDefKind::Closure
738738
| HirDefKind::Generator,
739739
_,

compiler/rustc_ty_utils/src/implied_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
2121
assumed_wf_types.extend(liberated_sig.inputs_and_output);
2222
tcx.intern_type_list(&assumed_wf_types)
2323
}
24-
DefKind::Impl => {
24+
DefKind::Impl { .. } => {
2525
match tcx.impl_trait_ref(def_id) {
2626
Some(trait_ref) => {
2727
let types: Vec<_> = trait_ref.skip_binder().substs.types().collect();

src/librustdoc/formats/item_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl From<DefKind> for ItemType {
140140
| DefKind::Field
141141
| DefKind::LifetimeParam
142142
| DefKind::GlobalAsm
143-
| DefKind::Impl
143+
| DefKind::Impl { .. }
144144
| DefKind::Closure
145145
| DefKind::Generator => Self::ForeignType,
146146
}

0 commit comments

Comments
 (0)