about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPavel Grigorenko <GrigorenkoPV@ya.ru>2024-09-21 20:29:22 +0300
committerPavel Grigorenko <GrigorenkoPV@ya.ru>2024-09-21 20:29:22 +0300
commit82482dc3579fd227bbb1226b7b4fc747b01f0def (patch)
treec196409566b12c58655b0d8a19e43d01b682b09d
parente90e2593ea9c29ff6be20ec38b314fb2d6d927a4 (diff)
downloadrust-82482dc3579fd227bbb1226b7b4fc747b01f0def.tar.gz
rust-82482dc3579fd227bbb1226b7b4fc747b01f0def.zip
Parser: recover from `:::` to `::` in delegations
-rw-r--r--compiler/rustc_parse/src/parser/item.rs2
-rw-r--r--tests/ui/parser/triple-colon-delegation.fixed44
-rw-r--r--tests/ui/parser/triple-colon-delegation.rs44
-rw-r--r--tests/ui/parser/triple-colon-delegation.stderr38
4 files changed, 127 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 25627ad53a3..afd9871a635 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -707,7 +707,7 @@ impl<'a> Parser<'a> {
             })
         };
 
-        let (ident, item_kind) = if self.eat(&token::PathSep) {
+        let (ident, item_kind) = if self.eat_path_sep() {
             let suffixes = if self.eat(&token::BinOp(token::Star)) {
                 None
             } else {
diff --git a/tests/ui/parser/triple-colon-delegation.fixed b/tests/ui/parser/triple-colon-delegation.fixed
new file mode 100644
index 00000000000..fbb614b57da
--- /dev/null
+++ b/tests/ui/parser/triple-colon-delegation.fixed
@@ -0,0 +1,44 @@
+//@ run-rustfix
+
+#![feature(fn_delegation)]
+#![allow(incomplete_features, unused)]
+
+trait Trait {
+    fn foo(&self) {}
+}
+
+struct F;
+impl Trait for F {}
+
+pub mod to_reuse {
+    pub fn bar() {}
+}
+
+mod fn_to_other {
+    use super::*;
+
+    reuse Trait::foo; //~ ERROR path separator must be a double colon
+    reuse to_reuse::bar; //~ ERROR path separator must be a double colon
+}
+
+impl Trait for u8 {}
+
+struct S(u8);
+
+mod to_import {
+    pub fn check(arg: &u8) -> &u8 { arg }
+}
+
+impl Trait for S {
+    reuse Trait::* { //~ ERROR path separator must be a double colon
+        use to_import::check;
+
+        let _arr = Some(self.0).map(|x| [x * 2; 3]);
+        check(&self.0)
+    }
+}
+
+fn main() {
+    let s = S(0);
+    s.foo();
+}
diff --git a/tests/ui/parser/triple-colon-delegation.rs b/tests/ui/parser/triple-colon-delegation.rs
new file mode 100644
index 00000000000..9fbaa4477ae
--- /dev/null
+++ b/tests/ui/parser/triple-colon-delegation.rs
@@ -0,0 +1,44 @@
+//@ run-rustfix
+
+#![feature(fn_delegation)]
+#![allow(incomplete_features, unused)]
+
+trait Trait {
+    fn foo(&self) {}
+}
+
+struct F;
+impl Trait for F {}
+
+pub mod to_reuse {
+    pub fn bar() {}
+}
+
+mod fn_to_other {
+    use super::*;
+
+    reuse Trait:::foo; //~ ERROR path separator must be a double colon
+    reuse to_reuse:::bar; //~ ERROR path separator must be a double colon
+}
+
+impl Trait for u8 {}
+
+struct S(u8);
+
+mod to_import {
+    pub fn check(arg: &u8) -> &u8 { arg }
+}
+
+impl Trait for S {
+    reuse Trait:::* { //~ ERROR path separator must be a double colon
+        use to_import::check;
+
+        let _arr = Some(self.0).map(|x| [x * 2; 3]);
+        check(&self.0)
+    }
+}
+
+fn main() {
+    let s = S(0);
+    s.foo();
+}
diff --git a/tests/ui/parser/triple-colon-delegation.stderr b/tests/ui/parser/triple-colon-delegation.stderr
new file mode 100644
index 00000000000..d748c7d92b5
--- /dev/null
+++ b/tests/ui/parser/triple-colon-delegation.stderr
@@ -0,0 +1,38 @@
+error: path separator must be a double colon
+  --> $DIR/triple-colon-delegation.rs:20:18
+   |
+LL |     reuse Trait:::foo;
+   |                  ^
+   |
+help: use a double colon instead
+   |
+LL -     reuse Trait:::foo;
+LL +     reuse Trait::foo;
+   |
+
+error: path separator must be a double colon
+  --> $DIR/triple-colon-delegation.rs:21:21
+   |
+LL |     reuse to_reuse:::bar;
+   |                     ^
+   |
+help: use a double colon instead
+   |
+LL -     reuse to_reuse:::bar;
+LL +     reuse to_reuse::bar;
+   |
+
+error: path separator must be a double colon
+  --> $DIR/triple-colon-delegation.rs:33:18
+   |
+LL |     reuse Trait:::* {
+   |                  ^
+   |
+help: use a double colon instead
+   |
+LL -     reuse Trait:::* {
+LL +     reuse Trait::* {
+   |
+
+error: aborting due to 3 previous errors
+