about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorsurechen <chenshuo17@huawei.com>2024-09-26 12:35:44 +0800
committersurechen <chenshuo17@huawei.com>2024-09-27 15:41:04 +0800
commitd0165956fe070d12090896aa5546e509045471eb (patch)
treeb20e179b82deee8233884d2f03ab873425bfe29b /compiler/rustc_parse/src/parser
parent1b5aa96d6016bafe50e071b45d4d2e3c90fd766f (diff)
downloadrust-d0165956fe070d12090896aa5546e509045471eb.tar.gz
rust-d0165956fe070d12090896aa5546e509045471eb.zip
Add suggestion for removing invalid path separator `::` in function definition.
for example: `fn invalid_path_separator::<T>() {}`

fixes: #130791
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/generics.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs
index b9256daa725..5aebe716b0a 100644
--- a/compiler/rustc_parse/src/parser/generics.rs
+++ b/compiler/rustc_parse/src/parser/generics.rs
@@ -269,6 +269,13 @@ impl<'a> Parser<'a> {
     ///                  | ( < lifetimes , typaramseq ( , )? > )
     /// where   typaramseq = ( typaram ) | ( typaram , typaramseq )
     pub(super) fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
+        // invalid path separator `::` in function definition
+        // for example `fn invalid_path_separator::<T>() {}`
+        if self.eat_noexpect(&token::PathSep) {
+            self.dcx()
+                .emit_err(errors::InvalidPathSepInFnDefinition { span: self.prev_token.span });
+        }
+
         let span_lo = self.token.span;
         let (params, span) = if self.eat_lt() {
             let params = self.parse_generic_params()?;