diff options
| author | Jack Huey <31162821+jackh726@users.noreply.github.com> | 2021-10-19 18:45:48 -0400 |
|---|---|---|
| committer | Jack Huey <31162821+jackh726@users.noreply.github.com> | 2022-03-05 13:13:45 -0500 |
| commit | c20b4f558440c24e8ef84782a71163fe236d72de (patch) | |
| tree | 6e09aa43d0f3eb54043950a2d89e237f23dde41e /compiler/rustc_ast | |
| parent | 379e94f5a4aebe7dc2d8742653ca244d92b06f3d (diff) | |
| download | rust-c20b4f558440c24e8ef84782a71163fe236d72de.tar.gz rust-c20b4f558440c24e8ef84782a71163fe236d72de.zip | |
Change syntax for TyAlias where clauses
Diffstat (limited to 'compiler/rustc_ast')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 28 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/visit.rs | 6 |
3 files changed, 41 insertions, 6 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 725499e5c78..2fbafca1681 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2662,10 +2662,23 @@ pub struct Trait { pub items: Vec<P<AssocItem>>, } +/// The location of a where clause on a `TyAlias` (`Span`) and whether there was +/// a `where` keyword (`bool`). This is split out from `WhereClause`, since there +/// are two locations for where clause on type aliases, but their predicates +/// are concatenated together. +#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)] +pub struct TyAliasWhereClause(pub bool, pub Span); + #[derive(Clone, Encodable, Decodable, Debug)] pub struct TyAlias { pub defaultness: Defaultness, pub generics: Generics, + /// The span information for the two where clauses (before equals, after equals) + pub where_clauses: (TyAliasWhereClause, TyAliasWhereClause), + /// The index in `generics.where_clause.predicates` that would split into + /// predicates from the where clause before the equals and the predicates + /// from the where clause after the equals + pub where_predicates_split: usize, pub bounds: GenericBounds, pub ty: Option<P<Ty>>, } diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index a81a2276295..c60c77e6987 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1018,9 +1018,13 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) { } ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm), ItemKind::GlobalAsm(asm) => noop_visit_inline_asm(asm, vis), - ItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => { + ItemKind::TyAlias(box TyAlias { + defaultness, generics, where_clauses, bounds, ty, .. + }) => { visit_defaultness(defaultness, vis); vis.visit_generics(generics); + vis.visit_span(&mut where_clauses.0.1); + vis.visit_span(&mut where_clauses.1.1); visit_bounds(bounds, vis); visit_opt(ty, |ty| vis.visit_ty(ty)); } @@ -1087,9 +1091,18 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>( visit_fn_sig(sig, visitor); visit_opt(body, |body| visitor.visit_block(body)); } - AssocItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => { + AssocItemKind::TyAlias(box TyAlias { + defaultness, + generics, + where_clauses, + bounds, + ty, + .. + }) => { visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); + visitor.visit_span(&mut where_clauses.0.1); + visitor.visit_span(&mut where_clauses.1.1); visit_bounds(bounds, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); } @@ -1152,9 +1165,18 @@ pub fn noop_flat_map_foreign_item<T: MutVisitor>( visit_fn_sig(sig, visitor); visit_opt(body, |body| visitor.visit_block(body)); } - ForeignItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => { + ForeignItemKind::TyAlias(box TyAlias { + defaultness, + generics, + where_clauses, + bounds, + ty, + .. + }) => { visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); + visitor.visit_span(&mut where_clauses.0.1); + visitor.visit_span(&mut where_clauses.1.1); visit_bounds(bounds, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 73e9297549c..ed16c25d921 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -303,7 +303,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { walk_list!(visitor, visit_foreign_item, &foreign_module.items); } ItemKind::GlobalAsm(ref asm) => walk_inline_asm(visitor, asm), - ItemKind::TyAlias(box TyAlias { defaultness: _, ref generics, ref bounds, ref ty }) => { + ItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) => { visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, ty); @@ -559,7 +559,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, body.as_deref()); visitor.visit_fn(kind, span, id); } - ForeignItemKind::TyAlias(box TyAlias { defaultness: _, generics, bounds, ty }) => { + ForeignItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => { visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, ty); @@ -665,7 +665,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, body.as_deref()); visitor.visit_fn(kind, span, id); } - AssocItemKind::TyAlias(box TyAlias { defaultness: _, generics, bounds, ty }) => { + AssocItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => { visitor.visit_generics(generics); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, ty); |
