Skip to content

Commit 2737bcf

Browse files
committed
WIP
1 parent d365e9c commit 2737bcf

File tree

20 files changed

+112
-178
lines changed

20 files changed

+112
-178
lines changed

compiler/rustc_ast/src/ast.rs

+13-29
Original file line numberDiff line numberDiff line change
@@ -2950,8 +2950,7 @@ impl Item {
29502950
| ItemKind::GlobalAsm(_)
29512951
| ItemKind::MacCall(_)
29522952
| ItemKind::Delegation(_)
2953-
| ItemKind::DelegationList(_)
2954-
| ItemKind::DelegationGlob(_)
2953+
| ItemKind::DelegationMac(_)
29552954
| ItemKind::MacroDef(_) => None,
29562955
ItemKind::Static(_) => None,
29572956
ItemKind::Const(i) => Some(&i.generics),
@@ -3120,17 +3119,11 @@ pub struct Delegation {
31203119
}
31213120

31223121
#[derive(Clone, Encodable, Decodable, Debug)]
3123-
pub struct DelegationList {
3124-
pub qself: Option<P<QSelf>>,
3125-
pub prefix: Path,
3126-
pub suffixes: ThinVec<Ident>,
3127-
pub body: Option<P<Block>>,
3128-
}
3129-
3130-
#[derive(Clone, Encodable, Decodable, Debug)]
3131-
pub struct DelegationGlob {
3122+
pub struct DelegationMac {
31323123
pub qself: Option<P<QSelf>>,
31333124
pub prefix: Path,
3125+
// Some for list delegation, and None for glob delegation
3126+
pub suffixes: Option<ThinVec<Ident>>,
31343127
pub body: Option<P<Block>>,
31353128
}
31363129

@@ -3224,12 +3217,9 @@ pub enum ItemKind {
32243217
///
32253218
/// E.g. `reuse <Type as Trait>::name { target_expr_template }`.
32263219
Delegation(Box<Delegation>),
3227-
/// A list delegation item (`reuse prefix::{a, b, c}`).
3228-
/// Treated similarly to a macro call and expanded early.
3229-
DelegationList(Box<DelegationList>),
3230-
/// A glob delegation item (`reuse prefix::*`).
3220+
/// A list or glob delegation item (`reuse prefix::{a, b, c}`, `reuse prefix::*`).
32313221
/// Treated similarly to a macro call and expanded early.
3232-
DelegationGlob(Box<DelegationGlob>),
3222+
DelegationMac(Box<DelegationMac>),
32333223
}
32343224

32353225
impl ItemKind {
@@ -3238,7 +3228,7 @@ impl ItemKind {
32383228
match self {
32393229
Use(..) | Static(..) | Const(..) | Fn(..) | Mod(..) | GlobalAsm(..) | TyAlias(..)
32403230
| Struct(..) | Union(..) | Trait(..) | TraitAlias(..) | MacroDef(..)
3241-
| Delegation(..) | DelegationList(..) | DelegationGlob(..) => "a",
3231+
| Delegation(..) | DelegationMac(..) => "a",
32423232
ExternCrate(..) | ForeignMod(..) | MacCall(..) | Enum(..) | Impl { .. } => "an",
32433233
}
32443234
}
@@ -3263,8 +3253,7 @@ impl ItemKind {
32633253
ItemKind::MacroDef(..) => "macro definition",
32643254
ItemKind::Impl { .. } => "implementation",
32653255
ItemKind::Delegation(..) => "delegated function",
3266-
ItemKind::DelegationList(..) => "delegation list",
3267-
ItemKind::DelegationGlob(..) => "delegation glob",
3256+
ItemKind::DelegationMac(..) => "delegation",
32683257
}
32693258
}
32703259

@@ -3308,10 +3297,8 @@ pub enum AssocItemKind {
33083297
MacCall(P<MacCall>),
33093298
/// An associated delegation item.
33103299
Delegation(Box<Delegation>),
3311-
/// An associated delegation item list.
3312-
DelegationList(Box<DelegationList>),
3313-
/// An associated delegation item glob.
3314-
DelegationGlob(Box<DelegationGlob>),
3300+
/// An associated list or glob delegation item.
3301+
DelegationMac(Box<DelegationMac>),
33153302
}
33163303

33173304
impl AssocItemKind {
@@ -3322,8 +3309,7 @@ impl AssocItemKind {
33223309
| Self::Type(box TyAlias { defaultness, .. }) => defaultness,
33233310
Self::MacCall(..)
33243311
| Self::Delegation(..)
3325-
| Self::DelegationList(..)
3326-
| Self::DelegationGlob(..) => Defaultness::Final,
3312+
| Self::DelegationMac(..) => Defaultness::Final,
33273313
}
33283314
}
33293315
}
@@ -3336,8 +3322,7 @@ impl From<AssocItemKind> for ItemKind {
33363322
AssocItemKind::Type(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
33373323
AssocItemKind::MacCall(a) => ItemKind::MacCall(a),
33383324
AssocItemKind::Delegation(delegation) => ItemKind::Delegation(delegation),
3339-
AssocItemKind::DelegationList(delegation) => ItemKind::DelegationList(delegation),
3340-
AssocItemKind::DelegationGlob(delegation) => ItemKind::DelegationGlob(delegation),
3325+
AssocItemKind::DelegationMac(delegation) => ItemKind::DelegationMac(delegation),
33413326
}
33423327
}
33433328
}
@@ -3352,8 +3337,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
33523337
ItemKind::TyAlias(ty_kind) => AssocItemKind::Type(ty_kind),
33533338
ItemKind::MacCall(a) => AssocItemKind::MacCall(a),
33543339
ItemKind::Delegation(d) => AssocItemKind::Delegation(d),
3355-
ItemKind::DelegationList(d) => AssocItemKind::DelegationList(d),
3356-
ItemKind::DelegationGlob(d) => AssocItemKind::DelegationGlob(d),
3340+
ItemKind::DelegationMac(d) => AssocItemKind::DelegationMac(d),
33573341
_ => return Err(item_kind),
33583342
})
33593343
}

