Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad0d1d7

Browse files
committedMar 6, 2022
Auto merge of rust-lang#90076 - jackh726:wherethewhere, r=nikomatsakis
Change location of where clause on GATs Closes rust-lang#89122 ~Blocked on lang FCP~ r? `@nikomatsakis`
2 parents 5d9d1e8 + d16ec7b commit ad0d1d7

Some content is hidden

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

52 files changed

+552
-283
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,10 +2662,37 @@ pub struct Trait {
26622662
pub items: Vec<P<AssocItem>>,
26632663
}
26642664

2665+
/// The location of a where clause on a `TyAlias` (`Span`) and whether there was
2666+
/// a `where` keyword (`bool`). This is split out from `WhereClause`, since there
2667+
/// are two locations for where clause on type aliases, but their predicates
2668+
/// are concatenated together.
2669+
///
2670+
/// Take this example:
2671+
/// ```ignore (only-for-syntax-highlight)
2672+
/// trait Foo {
2673+
/// type Assoc<'a, 'b> where Self: 'a, Self: 'b;
2674+
/// }
2675+
/// impl Foo for () {
2676+
/// type Assoc<'a, 'b> where Self: 'a = () where Self: 'b;
2677+
/// // ^^^^^^^^^^^^^^ first where clause
2678+
/// // ^^^^^^^^^^^^^^ second where clause
2679+
/// }
2680+
/// ```
2681+
///
2682+
/// If there is no where clause, then this is `false` with `DUMMY_SP`.
2683+
#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)]
2684+
pub struct TyAliasWhereClause(pub bool, pub Span);
2685+
26652686
#[derive(Clone, Encodable, Decodable, Debug)]
26662687
pub struct TyAlias {
26672688
pub defaultness: Defaultness,
26682689
pub generics: Generics,
2690+
/// The span information for the two where clauses (before equals, after equals)
2691+
pub where_clauses: (TyAliasWhereClause, TyAliasWhereClause),
2692+
/// The index in `generics.where_clause.predicates` that would split into
2693+
/// predicates from the where clause before the equals and the predicates
2694+
/// from the where clause after the equals
2695+
pub where_predicates_split: usize,
26692696
pub bounds: GenericBounds,
26702697
pub ty: Option<P<Ty>>,
26712698
}

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,13 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10181018
}
10191019
ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm),
10201020
ItemKind::GlobalAsm(asm) => noop_visit_inline_asm(asm, vis),
1021-
ItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => {
1021+
ItemKind::TyAlias(box TyAlias {
1022+
defaultness, generics, where_clauses, bounds, ty, ..
1023+
}) => {
10221024
visit_defaultness(defaultness, vis);
10231025
vis.visit_generics(generics);
1026+
vis.visit_span(&mut where_clauses.0.1);
1027+
vis.visit_span(&mut where_clauses.1.1);
10241028
visit_bounds(bounds, vis);
10251029
visit_opt(ty, |ty| vis.visit_ty(ty));
10261030
}
@@ -1087,9 +1091,18 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
10871091
visit_fn_sig(sig, visitor);
10881092
visit_opt(body, |body| visitor.visit_block(body));
10891093
}
1090-
AssocItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => {
1094+
AssocItemKind::TyAlias(box TyAlias {
1095+
defaultness,
1096+
generics,
1097+
where_clauses,
1098+
bounds,
1099+
ty,
1100+
..
1101+
}) => {
10911102
visit_defaultness(defaultness, visitor);
10921103
visitor.visit_generics(generics);
1104+
visitor.visit_span(&mut where_clauses.0.1);
1105+
visitor.visit_span(&mut where_clauses.1.1);
10931106
visit_bounds(bounds, visitor);
10941107
visit_opt(ty, |ty| visitor.visit_ty(ty));
10951108
}
@@ -1152,9 +1165,18 @@ pub fn noop_flat_map_foreign_item<T: MutVisitor>(
11521165
visit_fn_sig(sig, visitor);
11531166
visit_opt(body, |body| visitor.visit_block(body));
11541167
}
1155-
ForeignItemKind::TyAlias(box TyAlias { defaultness, generics, bounds, ty }) => {
1168+
ForeignItemKind::TyAlias(box TyAlias {
1169+
defaultness,
1170+
generics,
1171+
where_clauses,
1172+
bounds,
1173+
ty,
1174+
..
1175+
}) => {
11561176
visit_defaultness(defaultness, visitor);
11571177
visitor.visit_generics(generics);
1178+
visitor.visit_span(&mut where_clauses.0.1);
1179+
visitor.visit_span(&mut where_clauses.1.1);
11581180
visit_bounds(bounds, visitor);
11591181
visit_opt(ty, |ty| visitor.visit_ty(ty));
11601182
}

0 commit comments

Comments
 (0)
This repository has been archived.