Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 68bc049

Browse files
committedMay 28, 2024
Rename HIR TypeBinding to AssocItemConstraint and related cleanup
1 parent 0a59f11 commit 68bc049

File tree

103 files changed

+808
-754
lines changed

Some content is hidden

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

103 files changed

+808
-754
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl PathSegment {
167167
}
168168
}
169169

170-
/// The arguments of a path segment.
170+
/// The generic arguments and associated item constraints on a path segment.
171171
///
172172
/// E.g., `<A, B>` as in `Foo<A, B>` or `(A, B)` as in `Foo(A, B)`.
173173
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -221,14 +221,13 @@ pub struct AngleBracketedArgs {
221221
pub args: ThinVec<AngleBracketedArg>,
222222
}
223223

224-
/// Either an argument for a parameter e.g., `'a`, `Vec<u8>`, `0`,
225-
/// or a constraint on an associated item, e.g., `Item = String` or `Item: Bound`.
224+
/// Either an argument for a generic parameter or a constraint on an associated item.
226225
#[derive(Clone, Encodable, Decodable, Debug)]
227226
pub enum AngleBracketedArg {
228-
/// Argument for a generic parameter.
227+
/// A generic argument for a generic parameter.
229228
Arg(GenericArg),
230-
/// Constraint for an associated item.
231-
Constraint(AssocConstraint),
229+
/// A constraint on an associated item.
230+
Constraint(AssocItemConstraint),
232231
}
233232

234233
impl AngleBracketedArg {
@@ -418,7 +417,7 @@ impl Default for WhereClause {
418417
/// A single predicate in a where-clause.
419418
#[derive(Clone, Encodable, Decodable, Debug)]
420419
pub enum WherePredicate {
421-
/// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`).
420+
/// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
422421
BoundPredicate(WhereBoundPredicate),
423422
/// A lifetime predicate (e.g., `'a: 'b + 'c`).
424423
RegionPredicate(WhereRegionPredicate),
@@ -2034,18 +2033,25 @@ impl UintTy {
20342033
}
20352034
}
20362035

2037-
/// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
2038-
/// `A: TraitA + TraitB` in `Foo<A: TraitA + TraitB>`).
2039-
#[derive(Clone, Encodable, Decodable, Debug)]
2040-
pub struct AssocConstraint {
2036+
/// A constraint on an associated item.
2037+
///
2038+
/// ### Examples
2039+
///
2040+
/// * the `A = Ty` and `B = Ty` in `Trait<A = Ty, B = Ty>`
2041+
/// * the `G<Ty> = Ty` in `Trait<G<Ty> = Ty>`
2042+
/// * the `A: Bound` in `Trait<A: Bound>`
2043+
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
2044+
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
2045+
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
2046+
#[derive(Clone, Encodable, Decodable, Debug)]
2047+
pub struct AssocItemConstraint {
20412048
pub id: NodeId,
20422049
pub ident: Ident,
20432050
pub gen_args: Option<GenericArgs>,
2044-
pub kind: AssocConstraintKind,
2051+
pub kind: AssocItemConstraintKind,
20452052
pub span: Span,
20462053
}
20472054

2048-
/// The kinds of an `AssocConstraint`.
20492055
#[derive(Clone, Encodable, Decodable, Debug)]
20502056
pub enum Term {
20512057
Ty(P<Ty>),
@@ -2064,12 +2070,17 @@ impl From<AnonConst> for Term {
20642070
}
20652071
}
20662072

2067-
/// The kinds of an `AssocConstraint`.
2073+
/// The kind of [associated item constraint][AssocItemConstraint].
20682074
#[derive(Clone, Encodable, Decodable, Debug)]
2069-
pub enum AssocConstraintKind {
2070-
/// E.g., `A = Bar`, `A = 3` in `Foo<A = Bar>` where A is an associated type.
2075+
pub enum AssocItemConstraintKind {
2076+
/// An equality constraint for an associated item (e.g., `AssocTy = Ty` in `Trait<AssocTy = Ty>`).
2077+
///
2078+
/// Also known as an *associated item binding* (we *bind* an associated item to a term).
2079+
///
2080+
/// Furthermore, associated type equality constraints can also be referred to as *associated type
2081+
/// bindings*. Similarly with associated const equality constraints and *associated const bindings*.
20712082
Equality { term: Term },
2072-
/// E.g. `A: TraitA + TraitB` in `Foo<A: TraitA + TraitB>`.
2083+
/// A bound on an associated type (e.g., `AssocTy: Bound` in `Trait<AssocTy: Bound>`).
20732084
Bound { bounds: GenericBounds },
20742085
}
20752086

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ pub trait MutVisitor: Sized {
175175
noop_visit_lifetime(l, self);
176176
}
177177

178-
fn visit_constraint(&mut self, t: &mut AssocConstraint) {
179-
noop_visit_constraint(t, self);
178+
fn visit_assoc_item_constraint(&mut self, c: &mut AssocItemConstraint) {
179+
noop_visit_assoc_item_constraint(c, self);
180180
}
181181

182182
fn visit_foreign_mod(&mut self, nm: &mut ForeignMod) {
@@ -463,8 +463,8 @@ pub fn noop_flat_map_arm<T: MutVisitor>(mut arm: Arm, vis: &mut T) -> SmallVec<[
463463
smallvec![arm]
464464
}
465465

466-
fn noop_visit_constraint<T: MutVisitor>(
467-
AssocConstraint { id, ident, gen_args, kind, span }: &mut AssocConstraint,
466+
fn noop_visit_assoc_item_constraint<T: MutVisitor>(
467+
AssocItemConstraint { id, ident, gen_args, kind, span }: &mut AssocItemConstraint,
468468
vis: &mut T,
469469
) {
470470
vis.visit_id(id);
@@ -473,11 +473,11 @@ fn noop_visit_constraint<T: MutVisitor>(
473473
vis.visit_generic_args(gen_args);
474474
}
475475
match kind {
476-
AssocConstraintKind::Equality { term } => match term {
476+
AssocItemConstraintKind::Equality { term } => match term {
477477
Term::Ty(ty) => vis.visit_ty(ty),
478478
Term::Const(c) => vis.visit_anon_const(c),
479479
},
480-
AssocConstraintKind::Bound { bounds } => visit_bounds(bounds, vis),
480+
AssocItemConstraintKind::Bound { bounds } => visit_bounds(bounds, vis),
481481
}
482482
vis.visit_span(span);
483483
}
@@ -607,7 +607,7 @@ fn noop_visit_angle_bracketed_parameter_data<T: MutVisitor>(
607607
let AngleBracketedArgs { args, span } = data;
608608
visit_thin_vec(args, |arg| match arg {
609609
AngleBracketedArg::Arg(arg) => vis.visit_generic_arg(arg),
610-
AngleBracketedArg::Constraint(constraint) => vis.visit_constraint(constraint),
610+
AngleBracketedArg::Constraint(constraint) => vis.visit_assoc_item_constraint(constraint),
611611
});
612612
vis.visit_span(span);
613613
}

0 commit comments

Comments
 (0)
Please sign in to comment.