mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
syntax: Don't parse idents with parse_path
Lift some restrictions on type parameters in paths Sanity check import paths for type parameters
This commit is contained in:
@@ -120,7 +120,7 @@ fn sanity_check_import(&self, view_path: &hir::ViewPath, id: NodeId) {
|
||||
// prevent `self` or `super` at beginning of global path
|
||||
if path.global && path.segments.len() > 0 {
|
||||
let first = path.segments[0].identifier.name;
|
||||
if first == keywords::Super.to_name() || first == keywords::SelfValue.to_name() {
|
||||
if first == keywords::Super.ident.name || first == keywords::SelfValue.ident.name {
|
||||
self.session.add_lint(
|
||||
lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
|
||||
format!("expected identifier, found keyword `{}`", first)
|
||||
|
||||
@@ -583,6 +583,11 @@ pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_ident_into_path(&mut self) -> PResult<'a, ast::Path> {
|
||||
let ident = self.parse_ident()?;
|
||||
Ok(ast::Path::from_ident(self.last_span, ident))
|
||||
}
|
||||
|
||||
/// Check if the next token is `tok`, and return `true` if so.
|
||||
///
|
||||
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
|
||||
@@ -1462,7 +1467,7 @@ pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> {
|
||||
} else if self.eat_lt() {
|
||||
|
||||
let (qself, path) =
|
||||
self.parse_qualified_path(NoTypesAllowed)?;
|
||||
self.parse_qualified_path(LifetimeAndTypesWithoutColons)?;
|
||||
|
||||
TyKind::Path(Some(qself), path)
|
||||
} else if self.is_path_start() {
|
||||
@@ -3573,7 +3578,7 @@ fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
|
||||
let (qself, path) = if self.eat_lt() {
|
||||
// Parse a qualified path
|
||||
let (qself, path) =
|
||||
self.parse_qualified_path(NoTypesAllowed)?;
|
||||
self.parse_qualified_path(LifetimeAndTypesWithColons)?;
|
||||
(Some(qself), path)
|
||||
} else {
|
||||
// Parse an unqualified path
|
||||
@@ -3651,9 +3656,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
|
||||
// Plain idents have some extra abilities here compared to general paths
|
||||
if self.look_ahead(1, |t| *t == token::Not) {
|
||||
// Parse macro invocation
|
||||
let ident = self.parse_ident()?;
|
||||
let ident_span = self.last_span;
|
||||
let path = ast::Path::from_ident(ident_span, ident);
|
||||
let path = self.parse_ident_into_path()?;
|
||||
self.bump();
|
||||
let delim = self.expect_open_delim()?;
|
||||
let tts = self.parse_seq_to_end(
|
||||
@@ -3673,7 +3676,7 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
|
||||
let (qself, path) = if self.eat_lt() {
|
||||
// Parse a qualified path
|
||||
let (qself, path) =
|
||||
self.parse_qualified_path(NoTypesAllowed)?;
|
||||
self.parse_qualified_path(LifetimeAndTypesWithColons)?;
|
||||
(Some(qself), path)
|
||||
} else {
|
||||
// Parse an unqualified path
|
||||
@@ -3936,7 +3939,7 @@ fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> {
|
||||
|
||||
// Potential trouble: if we allow macros with paths instead of
|
||||
// idents, we'd need to look ahead past the whole path here...
|
||||
let pth = self.parse_path(NoTypesAllowed)?;
|
||||
let pth = self.parse_ident_into_path()?;
|
||||
self.bump();
|
||||
|
||||
let id = match self.token {
|
||||
@@ -4956,7 +4959,7 @@ fn parse_impl_method(&mut self, vis: &Visibility)
|
||||
self.complain_if_pub_macro(&vis, last_span);
|
||||
|
||||
let lo = self.span.lo;
|
||||
let pth = self.parse_path(NoTypesAllowed)?;
|
||||
let pth = self.parse_ident_into_path()?;
|
||||
self.expect(&token::Not)?;
|
||||
|
||||
// eat a matched-delimiter token tree:
|
||||
@@ -6009,7 +6012,7 @@ fn parse_macro_use_or_failure(
|
||||
let mac_lo = self.span.lo;
|
||||
|
||||
// item macro.
|
||||
let pth = self.parse_path(NoTypesAllowed)?;
|
||||
let pth = self.parse_ident_into_path()?;
|
||||
self.expect(&token::Not)?;
|
||||
|
||||
// a 'special' identifier (like what `macro_rules!` uses)
|
||||
|
||||
Reference in New Issue
Block a user