about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-08-26 16:34:11 +0200
committerGitHub <noreply@github.com>2025-08-26 16:34:11 +0200
commit2708b26a3ba9c1fbdb44df037a3626ee5eb4657d (patch)
tree559815d823c9a9583233fd214d9cc4f5223de666 /tests
parent879bb220927556e6c1de6a0f020127129698e3de (diff)
parent5e8c2c3aec19c50efc22854c09564844a133bbaf (diff)
downloadrust-2708b26a3ba9c1fbdb44df037a3626ee5eb4657d.tar.gz
rust-2708b26a3ba9c1fbdb44df037a3626ee5eb4657d.zip
Rollup merge of #145481 - mu001999-contrib:fix/closure-sugg, r=SparrowLii
Add parentheses for closure when suggesting calling closure

Fixes rust-lang/rust#145404
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr5
-rw-r--r--tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.fixed13
-rw-r--r--tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.rs13
-rw-r--r--tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.stderr23
4 files changed, 52 insertions, 2 deletions
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr
index 4c8a5e46751..c05584ef909 100644
--- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr
@@ -32,8 +32,9 @@ LL | fn check(_: impl std::marker::UnsizedConstParamTy) {}
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
 help: use parentheses to call this closure
    |
-LL |     check(|| {}());
-   |                ++
+LL -     check(|| {});
+LL +     check((|| {})());
+   |
 
 error[E0277]: `fn()` can't be used as a const parameter type
   --> $DIR/const_param_ty_bad.rs:9:11
diff --git a/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.fixed b/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.fixed
new file mode 100644
index 00000000000..2835743fca2
--- /dev/null
+++ b/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.fixed
@@ -0,0 +1,13 @@
+//@ run-rustfix
+
+use std::fmt::Display;
+
+struct S;
+
+impl S {
+    fn call(&self, _: impl Display) {}
+}
+
+fn main() {
+    S.call((|| "hello")()); //~ ERROR [E0277]
+}
diff --git a/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.rs b/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.rs
new file mode 100644
index 00000000000..848629a6700
--- /dev/null
+++ b/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.rs
@@ -0,0 +1,13 @@
+//@ run-rustfix
+
+use std::fmt::Display;
+
+struct S;
+
+impl S {
+    fn call(&self, _: impl Display) {}
+}
+
+fn main() {
+    S.call(|| "hello"); //~ ERROR [E0277]
+}
diff --git a/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.stderr b/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.stderr
new file mode 100644
index 00000000000..cb6df5af7fb
--- /dev/null
+++ b/tests/ui/suggestions/use-parentheses-to-call-closure-issue-145404.stderr
@@ -0,0 +1,23 @@
+error[E0277]: `{closure@$DIR/use-parentheses-to-call-closure-issue-145404.rs:12:12: 12:14}` doesn't implement `std::fmt::Display`
+  --> $DIR/use-parentheses-to-call-closure-issue-145404.rs:12:12
+   |
+LL |     S.call(|| "hello");
+   |       ---- ^^^^^^^^^^ unsatisfied trait bound
+   |       |
+   |       required by a bound introduced by this call
+   |
+   = help: the trait `std::fmt::Display` is not implemented for closure `{closure@$DIR/use-parentheses-to-call-closure-issue-145404.rs:12:12: 12:14}`
+note: required by a bound in `S::call`
+  --> $DIR/use-parentheses-to-call-closure-issue-145404.rs:8:28
+   |
+LL |     fn call(&self, _: impl Display) {}
+   |                            ^^^^^^^ required by this bound in `S::call`
+help: use parentheses to call this closure
+   |
+LL -     S.call(|| "hello");
+LL +     S.call((|| "hello")());
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.