Rename HIR TypeBinding
to AssocItemConstraint
and related cleanup
This commit is contained in:
parent
0a59f11362
commit
34c56c45cf
108 changed files with 878 additions and 818 deletions
|
@ -167,7 +167,7 @@ impl PathSegment {
|
|||
}
|
||||
}
|
||||
|
||||
/// The arguments of a path segment.
|
||||
/// The generic arguments and associated item constraints of a path segment.
|
||||
///
|
||||
/// E.g., `<A, B>` as in `Foo<A, B>` or `(A, B)` as in `Foo(A, B)`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
|
@ -221,14 +221,13 @@ pub struct AngleBracketedArgs {
|
|||
pub args: ThinVec<AngleBracketedArg>,
|
||||
}
|
||||
|
||||
/// Either an argument for a parameter e.g., `'a`, `Vec<u8>`, `0`,
|
||||
/// or a constraint on an associated item, e.g., `Item = String` or `Item: Bound`.
|
||||
/// Either an argument for a generic parameter or a constraint on an associated item.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum AngleBracketedArg {
|
||||
/// Argument for a generic parameter.
|
||||
/// A generic argument for a generic parameter.
|
||||
Arg(GenericArg),
|
||||
/// Constraint for an associated item.
|
||||
Constraint(AssocConstraint),
|
||||
/// A constraint on an associated item.
|
||||
Constraint(AssocItemConstraint),
|
||||
}
|
||||
|
||||
impl AngleBracketedArg {
|
||||
|
@ -418,7 +417,7 @@ impl Default for WhereClause {
|
|||
/// A single predicate in a where-clause.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum WherePredicate {
|
||||
/// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`).
|
||||
/// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
|
||||
BoundPredicate(WhereBoundPredicate),
|
||||
/// A lifetime predicate (e.g., `'a: 'b + 'c`).
|
||||
RegionPredicate(WhereRegionPredicate),
|
||||
|
@ -2034,18 +2033,25 @@ impl UintTy {
|
|||
}
|
||||
}
|
||||
|
||||
/// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
|
||||
/// `A: TraitA + TraitB` in `Foo<A: TraitA + TraitB>`).
|
||||
/// A constraint on an associated item.
|
||||
///
|
||||
/// ### Examples
|
||||
///
|
||||
/// * the `A = Ty` and `B = Ty` in `Trait<A = Ty, B = Ty>`
|
||||
/// * the `G<Ty> = Ty` in `Trait<G<Ty> = Ty>`
|
||||
/// * the `A: Bound` in `Trait<A: Bound>`
|
||||
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
|
||||
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
|
||||
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct AssocConstraint {
|
||||
pub struct AssocItemConstraint {
|
||||
pub id: NodeId,
|
||||
pub ident: Ident,
|
||||
pub gen_args: Option<GenericArgs>,
|
||||
pub kind: AssocConstraintKind,
|
||||
pub kind: AssocItemConstraintKind,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// The kinds of an `AssocConstraint`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum Term {
|
||||
Ty(P<Ty>),
|
||||
|
@ -2064,12 +2070,17 @@ impl From<AnonConst> for Term {
|
|||
}
|
||||
}
|
||||
|
||||
/// The kinds of an `AssocConstraint`.
|
||||
/// The kind of [associated item constraint][AssocItemConstraint].
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum AssocConstraintKind {
|
||||
/// E.g., `A = Bar`, `A = 3` in `Foo<A = Bar>` where A is an associated type.
|
||||
pub enum AssocItemConstraintKind {
|
||||
/// An equality constraint for an associated item (e.g., `AssocTy = Ty` in `Trait<AssocTy = Ty>`).
|
||||
///
|
||||
/// Also known as an *associated item binding* (we *bind* an associated item to a term).
|
||||
///
|
||||
/// Furthermore, associated type equality constraints can also be referred to as *associated type
|
||||
/// bindings*. Similarly with associated const equality constraints and *associated const bindings*.
|
||||
Equality { term: Term },
|
||||
/// E.g. `A: TraitA + TraitB` in `Foo<A: TraitA + TraitB>`.
|
||||
/// A bound on an associated type (e.g., `AssocTy: Bound` in `Trait<AssocTy: Bound>`).
|
||||
Bound { bounds: GenericBounds },
|
||||
}
|
||||
|
||||
|
|
|
@ -175,8 +175,8 @@ pub trait MutVisitor: Sized {
|
|||
noop_visit_lifetime(l, self);
|
||||
}
|
||||
|
||||
fn visit_constraint(&mut self, t: &mut AssocConstraint) {
|
||||
noop_visit_constraint(t, self);
|
||||
fn visit_assoc_item_constraint(&mut self, c: &mut AssocItemConstraint) {
|
||||
noop_visit_assoc_item_constraint(c, self);
|
||||
}
|
||||
|
||||
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<[
|
|||
smallvec![arm]
|
||||
}
|
||||
|
||||
fn noop_visit_constraint<T: MutVisitor>(
|
||||
AssocConstraint { id, ident, gen_args, kind, span }: &mut AssocConstraint,
|
||||
fn noop_visit_assoc_item_constraint<T: MutVisitor>(
|
||||
AssocItemConstraint { id, ident, gen_args, kind, span }: &mut AssocItemConstraint,
|
||||
vis: &mut T,
|
||||
) {
|
||||
vis.visit_id(id);
|
||||
|
@ -473,11 +473,11 @@ fn noop_visit_constraint<T: MutVisitor>(
|
|||
vis.visit_generic_args(gen_args);
|
||||
}
|
||||
match kind {
|
||||
AssocConstraintKind::Equality { term } => match term {
|
||||
AssocItemConstraintKind::Equality { term } => match term {
|
||||
Term::Ty(ty) => vis.visit_ty(ty),
|
||||
Term::Const(c) => vis.visit_anon_const(c),
|
||||
},
|
||||
AssocConstraintKind::Bound { bounds } => visit_bounds(bounds, vis),
|
||||
AssocItemConstraintKind::Bound { bounds } => visit_bounds(bounds, vis),
|
||||
}
|
||||
vis.visit_span(span);
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ fn noop_visit_angle_bracketed_parameter_data<T: MutVisitor>(
|
|||
let AngleBracketedArgs { args, span } = data;
|
||||
visit_thin_vec(args, |arg| match arg {
|
||||
AngleBracketedArg::Arg(arg) => vis.visit_generic_arg(arg),
|
||||
AngleBracketedArg::Constraint(constraint) => vis.visit_constraint(constraint),
|
||||
AngleBracketedArg::Constraint(constraint) => vis.visit_assoc_item_constraint(constraint),
|
||||
});
|
||||
vis.visit_span(span);
|
||||
}
|
||||
|
|
|
@ -246,8 +246,11 @@ pub trait Visitor<'ast>: Sized {
|
|||
fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) -> Self::Result {
|
||||
walk_generic_arg(self, generic_arg)
|
||||
}
|
||||
fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) -> Self::Result {
|
||||
walk_assoc_constraint(self, constraint)
|
||||
fn visit_assoc_item_constraint(
|
||||
&mut self,
|
||||
constraint: &'ast AssocItemConstraint,
|
||||
) -> Self::Result {
|
||||
walk_assoc_item_constraint(self, constraint)
|
||||
}
|
||||
fn visit_attribute(&mut self, attr: &'ast Attribute) -> Self::Result {
|
||||
walk_attribute(self, attr)
|
||||
|
@ -558,7 +561,7 @@ where
|
|||
match arg {
|
||||
AngleBracketedArg::Arg(a) => try_visit!(visitor.visit_generic_arg(a)),
|
||||
AngleBracketedArg::Constraint(c) => {
|
||||
try_visit!(visitor.visit_assoc_constraint(c))
|
||||
try_visit!(visitor.visit_assoc_item_constraint(c))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -582,18 +585,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(
|
||||
pub fn walk_assoc_item_constraint<'a, V: Visitor<'a>>(
|
||||
visitor: &mut V,
|
||||
constraint: &'a AssocConstraint,
|
||||
constraint: &'a AssocItemConstraint,
|
||||
) -> V::Result {
|
||||
try_visit!(visitor.visit_ident(constraint.ident));
|
||||
visit_opt!(visitor, visit_generic_args, &constraint.gen_args);
|
||||
match &constraint.kind {
|
||||
AssocConstraintKind::Equality { term } => match term {
|
||||
AssocItemConstraintKind::Equality { term } => match term {
|
||||
Term::Ty(ty) => try_visit!(visitor.visit_ty(ty)),
|
||||
Term::Const(c) => try_visit!(visitor.visit_anon_const(c)),
|
||||
},
|
||||
AssocConstraintKind::Bound { bounds } => {
|
||||
AssocItemConstraintKind::Bound { bounds } => {
|
||||
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue