Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c8c25ce

Browse files
Rename some OwnerId fields.
spastorino noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone.
1 parent 33b55ac commit c8c25ce

File tree

107 files changed

+618
-603
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+618
-603
lines changed

‎compiler/rustc_ast_lowering/src/index.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,19 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
112112
113113
fn visit_nested_item(&mut self, item: ItemId) {
114114
debug!("visit_nested_item: {:?}", item);
115-
self.insert_nested(item.def_id.def_id);
115+
self.insert_nested(item.owner_id.def_id);
116116
}
117117

118118
fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
119-
self.insert_nested(item_id.def_id.def_id);
119+
self.insert_nested(item_id.owner_id.def_id);
120120
}
121121

122122
fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
123-
self.insert_nested(item_id.def_id.def_id);
123+
self.insert_nested(item_id.owner_id.def_id);
124124
}
125125

126126
fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) {
127-
self.insert_nested(foreign_id.def_id.def_id);
127+
self.insert_nested(foreign_id.owner_id.def_id);
128128
}
129129

130130
fn visit_nested_body(&mut self, id: BodyId) {
@@ -143,7 +143,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
143143

144144
#[instrument(level = "debug", skip(self))]
145145
fn visit_item(&mut self, i: &'hir Item<'hir>) {
146-
debug_assert_eq!(i.def_id, self.owner);
146+
debug_assert_eq!(i.owner_id, self.owner);
147147
self.with_parent(i.hir_id(), |this| {
148148
if let ItemKind::Struct(ref struct_def, _) = i.kind {
149149
// If this is a tuple or unit-like struct, register the constructor.
@@ -157,7 +157,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
157157

158158
#[instrument(level = "debug", skip(self))]
159159
fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) {
160-
debug_assert_eq!(fi.def_id, self.owner);
160+
debug_assert_eq!(fi.owner_id, self.owner);
161161
self.with_parent(fi.hir_id(), |this| {
162162
intravisit::walk_foreign_item(this, fi);
163163
});
@@ -176,15 +176,15 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
176176

177177
#[instrument(level = "debug", skip(self))]
178178
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
179-
debug_assert_eq!(ti.def_id, self.owner);
179+
debug_assert_eq!(ti.owner_id, self.owner);
180180
self.with_parent(ti.hir_id(), |this| {
181181
intravisit::walk_trait_item(this, ti);
182182
});
183183
}
184184

185185
#[instrument(level = "debug", skip(self))]
186186
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
187-
debug_assert_eq!(ii.def_id, self.owner);
187+
debug_assert_eq!(ii.owner_id, self.owner);
188188
self.with_parent(ii.hir_id(), |this| {
189189
intravisit::walk_impl_item(this, ii);
190190
});

‎compiler/rustc_ast_lowering/src/item.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
178178

179179
pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
180180
let mut node_ids =
181-
smallvec![hir::ItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }];
181+
smallvec![hir::ItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }];
182182
if let ItemKind::Use(ref use_tree) = &i.kind {
183183
self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids);
184184
}
@@ -195,7 +195,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
195195
UseTreeKind::Nested(ref nested_vec) => {
196196
for &(ref nested, id) in nested_vec {
197197
vec.push(hir::ItemId {
198-
def_id: hir::OwnerId { def_id: self.local_def_id(id) },
198+
owner_id: hir::OwnerId { def_id: self.local_def_id(id) },
199199
});
200200
self.lower_item_id_use_tree(nested, id, vec);
201201
}
@@ -206,7 +206,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
206206
iter::zip(self.expect_full_res_from_use(base_id).skip(1), &[id1, id2])
207207
{
208208
vec.push(hir::ItemId {
209-
def_id: hir::OwnerId { def_id: self.local_def_id(id) },
209+
owner_id: hir::OwnerId { def_id: self.local_def_id(id) },
210210
});
211211
}
212212
}
@@ -220,7 +220,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
220220
let attrs = self.lower_attrs(hir_id, &i.attrs);
221221
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, vis_span, &i.kind);
222222
let item = hir::Item {
223-
def_id: hir_id.expect_owner(),
223+
owner_id: hir_id.expect_owner(),
224224
ident: self.lower_ident(ident),
225225
kind,
226226
vis_span,
@@ -562,7 +562,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
562562
}
563563

