diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 9c95adc628bc6..5b9513ebc0da4 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -282,6 +282,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { "you may want to use a bool value instead", format!("{}", item_typo), )) + // FIXME(vicnenzopalazzo): make the check smarter, + // and maybe expand with levenshtein distance checks + } else if item_str.as_str() == "printf" { + Some(( + item_span, + "you may have meant to use the `print` macro", + "print!".to_owned(), + )) } else { suggestion }; 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 0000000000000..25566cd7f2aeb --- /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 0000000000000..7b1ce047a9274 --- /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`.