Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/suggestions/seggest_print_over_printf.rs
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions src/test/ui/suggestions/seggest_print_over_printf.stderr
Original file line number Diff line number Diff line change
@@ -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`.