564564
let item = hir::Item {
565-
def_id: hir::OwnerId { def_id: new_id },
565+
owner_id: hir::OwnerId { def_id: new_id },
566566
ident: this.lower_ident(ident),
567567
kind,
568568
vis_span,
@@ -640,7 +640,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
640640
}
641641

642642
let item = hir::Item {
643-
def_id: hir::OwnerId { def_id: new_hir_id },
643+
owner_id: hir::OwnerId { def_id: new_hir_id },
644644
ident: this.lower_ident(ident),
645645
kind,
646646
vis_span,
@@ -660,10 +660,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
660660

661661
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
662662
let hir_id = self.lower_node_id(i.id);
663-
let def_id = hir_id.expect_owner();
663+
let owner_id = hir_id.expect_owner();
664664
self.lower_attrs(hir_id, &i.attrs);
665665
let item = hir::ForeignItem {
666-
def_id,
666+
owner_id,
667667
ident: self.lower_ident(i.ident),
668668
kind: match i.kind {
669669
ForeignItemKind::Fn(box Fn { ref sig, ref generics, .. }) => {
@@ -702,7 +702,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
702702

703703
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
704704
hir::ForeignItemRef {
705-
id: hir::ForeignItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } },
705+
id: hir::ForeignItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } },
706706
ident: self.lower_ident(i.ident),
707707
span: self.lower_span(i.span),
708708
}
@@ -845,7 +845,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
845845

