Rename HIR TypeBinding to AssocItemConstraint and related cleanup

This commit is contained in:
León Orell Valerian Liehr 2024-05-27 23:53:46 +02:00
parent 0a59f11362
commit 34c56c45cf
No known key found for this signature in database
GPG key ID: D17A07215F68E713
108 changed files with 878 additions and 818 deletions

View file

@ -7,8 +7,8 @@ use ast::token::IdentIsRaw;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::{
self as ast, AngleBracketedArg, AngleBracketedArgs, AnonConst, AssocConstraint,
AssocConstraintKind, BlockCheckMode, GenericArg, GenericArgs, Generics, ParenthesizedArgs,
self as ast, AngleBracketedArg, AngleBracketedArgs, AnonConst, AssocItemConstraint,
AssocItemConstraintKind, BlockCheckMode, GenericArg, GenericArgs, Generics, ParenthesizedArgs,
Path, PathSegment, QSelf,
};
use rustc_errors::{Applicability, Diag, PResult};
@ -720,10 +720,7 @@ impl<'a> Parser<'a> {
));
}
let kind = if self.eat(&token::Colon) {
// Parse associated type constraint bound.
let bounds = self.parse_generic_bounds()?;
AssocConstraintKind::Bound { bounds }
AssocItemConstraintKind::Bound { bounds: self.parse_generic_bounds()? }
} else if self.eat(&token::Eq) {
self.parse_assoc_equality_term(
ident,
@ -735,17 +732,17 @@ impl<'a> Parser<'a> {
};
let span = lo.to(self.prev_token.span);
// Gate associated type bounds, e.g., `Iterator<Item: Ord>`.
if let AssocConstraintKind::Bound { .. } = kind {
if let Some(ast::GenericArgs::Parenthesized(args)) = &gen_args
&& args.inputs.is_empty()
&& matches!(args.output, ast::FnRetTy::Default(..))
{
self.psess.gated_spans.gate(sym::return_type_notation, span);
}
if let AssocItemConstraintKind::Bound { .. } = kind
&& let Some(ast::GenericArgs::Parenthesized(args)) = &gen_args
&& args.inputs.is_empty()
&& let ast::FnRetTy::Default(..) = args.output
{
self.psess.gated_spans.gate(sym::return_type_notation, span);
}
let constraint =
AssocConstraint { id: ast::DUMMY_NODE_ID, ident, gen_args, kind, span };
AssocItemConstraint { id: ast::DUMMY_NODE_ID, ident, gen_args, kind, span };
Ok(Some(AngleBracketedArg::Constraint(constraint)))
} else {
// we only want to suggest `:` and `=` in contexts where the previous token
@ -772,7 +769,7 @@ impl<'a> Parser<'a> {
ident: Ident,
gen_args: Option<&GenericArgs>,
eq: Span,
) -> PResult<'a, AssocConstraintKind> {
) -> PResult<'a, AssocItemConstraintKind> {
let arg = self.parse_generic_arg(None)?;
let span = ident.span.to(self.prev_token.span);
let term = match arg {
@ -820,7 +817,7 @@ impl<'a> Parser<'a> {
return Err(err);
}
};
Ok(AssocConstraintKind::Equality { term })
Ok(AssocItemConstraintKind::Equality { term })
}
/// We do not permit arbitrary expressions as const arguments. They must be one of:
@ -941,7 +938,7 @@ impl<'a> Parser<'a> {
}
/// Given a arg inside of generics, we try to destructure it as if it were the LHS in
/// `LHS = ...`, i.e. an associated type binding.
/// `LHS = ...`, i.e. an associated item binding.
/// This returns a bool indicating if there are any `for<'a, 'b>` binder args, the
/// identifier, and any GAT arguments.
fn get_ident_from_generic_arg(