about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-28 17:25:48 +0100
committerGitHub <noreply@github.com>2022-11-28 17:25:48 +0100
commit412f05c9e8f0b619300b061b1affc963020f8c98 (patch)
treefd8ffcc8200278291c1c171cb6f732d613e0665d /src
parent60d136000eab7e171e4d2c5bab47e6fee1fd5ec6 (diff)
parentee6f18ef595df21cfe167834f59c768985d74d4c (diff)
downloadrust-412f05c9e8f0b619300b061b1affc963020f8c98.tar.gz
rust-412f05c9e8f0b619300b061b1affc963020f8c98.zip
Rollup merge of #104954 - vincenzopalazzo:macros/prinf, r=estebank
make simple check of prinf function

Fixes https://github.com/rust-lang/rust/issues/92898

With this commit we start to make some simple
check when the name resolution fails, and
we generate some helper messages in case the
name is a C name like in the case of the `printf`
and suggest the correct rust method.

`@rustbot` r? `@pnkfelix`

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/suggestions/seggest_print_over_printf.rs9
-rw-r--r--src/test/ui/suggestions/seggest_print_over_printf.stderr14
2 files changed, 23 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/seggest_print_over_printf.rs b/src/test/ui/suggestions/seggest_print_over_printf.rs
new file mode 100644
index 00000000000..25566cd7f2a
--- /dev/null
+++ b/src/test/ui/suggestions/seggest_print_over_printf.rs
@@ -0,0 +1,9 @@
+// Suggest to a user to use the print macros
+// instead to use the printf.
+
+fn main() {
+    let x = 4;
+    printf("%d", x);
+    //~^ ERROR cannot find function `printf` in this scope
+    //~| HELP you may have meant to use the `print` macro
+}
diff --git a/src/test/ui/suggestions/seggest_print_over_printf.stderr b/src/test/ui/suggestions/seggest_print_over_printf.stderr
new file mode 100644
index 00000000000..7b1ce047a92
--- /dev/null
+++ b/src/test/ui/suggestions/seggest_print_over_printf.stderr
@@ -0,0 +1,14 @@
+error[E0425]: cannot find function `printf` in this scope
+  --> $DIR/seggest_print_over_printf.rs:6:5
+   |
+LL |     printf("%d", x);
+   |     ^^^^^^ not found in this scope
+   |
+help: you may have meant to use the `print` macro
+   |
+LL |     print!("%d", x);
+   |     ~~~~~~
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.