compiler/rustc_ast/src/mut_visit.rs

+10-21
Original file line numberDiff line numberDiff line change
@@ -1157,19 +1157,14 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
11571157
vis.visit_block(body);
11581158
}
11591159
}
1160-
ItemKind::DelegationList(box DelegationList { qself, prefix, suffixes, body }) => {
1160+
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
11611161
vis.visit_qself(qself);
11621162
vis.visit_path(prefix);
1163-
for ident in suffixes {
1164-
vis.visit_ident(ident);
1165-
}
1166-
if let Some(body) = body {
1167-
vis.visit_block(body);
1163+
if let Some(suffixes) = suffixes {
1164+
for ident in suffixes {
1165+
vis.visit_ident(ident);
1166+
}
11681167
}
1169-
}
1170-
ItemKind::DelegationGlob(box DelegationGlob { qself, prefix, body }) => {
1171-
vis.visit_qself(qself);
1172-
vis.visit_path(prefix);
11731168
if let Some(body) = body {
11741169
vis.visit_block(body);
11751170
}
@@ -1220,21 +1215,15 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
12201215
visitor.visit_block(body);
12211216
}
12221217
}
1223-
AssocItemKind::DelegationList(box DelegationList { qself, prefix, suffixes, body }) => {
1218+
AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
12241219
visitor.visit_id(id);
12251220
visitor.visit_qself(qself);
12261221
visitor.visit_path(prefix);
1227-
for ident in suffixes {
1228-
visitor.visit_ident(ident);
1229-
}
1230-
if let Some(body) = body {
1231-
visitor.visit_block(body);
1222+
if let Some(suffixes) = suffixes {
1223+
for ident in suffixes {
1224+
visitor.visit_ident(ident);
1225+
}
12321226
}
1233-
}
1234-
AssocItemKind::DelegationGlob(box DelegationGlob { qself, prefix, body }) => {
1235-
visitor.visit_id(id);
1236-
visitor.visit_qself(qself);
1237-
visitor.visit_path(prefix);
12381227
if let Some(body) = body {
12391228
visitor.visit_block(body);
12401229
}

compiler/rustc_ast/src/visit.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,16 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) -> V::Resu
389389
try_visit!(visitor.visit_path(path, *id));
390390
visit_opt!(visitor, visit_block, body);
391391
}
392-
ItemKind::DelegationList(box DelegationList { qself, prefix, suffixes, body }) => {
392+
ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
393393
if let Some(qself) = qself {
394394
try_visit!(visitor.visit_ty(&qself.ty));
395395
}
396396
try_visit!(visitor.visit_path(prefix, item.id));
397-
for suffix in suffixes {
398-
visitor.visit_ident(*suffix);
399-
}
400-
visit_opt!(visitor, visit_block, body);
401-
}
402-
ItemKind::DelegationGlob(box DelegationGlob { qself, prefix, body }) => {
403-
if let Some(qself) = qself {
404-
try_visit!(visitor.visit_ty(&qself.ty));
397+
if let Some(suffixes) = suffixes {
398+
for suffix in suffixes {
399+
visitor.visit_ident(*suffix);
400+
}
405401
}
406-
try_visit!(visitor.visit_path(prefix, item.id));
407402
visit_opt!(visitor, visit_block, body);
408403
}
409404
}
@@ -806,21 +801,16 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
806801
try_visit!(visitor.visit_path(path, *id));
807802
visit_opt!(visitor, visit_block, body);
808803
}
809-
AssocItemKind::DelegationList(box DelegationList { qself, prefix, suffixes, body }) => {
804+
AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
810805
if let Some(qself) = qself {
811806
try_visit!(visitor.visit_ty(&qself.ty));
812807
}
813808
try_visit!(visitor.visit_path(prefix, item.id));
814-
for suffix in suffixes {
815-
visitor.visit_ident(*suffix);
816-
}
817-
visit_opt!(visitor, visit_block, body);
818-
}
819-
AssocItemKind::DelegationGlob(box DelegationGlob { qself, prefix, body }) => {
820-
if let Some(qself) = qself {
821-
try_visit!(visitor.visit_ty(&qself.ty));
809+
if let Some(suffixes) = suffixes {
810+
for suffix in suffixes {
811+
visitor.visit_ident(*suffix);
812+
}
822813
}
823-
try_visit!(visitor.visit_path(prefix, item.id));
824814
visit_opt!(visitor, visit_block, body);
825815
}
826816
}

