use super::ty::{AllowPlus, RecoverQPath};
use super::{Parser, TokenType};
use crate::maybe_whole;
+use rustc_ast::ast::{
+ self, AngleBracketedArgs, Ident, ParenthesizedArgs, Path, PathSegment, QSelf,
+};
+use rustc_ast::ast::{
+ AnonConst, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode, GenericArg,
+};
+use rustc_ast::token::{self, Token};
use rustc_errors::{pluralize, Applicability, PResult};
use rustc_span::source_map::{BytePos, Span};
use rustc_span::symbol::{kw, sym};
-use syntax::ast::{self, AngleBracketedArgs, Ident, ParenthesizedArgs, Path, PathSegment, QSelf};
-use syntax::ast::{
- AnonConst, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode, GenericArg,
-};
-use syntax::token::{self, Token};
use log::debug;
use std::mem;
/// `<T as U>::F::a<S>` (without disambiguator)
/// `<T as U>::F::a::<S>` (with disambiguator)
pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (QSelf, Path)> {
- let lo = self.prev_span;
+ let lo = self.prev_token.span;
let ty = self.parse_ty()?;
// `path` will contain the prefix of the path up to the `>`,
if self.eat_keyword(kw::As) {
let path_lo = self.token.span;
path = self.parse_path(PathStyle::Type)?;
- path_span = path_lo.to(self.prev_span);
+ path_span = path_lo.to(self.prev_token.span);
} else {
path_span = self.token.span.to(self.token.span);
path = ast::Path { segments: Vec::new(), span: path_span };
let qself = QSelf { ty, path_span, position: path.segments.len() };
self.parse_path_segments(&mut path.segments, style)?;
- Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_span) }))
+ Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_token.span) }))
}
/// Recover from an invalid single colon, when the user likely meant a qualified path.
self.diagnostic()
.struct_span_err(
- self.prev_span,
+ self.prev_token.span,
"found single colon before projection in qualified path",
)
.span_suggestion(
- self.prev_span,
+ self.prev_token.span,
"use double colon",
"::".to_string(),
Applicability::MachineApplicable,
path
});
- let lo = self.unnormalized_token.span;
+ let lo = self.token.span;
let mut segments = Vec::new();
let mod_sep_ctxt = self.token.span.ctxt();
if self.eat(&token::ModSep) {
}
self.parse_path_segments(&mut segments, style)?;
- Ok(Path { segments, span: lo.to(self.prev_span) })
+ Ok(Path { segments, span: lo.to(self.prev_token.span) })
}
pub(super) fn parse_path_segments(
let (args, constraints) =
self.parse_generic_args_with_leading_angle_bracket_recovery(style, lo)?;
self.expect_gt()?;
- let span = lo.to(self.prev_span);
+ let span = lo.to(self.prev_token.span);
AngleBracketedArgs { args, constraints, span }.into()
} else {
// `(T, U) -> R`
let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?;
- let span = ident.span.to(self.prev_span);
+ let span = ident.span.to(self.prev_token.span);
let output = self.parse_ret_ty(AllowPlus::No, RecoverQPath::No)?;
ParenthesizedArgs { inputs, output, span }.into()
};
}
pub(super) fn parse_path_segment_ident(&mut self) -> PResult<'a, Ident> {
- match self.token.kind {
+ match self.normalized_token.kind {
token::Ident(name, _) if name.is_path_segment_keyword() => {
- let span = self.token.span;
self.bump();
- Ok(Ident::new(name, span))
+ Ok(Ident::new(name, self.normalized_prev_token.span))
}
_ => self.parse_ident(),
}
AssocTyConstraintKind::Equality { ty: self.parse_ty()? }
} else if self.eat(&token::Colon) {
AssocTyConstraintKind::Bound {
- bounds: self.parse_generic_bounds(Some(self.prev_span))?,
+ bounds: self.parse_generic_bounds(Some(self.prev_token.span))?,
}
} else {
unreachable!();
};
- let span = lo.to(self.prev_span);
+ let span = lo.to(self.prev_token.span);
// Gate associated type bounds, e.g., `Iterator<Item: Ord>`.
if let AssocTyConstraintKind::Bound { .. } = kind {
// FIXME: we would like to report this in ast_validation instead, but we currently do not
// preserve ordering of generic parameters with respect to associated type binding, so we
// lose that information after parsing.
- if misplaced_assoc_ty_constraints.len() > 0 {
+ if !misplaced_assoc_ty_constraints.is_empty() {
let mut err = self.struct_span_err(
- args_lo.to(self.prev_span),
+ args_lo.to(self.prev_token.span),
"associated type bindings must be declared after generic parameters",
);
for span in misplaced_assoc_ty_constraints {