about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-15 12:10:36 +0000
committerbors <bors@rust-lang.org>2023-01-15 12:10:36 +0000
commitfc11ee02ee91b32e23684cd478bca80fe5323b47 (patch)
tree0c66b87e31438e45c055345e2f62e1e10b2639b6 /tests
parentbbb36fe5455ee56cdeec0a5d12015ac7ae77a6a7 (diff)
parentc1a7dbc0e3511b144f7051a065b9467871ad6ef9 (diff)
downloadrust-fc11ee02ee91b32e23684cd478bca80fe5323b47.tar.gz
rust-fc11ee02ee91b32e23684cd478bca80fe5323b47.zip
Auto merge of #106171 - compiler-errors:consolidate-extract_callable_info, r=estebank,lcnr
Consolidate two almost duplicated fn info extraction routines

Moves `extract_callable_info` up to trait selection, because it was being (almost) duplicated fully there for similar diagnostic purposes. This also generalizes the diagnostics we can give slightly (see UI test).
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/suggestions/call-on-unimplemented-with-autoderef.rs13
-rw-r--r--tests/ui/suggestions/call-on-unimplemented-with-autoderef.stderr21
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/suggestions/call-on-unimplemented-with-autoderef.rs b/tests/ui/suggestions/call-on-unimplemented-with-autoderef.rs
new file mode 100644
index 00000000000..9021dd752e7
--- /dev/null
+++ b/tests/ui/suggestions/call-on-unimplemented-with-autoderef.rs
@@ -0,0 +1,13 @@
+trait Foo {}
+
+impl Foo for i32 {}
+
+fn needs_foo(_: impl Foo) {}
+
+fn test(x: &Box<dyn Fn() -> i32>) {
+    needs_foo(x);
+    //~^ ERROR the trait bound
+    //~| HELP use parentheses to call this trait object
+}
+
+fn main() {}
diff --git a/tests/ui/suggestions/call-on-unimplemented-with-autoderef.stderr b/tests/ui/suggestions/call-on-unimplemented-with-autoderef.stderr
new file mode 100644
index 00000000000..90f44cce06e
--- /dev/null
+++ b/tests/ui/suggestions/call-on-unimplemented-with-autoderef.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the trait bound `&Box<dyn Fn() -> i32>: Foo` is not satisfied
+  --> $DIR/call-on-unimplemented-with-autoderef.rs:8:15
+   |
+LL |     needs_foo(x);
+   |     --------- ^ the trait `Foo` is not implemented for `&Box<dyn Fn() -> i32>`
+   |     |
+   |     required by a bound introduced by this call
+   |
+note: required by a bound in `needs_foo`
+  --> $DIR/call-on-unimplemented-with-autoderef.rs:5:22
+   |
+LL | fn needs_foo(_: impl Foo) {}
+   |                      ^^^ required by this bound in `needs_foo`
+help: use parentheses to call this trait object
+   |
+LL |     needs_foo(x());
+   |                ++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.