846846
self.lower_attrs(hir_id, &i.attrs);
847847
let item = hir::TraitItem {
848-
def_id: trait_item_def_id,
848+
owner_id: trait_item_def_id,
849849
ident: self.lower_ident(i.ident),
850850
generics,
851851
kind,
@@ -864,7 +864,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
864864
}
865865
AssocItemKind::MacCall(..) => unimplemented!(),
866866
};
867-
let id = hir::TraitItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } };
867+
let id = hir::TraitItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } };
868868
hir::TraitItemRef {
869869
id,
870870
ident: self.lower_ident(i.ident),
@@ -931,7 +931,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
931931
let hir_id = self.lower_node_id(i.id);
932932
self.lower_attrs(hir_id, &i.attrs);
933933
let item = hir::ImplItem {
934-
def_id: hir_id.expect_owner(),
934+
owner_id: hir_id.expect_owner(),
935935
ident: self.lower_ident(i.ident),
936936
generics,
937937
kind,
@@ -944,7 +944,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
944944

945945
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
946946
hir::ImplItemRef {
947-
id: hir::ImplItemId { def_id: hir::OwnerId { def_id: self.local_def_id(i.id) } },
947+
id: hir::ImplItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } },
948948
ident: self.lower_ident(i.ident),
949949
span: self.lower_span(i.span),
950950
kind: match &i.kind {

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15741574

15751575
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
15761576
hir::TyKind::OpaqueDef(
1577-
hir::ItemId { def_id: hir::OwnerId { def_id: opaque_ty_def_id } },
1577+
hir::ItemId { owner_id: hir::OwnerId { def_id: opaque_ty_def_id } },
15781578
lifetimes,
15791579
in_trait,
15801580
)
@@ -1593,7 +1593,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15931593
// Generate an `type Foo = impl Trait;` declaration.
15941594
trace!("registering opaque type with id {:#?}", opaque_ty_id);
15951595
let opaque_ty_item = hir::Item {
1596-
def_id: hir::OwnerId { def_id: opaque_ty_id },
1596+
owner_id: hir::OwnerId { def_id: opaque_ty_id },
15971597
ident: Ident::empty(),
15981598
kind: opaque_ty_item_kind,
15991599
vis_span: self.lower_span(span.shrink_to_lo()),
@@ -2044,7 +2044,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20442044
// async fn, so the *type parameters* are inherited. It's
20452045
// only the lifetime parameters that we must supply.
20462046
let opaque_ty_ref = hir::TyKind::OpaqueDef(
2047-
hir::ItemId { def_id: hir::OwnerId { def_id: opaque_ty_def_id } },
2047+
hir::ItemId { owner_id: hir::OwnerId { def_id: opaque_ty_def_id } },
20482048
generic_args,
20492049
in_trait,
20502050
);

‎compiler/rustc_hir/src/hir.rs‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,14 +2207,14 @@ pub struct FnSig<'hir> {
22072207
// so it can fetched later.
22082208
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
22092209
pub struct TraitItemId {
2210-
pub def_id: OwnerId,
2210+
pub owner_id: OwnerId,
22112211
}
22122212

22132213
impl TraitItemId {
22142214
#[inline]
22152215
pub fn hir_id(&self) -> HirId {
22162216
// Items are always HIR owners.
2217-
HirId::make_owner(self.def_id.def_id)
2217+
HirId::make_owner(self.owner_id.def_id)
22182218
}
22192219
}
22202220

@@ -2225,7 +2225,7 @@ impl TraitItemId {
22252225
#[derive(Debug, HashStable_Generic)]
22262226
pub struct TraitItem<'hir> {
22272227
pub ident: Ident,
2228-
pub def_id: OwnerId,
2228+
pub owner_id: OwnerId,
22292229
pub generics: &'hir Generics<'hir>,
22302230
pub kind: TraitItemKind<'hir>,
22312231
pub span: Span,
@@ -2236,11 +2236,11 @@ impl TraitItem<'_> {
22362236
#[inline]
22372237
pub fn hir_id(&self) -> HirId {
22382238
// Items are always HIR owners.
2239-
HirId::make_owner(self.def_id.def_id)
2239+
HirId::make_owner(self.owner_id.def_id)
22402240
}
22412241

22422242
pub fn trait_item_id(&self) -> TraitItemId {
2243-
TraitItemId { def_id: self.def_id }
2243+
TraitItemId { owner_id: self.owner_id }
22442244
}
22452245
}
22462246

@@ -2271,22 +2271,22 @@ pub enum TraitItemKind<'hir> {
22712271
// so it can fetched later.
22722272
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
22732273
pub struct ImplItemId {
2274-
pub def_id: OwnerId,
2274+
pub owner_id: OwnerId,
22752275
}
22762276

22772277
impl ImplItemId {
22782278
#[inline]
22792279
pub fn hir_id(&self) -> HirId {
22802280
// Items are always HIR owners.
2281-
HirId::make_owner(self.def_id.def_id)
2281+
HirId::make_owner(self.owner_id.def_id)
22822282
}
22832283
}
22842284

22852285
/// Represents anything within an `impl` block.
22862286
#[derive(Debug, HashStable_Generic)]
22872287
pub struct ImplItem<'hir> {
22882288
pub ident: Ident,
2289-
pub def_id: OwnerId,
2289+
pub owner_id: OwnerId,
22902290
pub generics: &'hir Generics<'hir>,
22912291
pub kind: ImplItemKind<'hir>,
22922292
pub defaultness: Defaultness,
@@ -2298,11 +2298,11 @@ impl ImplItem<'_> {
22982298
#[inline]
22992299
pub fn hir_id(&self) -> HirId {
23002300
// Items are always HIR owners.
2301-
HirId::make_owner(self.def_id.def_id)
2301+
HirId::make_owner(self.owner_id.def_id)
23022302
}
23032303

23042304
pub fn impl_item_id(&self) -> ImplItemId {
2305-
ImplItemId { def_id: self.def_id }
2305+
ImplItemId { owner_id: self.owner_id }
23062306
}
23072307
}
23082308

@@ -2914,14 +2914,14 @@ impl<'hir> VariantData<'hir> {
29142914
// so it can fetched later.
29152915
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
29162916
pub struct ItemId {
2917-
pub def_id: OwnerId,
2917+
pub owner_id: OwnerId,
29182918
}
29192919

29202920
impl ItemId {
29212921
#[inline]
29222922
pub fn hir_id(&self) -> HirId {
29232923
// Items are always HIR owners.
2924-
HirId::make_owner(self.def_id.def_id)
2924+
HirId::make_owner(self.owner_id.def_id)
29252925
}
29262926
}
29272927

@@ -2931,7 +2931,7 @@ impl ItemId {
29312931
#[derive(Debug, HashStable_Generic)]
29322932
pub struct Item<'hir> {
29332933
pub ident: Ident,
2934-
pub def_id: OwnerId,
2934+
pub owner_id: OwnerId,
29352935
pub kind: ItemKind<'hir>,
29362936
pub span: Span,
29372937
pub vis_span: Span,
@@ -2941,11 +2941,11 @@ impl Item<'_> {
29412941
#[inline]
29422942
pub fn hir_id(&self) -> HirId {
29432943
// Items are always HIR owners.
2944-
HirId::make_owner(self.def_id.def_id)
2944+
HirId::make_owner(self.owner_id.def_id)
29452945
}
29462946

29472947
pub fn item_id(&self) -> ItemId {
2948-
ItemId { def_id: self.def_id }
2948+
ItemId { owner_id: self.owner_id }
29492949
}
29502950
}
29512951

@@ -3158,14 +3158,14 @@ pub enum AssocItemKind {
31583158
// so it can fetched later.
31593159
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
31603160
pub struct ForeignItemId {
3161-
pub def_id: OwnerId,
3161+
pub owner_id: OwnerId,
31623162
}
31633163

31643164
impl ForeignItemId {
31653165
#[inline]
31663166
pub fn hir_id(&self) -> HirId {
31673167
// Items are always HIR owners.
3168-
HirId::make_owner(self.def_id.def_id)
3168+
HirId::make_owner(self.owner_id.def_id)
31693169
}
31703170
}
31713171

@@ -3186,7 +3186,7 @@ pub struct ForeignItemRef {
31863186
pub struct ForeignItem<'hir> {
31873187
pub ident: Ident,
31883188
pub kind: ForeignItemKind<'hir>,
3189-
pub def_id: OwnerId,
3189+
pub owner_id: OwnerId,
31903190
pub span: Span,
31913191
pub vis_span: Span,
31923192
}
@@ -3195,11 +3195,11 @@ impl ForeignItem<'_> {
31953195
#[inline]
31963196
pub fn hir_id(&self) -> HirId {
31973197
// Items are always HIR owners.
3198-
HirId::make_owner(self.def_id.def_id)
3198+
HirId::make_owner(self.owner_id.def_id)
31993199
}
32003200

32013201
pub fn foreign_item_id(&self) -> ForeignItemId {
3202-
ForeignItemId { def_id: self.def_id }
3202+
ForeignItemId { owner_id: self.owner_id }
32033203
}
32043204
}
32053205

@@ -3291,10 +3291,10 @@ impl<'hir> OwnerNode<'hir> {
32913291

32923292
pub fn def_id(self) -> OwnerId {
32933293
match self {
3294-
OwnerNode::Item(Item { def_id, .. })
3295-
| OwnerNode::TraitItem(TraitItem { def_id, .. })
3296-
| OwnerNode::ImplItem(ImplItem { def_id, .. })
3297-
| OwnerNode::ForeignItem(ForeignItem { def_id, .. }) => *def_id,
3294+
OwnerNode::Item(Item { owner_id, .. })
3295+
| OwnerNode::TraitItem(TraitItem { owner_id, .. })
3296+
| OwnerNode::ImplItem(ImplItem { owner_id, .. })
3297+
| OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id,
32983298
OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner,
32993299
}
33003300
}

‎compiler/rustc_hir/src/intravisit.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(
912912

913913
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) {
914914
// N.B., deliberately force a compilation error if/when new fields are added.
915-
let TraitItem { ident, generics, ref defaultness, ref kind, span, def_id: _ } = *trait_item;
915+
let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item;
916916
let hir_id = trait_item.hir_id();
917917
visitor.visit_ident(ident);
918918
visitor.visit_generics(&generics);
@@ -952,7 +952,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
952952
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
953953
// N.B., deliberately force a compilation error if/when new fields are added.
954954
let ImplItem {
955-
def_id: _,
955+
owner_id: _,
956956
ident,
957957
ref generics,
958958
ref kind,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /