about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-05-07 18:19:06 +0200
committerGitHub <noreply@github.com>2025-05-07 18:19:06 +0200
commit32325e1decbced3fb590c0a698886dfea658af87 (patch)
tree4a025012e6ee77a9479b10d5784b8e388820af59 /tests
parentf7a9c672f061ac14f627d8fac0fdae9ea3a98f7c (diff)
parentb922da3586ce01a4bf174db09624a1d0a424d5d9 (diff)
downloadrust-32325e1decbced3fb590c0a698886dfea658af87.tar.gz
rust-32325e1decbced3fb590c0a698886dfea658af87.zip
Rollup merge of #140671 - xizheyin:issue-140169, r=petrochenkov
Parser: Recover error from named params while parse_path

Fixes #140169

I added test to the first commit and the second added the code and changes to test.

r? `@petrochenkov`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/fn/fn-trait-use-named-params-issue-140169.rs12
-rw-r--r--tests/ui/fn/fn-trait-use-named-params-issue-140169.stderr38
-rw-r--r--tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs8
-rw-r--r--tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.stderr45
-rw-r--r--tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs5
-rw-r--r--tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr39
6 files changed, 95 insertions, 52 deletions
diff --git a/tests/ui/fn/fn-trait-use-named-params-issue-140169.rs b/tests/ui/fn/fn-trait-use-named-params-issue-140169.rs
new file mode 100644
index 00000000000..218450abd49
--- /dev/null
+++ b/tests/ui/fn/fn-trait-use-named-params-issue-140169.rs
@@ -0,0 +1,12 @@
+fn f1(_: fn(a: u8)) {}
+fn f2(_: impl Fn(u8, vvvv: u8)) {} //~ ERROR `Trait(...)` syntax does not support named parameters
+fn f3(_: impl Fn(aaaa: u8, u8)) {} //~ ERROR `Trait(...)` syntax does not support named parameters
+fn f4(_: impl Fn(aaaa: u8, vvvv: u8)) {}
+//~^ ERROR `Trait(...)` syntax does not support named parameters
+//~| ERROR `Trait(...)` syntax does not support named parameters
+fn f5(_: impl Fn(u8, ...)) {}
+//~^ ERROR `Trait(...)` syntax does not support c_variadic parameters
+fn f6(_: impl Fn(u8, #[allow(unused_attributes)] u8)) {}
+//~^ ERROR `Trait(...)` syntax does not support attributes in parameters
+
+fn main(){}
diff --git a/tests/ui/fn/fn-trait-use-named-params-issue-140169.stderr b/tests/ui/fn/fn-trait-use-named-params-issue-140169.stderr
new file mode 100644
index 00000000000..b72d5b7b3bc
--- /dev/null
+++ b/tests/ui/fn/fn-trait-use-named-params-issue-140169.stderr
@@ -0,0 +1,38 @@
+error: `Trait(...)` syntax does not support named parameters
+  --> $DIR/fn-trait-use-named-params-issue-140169.rs:2:22
+   |
+LL | fn f2(_: impl Fn(u8, vvvv: u8)) {}
+   |                      ^^^^ help: remove the parameter name
+
+error: `Trait(...)` syntax does not support named parameters
+  --> $DIR/fn-trait-use-named-params-issue-140169.rs:3:18
+   |
+LL | fn f3(_: impl Fn(aaaa: u8, u8)) {}
+   |                  ^^^^ help: remove the parameter name
+
+error: `Trait(...)` syntax does not support named parameters
+  --> $DIR/fn-trait-use-named-params-issue-140169.rs:4:18
+   |
+LL | fn f4(_: impl Fn(aaaa: u8, vvvv: u8)) {}
+   |                  ^^^^ help: remove the parameter name
+
+error: `Trait(...)` syntax does not support named parameters
+  --> $DIR/fn-trait-use-named-params-issue-140169.rs:4:28
+   |
+LL | fn f4(_: impl Fn(aaaa: u8, vvvv: u8)) {}
+   |                            ^^^^ help: remove the parameter name
+
+error: `Trait(...)` syntax does not support c_variadic parameters
+  --> $DIR/fn-trait-use-named-params-issue-140169.rs:7:22
+   |
+LL | fn f5(_: impl Fn(u8, ...)) {}
+   |                      ^^^ help: remove the `...`
+
+error: `Trait(...)` syntax does not support attributes in parameters
+  --> $DIR/fn-trait-use-named-params-issue-140169.rs:9:22
+   |
+LL | fn f6(_: impl Fn(u8, #[allow(unused_attributes)] u8)) {}
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the attributes
+
+error: aborting due to 6 previous errors
+
diff --git a/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs b/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs
index 6bfe16ae37d..db25ce44089 100644
--- a/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs
+++ b/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs
@@ -2,8 +2,10 @@
 
 fn main() {
     unsafe {
-        dealloc(ptr2, Layout::(x: !)(1, 1)); //~ ERROR: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
-        //~^ ERROR: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
-        //~| NOTE while parsing this parenthesized list of type arguments starting here
+        dealloc(ptr2, Layout::(x: !)(1, 1)); //~ ERROR `Trait(...)` syntax does not support named parameters
+        //~^ ERROR cannot find function `dealloc` in this scope [E0425]
+        //~| ERROR cannot find value `ptr2` in this scope [E0425]
+        //~| ERROR the `!` type is experimental [E0658]
+        //~| ERROR cannot find function, tuple struct or tuple variant `Layout` in this scope [E0425]
     }
 }
diff --git a/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.stderr b/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.stderr
index c12bf7f9e3f..a083883af21 100644
--- a/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.stderr
+++ b/tests/ui/parser/diagnostics-parenthesized-type-arguments-ice-issue-122345.stderr
@@ -1,16 +1,43 @@
-error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
-  --> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:33
+error: `Trait(...)` syntax does not support named parameters
+  --> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:32
    |
 LL |         dealloc(ptr2, Layout::(x: !)(1, 1));
-   |                             --- ^ expected one of 7 possible tokens
-   |                             |
-   |                             while parsing this parenthesized list of type arguments starting here
+   |                                ^ help: remove the parameter name
 
-error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
-  --> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:43
+error[E0425]: cannot find function `dealloc` in this scope
+  --> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:9
    |
 LL |         dealloc(ptr2, Layout::(x: !)(1, 1));
-   |                                           ^ expected one of `.`, `;`, `?`, `}`, or an operator
+   |         ^^^^^^^ not found in this scope
+   |
+help: consider importing this function
+   |
+LL + use std::alloc::dealloc;
+   |
+
+error[E0425]: cannot find value `ptr2` in this scope
+  --> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:17
+   |
+LL |         dealloc(ptr2, Layout::(x: !)(1, 1));
+   |                 ^^^^ not found in this scope
+
+error[E0658]: the `!` type is experimental
+  --> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:35
+   |
+LL |         dealloc(ptr2, Layout::(x: !)(1, 1));
+   |                                   ^
+   |
+   = note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
+   = help: add `#![feature(never_type)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0425]: cannot find function, tuple struct or tuple variant `Layout` in this scope
+  --> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:5:23
+   |
+LL |         dealloc(ptr2, Layout::(x: !)(1, 1));
+   |                       ^^^^^^ not found in this scope
 
-error: aborting due to 2 previous errors
+error: aborting due to 5 previous errors
 
+Some errors have detailed explanations: E0425, E0658.
+For more information about an error, try `rustc --explain E0425`.
diff --git a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs
index 1c28c0632fa..60dd88e6540 100644
--- a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs
+++ b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs
@@ -2,7 +2,4 @@
 
 struct Apple((Apple, Option(Banana ? Citron)));
 //~^ ERROR invalid `?` in type
-//~| ERROR expected one of `)` or `,`, found `Citron`
-//~| ERROR cannot find type `Citron` in this scope [E0412]
-//~| ERROR parenthesized type parameters may only be used with a `Fn` trait [E0214]
-//~| ERROR `Apple` has infinite size
+//~| ERROR unexpected token: `Citron`
diff --git a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr
index 97a73b4fd5e..c92535c3906 100644
--- a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr
+++ b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr
@@ -10,44 +10,11 @@ LL - struct Apple((Apple, Option(Banana ? Citron)));
 LL + struct Apple((Apple, Option(Option<Banana > Citron)));
    |
 
-error: expected one of `)` or `,`, found `Citron`
+error: unexpected token: `Citron`
   --> $DIR/issue-103748-ICE-wrong-braces.rs:3:38
    |
 LL | struct Apple((Apple, Option(Banana ? Citron)));
-   |                                     -^^^^^^ expected one of `)` or `,`
-   |                                     |
-   |                                     help: missing `,`
+   |                                      ^^^^^^ unexpected token after this
 
-error[E0412]: cannot find type `Citron` in this scope
-  --> $DIR/issue-103748-ICE-wrong-braces.rs:3:38
-   |
-LL | struct Apple((Apple, Option(Banana ? Citron)));
-   |                                      ^^^^^^ not found in this scope
-
-error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
-  --> $DIR/issue-103748-ICE-wrong-braces.rs:3:22
-   |
-LL | struct Apple((Apple, Option(Banana ? Citron)));
-   |                      ^^^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
-   |
-help: use angle brackets instead
-   |
-LL - struct Apple((Apple, Option(Banana ? Citron)));
-LL + struct Apple((Apple, Option<Banana ? Citron>));
-   |
-
-error[E0072]: recursive type `Apple` has infinite size
-  --> $DIR/issue-103748-ICE-wrong-braces.rs:3:1
-   |
-LL | struct Apple((Apple, Option(Banana ? Citron)));
-   | ^^^^^^^^^^^^  ----- recursive without indirection
-   |
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
-   |
-LL | struct Apple((Box<Apple>, Option(Banana ? Citron)));
-   |               ++++     +
-
-error: aborting due to 5 previous errors
+error: aborting due to 2 previous errors
 
-Some errors have detailed explanations: E0072, E0214, E0412.
-For more information about an error, try `rustc --explain E0072`.