compiler/rustc_ast_lowering/src/item.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
459459
delegation_results.body_id,
460460
)
461461
}
462-
ItemKind::MacCall(..) | ItemKind::DelegationList(..) | ItemKind::DelegationGlob(..) => {
462+
ItemKind::MacCall(..) | ItemKind::DelegationMac(..) => {
463463
panic!("macros should have been expanded by now")
464464
}
465465
}
@@ -844,9 +844,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
844844
);
845845
(delegation_results.generics, item_kind, true)
846846
}
847-
AssocItemKind::MacCall(..)
848-
| AssocItemKind::DelegationList(..)
849-
| AssocItemKind::DelegationGlob(..) => {
847+
AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => {
850848
panic!("macro item shouldn't exist at this point")
851849
}
852850
};
@@ -872,9 +870,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
872870
AssocItemKind::Delegation(box delegation) => hir::AssocItemKind::Fn {
873871
has_self: self.delegation_has_self(i.id, delegation.id, i.span),
874872
},
875-
AssocItemKind::MacCall(..)
876-
| AssocItemKind::DelegationList(..)
877-
| AssocItemKind::DelegationGlob(..) => unreachable!(),
873+
AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => unreachable!(),
878874
};
879875
let id = hir::TraitItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } };
880876
hir::TraitItemRef {
@@ -969,9 +965,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
969965
hir::ImplItemKind::Fn(delegation_results.sig, delegation_results.body_id),
970966
)
971967
}
972-
AssocItemKind::MacCall(..)
973-
| AssocItemKind::DelegationList(..)
974-
| AssocItemKind::DelegationGlob(..) => {
968+
AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => {
975969
panic!("macros should have been expanded by now")
976970
}
977971
};
@@ -1002,9 +996,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1002996
AssocItemKind::Delegation(box delegation) => hir::AssocItemKind::Fn {
1003997
has_self: self.delegation_has_self(i.id, delegation.id, i.span),
1004998
},
1005-
AssocItemKind::MacCall(..)
1006-
| AssocItemKind::DelegationList(..)
1007-
| AssocItemKind::DelegationGlob(..) => unreachable!(),
999+
AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => unreachable!(),
10081000
},
10091001
trait_item_def_id: self
10101002
.resolver

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -386,20 +386,12 @@ impl<'a> State<'a> {
386386
DelegationKind::Single,
387387
&deleg.body,
388388
),
389-
ast::ItemKind::DelegationList(deleg) => self.print_delegation(
389+
ast::ItemKind::DelegationMac(deleg) => self.print_delegation(
390390
&item.attrs,
391391
&item.vis,
392392
&deleg.qself,
393393
&deleg.prefix,
394-
DelegationKind::List(&deleg.suffixes),
395-
&deleg.body,
396-
),
397-
ast::ItemKind::DelegationGlob(deleg) => self.print_delegation(
398-
&item.attrs,
399-
&item.vis,
400-
&deleg.qself,
401-
&deleg.prefix,
402-
DelegationKind::Glob,
394+
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
403395
&deleg.body,
404396
),
405397
}
@@ -586,20 +578,12 @@ impl<'a> State<'a> {
586578
DelegationKind::Single,
587579
&deleg.body,
588580
),
589-
ast::AssocItemKind::DelegationList(deleg) => self.print_delegation(
590-
&item.attrs,
591-
vis,
592-
&deleg.qself,
593-
&deleg.prefix,
594-
DelegationKind::List(&deleg.suffixes),
595-
&deleg.body,
596-
),
597-
ast::AssocItemKind::DelegationGlob(deleg) => self.print_delegation(
581+
ast::AssocItemKind::DelegationMac(deleg) => self.print_delegation(
598582
&item.attrs,
599583
vis,
600584
&deleg.qself,
601585
&deleg.prefix,
602-
DelegationKind::Glob,
586+
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
603587
&deleg.body,
604588
),
605589
}

0 commit comments

Comments
 (0)