Skip to content

Detect C lang printing functions and suggest the appropriate macro call #92898

Closed
@estebank

Description

@estebank

We already translate from C-style formatting strings to Rust formatting strings when passed to the format! family of macros. We should also detect invalid fn calls from other languages that were meant to be macro calls:

fn main() {
    let x = 4;
    printf("%d", x);
}

currently emits the dry

error[E0425]: cannot find function `printf` in this scope
 --> <source>:3:5
  |
3 |     printf("%d", x);
  |     ^^^^^^ not found in this scope

while it could be

error[E0425]: cannot find function `printf` in this scope
 --> <source>:3:5
  |
3 |     printf("%d", x);
  |     ^^^^^^ not found in this scope
help: you might have meant to use the `print!` macro
 --> <source>:3:5
  |
3 |     print!("{}", x);
  |     ~~~~~~  ~~

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions