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
|
@ -333,10 +333,10 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
});
|
||||
}
|
||||
|
||||
fn visit_assoc_type_binding(&mut self, type_binding: &'hir TypeBinding<'hir>) {
|
||||
self.insert(type_binding.span, type_binding.hir_id, Node::TypeBinding(type_binding));
|
||||
self.with_parent(type_binding.hir_id, |this| {
|
||||
intravisit::walk_assoc_type_binding(this, type_binding)
|
||||
fn visit_assoc_item_constraint(&mut self, constraint: &'hir AssocItemConstraint<'hir>) {
|
||||
self.insert(constraint.span, constraint.hir_id, Node::AssocItemConstraint(constraint));
|
||||
self.with_parent(constraint.hir_id, |this| {
|
||||
intravisit::walk_assoc_item_constraint(this, constraint)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -961,24 +961,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
DelimArgs { dspan: args.dspan, delim: args.delim, tokens: args.tokens.flattened() }
|
||||
}
|
||||
|
||||
/// Given an associated type constraint like one of these:
|
||||
///
|
||||
/// ```ignore (illustrative)
|
||||
/// T: Iterator<Item: Debug>
|
||||
/// ^^^^^^^^^^^
|
||||
/// T: Iterator<Item = Debug>
|
||||
/// ^^^^^^^^^^^^
|
||||
/// ```
|
||||
///
|
||||
/// returns a `hir::TypeBinding` representing `Item`.
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn lower_assoc_ty_constraint(
|
||||
/// Lower an associated item constraint.
|
||||
#[instrument(level = "debug", skip_all)]
|
||||
fn lower_assoc_item_constraint(
|
||||
&mut self,
|
||||
constraint: &AssocConstraint,
|
||||
constraint: &AssocItemConstraint,
|
||||
itctx: ImplTraitContext,
|
||||
) -> hir::TypeBinding<'hir> {
|
||||
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
|
||||
// lower generic arguments of identifier in constraint
|
||||
) -> hir::AssocItemConstraint<'hir> {
|
||||
debug!(?constraint, ?itctx);
|
||||
// Lower the generic arguments for the associated item.
|
||||
let gen_args = if let Some(gen_args) = &constraint.gen_args {
|
||||
let gen_args_ctor = match gen_args {
|
||||
GenericArgs::AngleBracketed(data) => {
|
||||
|
@ -994,7 +985,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
};
|
||||
GenericArgsCtor {
|
||||
args: Default::default(),
|
||||
bindings: &[],
|
||||
constraints: &[],
|
||||
parenthesized,
|
||||
span: data.inputs_span,
|
||||
}
|
||||
|
@ -1024,7 +1015,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
err.emit();
|
||||
GenericArgsCtor {
|
||||
args: Default::default(),
|
||||
bindings: &[],
|
||||
constraints: &[],
|
||||
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
|
||||
span: data.span,
|
||||
}
|
||||
|
@ -1046,14 +1037,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
self.arena.alloc(hir::GenericArgs::none())
|
||||
};
|
||||
let kind = match &constraint.kind {
|
||||
AssocConstraintKind::Equality { term } => {
|
||||
AssocItemConstraintKind::Equality { term } => {
|
||||
let term = match term {
|
||||
Term::Ty(ty) => self.lower_ty(ty, itctx).into(),
|
||||
Term::Const(c) => self.lower_anon_const(c).into(),
|
||||
};
|
||||
hir::TypeBindingKind::Equality { term }
|
||||
hir::AssocItemConstraintKind::Equality { term }
|
||||
}
|
||||
AssocConstraintKind::Bound { bounds } => {
|
||||
AssocItemConstraintKind::Bound { bounds } => {
|
||||
// Disallow ATB in dyn types
|
||||
if self.is_in_dyn_type {
|
||||
let suggestion = match itctx {
|
||||
|
@ -1077,18 +1068,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
});
|
||||
let err_ty =
|
||||
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
|
||||
hir::TypeBindingKind::Equality { term: err_ty.into() }
|
||||
hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
|
||||
} else {
|
||||
// Desugar `AssocTy: Bounds` into a type binding where the
|
||||
// Desugar `AssocTy: Bounds` into an assoc type binding where the
|
||||
// later desugars into a trait predicate.
|
||||
let bounds = self.lower_param_bounds(bounds, itctx);
|
||||
|
||||
hir::TypeBindingKind::Constraint { bounds }
|
||||
hir::AssocItemConstraintKind::Bound { bounds }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
hir::TypeBinding {
|
||||
hir::AssocItemConstraint {
|
||||
hir_id: self.lower_node_id(constraint.id),
|
||||
ident: self.lower_ident(constraint.ident),
|
||||
gen_args,
|
||||
|
@ -2008,7 +1999,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
|
||||
let bound_args = self.arena.alloc(hir::GenericArgs {
|
||||
args: &[],
|
||||
bindings: arena_vec![self; self.assoc_ty_binding(assoc_ty_name, opaque_ty_span, output_ty)],
|
||||
constraints: arena_vec![self; self.assoc_ty_binding(assoc_ty_name, opaque_ty_span, output_ty)],
|
||||
parenthesized: hir::GenericArgsParentheses::No,
|
||||
span_ext: DUMMY_SP,
|
||||
});
|
||||
|
@ -2581,10 +2572,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Helper struct for delayed construction of GenericArgs.
|
||||
/// Helper struct for the delayed construction of [`hir::GenericArgs`].
|
||||
struct GenericArgsCtor<'hir> {
|
||||
args: SmallVec<[hir::GenericArg<'hir>; 4]>,
|
||||
bindings: &'hir [hir::TypeBinding<'hir>],
|
||||
constraints: &'hir [hir::AssocItemConstraint<'hir>],
|
||||
parenthesized: hir::GenericArgsParentheses,
|
||||
span: Span,
|
||||
}
|
||||
|
@ -2664,14 +2655,14 @@ impl<'hir> GenericArgsCtor<'hir> {
|
|||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.args.is_empty()
|
||||
&& self.bindings.is_empty()
|
||||
&& self.constraints.is_empty()
|
||||
&& self.parenthesized == hir::GenericArgsParentheses::No
|
||||
}
|
||||
|
||||
fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
|
||||
let ga = hir::GenericArgs {
|
||||
args: this.arena.alloc_from_iter(self.args),
|
||||
bindings: self.bindings,
|
||||
constraints: self.constraints,
|
||||
parenthesized: self.parenthesized,
|
||||
span_ext: this.lower_span(self.span),
|
||||
};
|
||||
|
|
|
@ -281,7 +281,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
(
|
||||
GenericArgsCtor {
|
||||
args: Default::default(),
|
||||
bindings: &[],
|
||||
constraints: &[],
|
||||
parenthesized: hir::GenericArgsParentheses::No,
|
||||
span: path_span.shrink_to_hi(),
|
||||
},
|
||||
|
@ -390,13 +390,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
AngleBracketedArg::Constraint(_) => None,
|
||||
})
|
||||
.collect();
|
||||
let bindings = self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
|
||||
AngleBracketedArg::Constraint(c) => Some(self.lower_assoc_ty_constraint(c, itctx)),
|
||||
AngleBracketedArg::Arg(_) => None,
|
||||
}));
|
||||
let constraints =
|
||||
self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
|
||||
AngleBracketedArg::Constraint(c) => {
|
||||
Some(self.lower_assoc_item_constraint(c, itctx))
|
||||
}
|
||||
AngleBracketedArg::Arg(_) => None,
|
||||
}));
|
||||
let ctor = GenericArgsCtor {
|
||||
args,
|
||||
bindings,
|
||||
constraints,
|
||||
parenthesized: hir::GenericArgsParentheses::No,
|
||||
span: data.span,
|
||||
};
|
||||
|
@ -454,12 +457,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
Some(bound_modifier_allowed_features),
|
||||
);
|
||||
}
|
||||
let binding = self.assoc_ty_binding(sym::Output, output_span, output_ty);
|
||||
let constraint = self.assoc_ty_binding(sym::Output, output_span, output_ty);
|
||||
|
||||
(
|
||||
GenericArgsCtor {
|
||||
args,
|
||||
bindings: arena_vec![self; binding],
|
||||
constraints: arena_vec![self; constraint],
|
||||
parenthesized: hir::GenericArgsParentheses::ParenSugar,
|
||||
span: data.inputs_span,
|
||||
},
|
||||
|
@ -467,24 +470,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
)
|
||||
}
|
||||
|
||||
/// An associated type binding `$assoc_ty_name = $ty`.
|
||||
/// An associated type binding (i.e., associated type equality constraint).
|
||||
pub(crate) fn assoc_ty_binding(
|
||||
&mut self,
|
||||
assoc_ty_name: rustc_span::Symbol,
|
||||
span: Span,
|
||||
ty: &'hir hir::Ty<'hir>,
|
||||
) -> hir::TypeBinding<'hir> {
|
||||
) -> hir::AssocItemConstraint<'hir> {
|
||||
let ident = Ident::with_dummy_span(assoc_ty_name);
|
||||
let kind = hir::TypeBindingKind::Equality { term: ty.into() };
|
||||
let kind = hir::AssocItemConstraintKind::Equality { term: ty.into() };
|
||||
let args = arena_vec![self;];
|
||||
let bindings = arena_vec![self;];
|
||||
let constraints = arena_vec![self;];
|
||||
let gen_args = self.arena.alloc(hir::GenericArgs {
|
||||
args,
|
||||
bindings,
|
||||
constraints,
|
||||
parenthesized: hir::GenericArgsParentheses::No,
|
||||
span_ext: DUMMY_SP,
|
||||
});
|
||||
hir::TypeBinding {
|
||||
hir::AssocItemConstraint {
|
||||
hir_id: self.next_id(),
|
||||
gen_args,
|
||||
span: self.lower_span(span),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue