Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
estebank opened this issue Jan 14, 2022 · 2 comments · Fixed by #104954
Closed

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

estebank opened this issue Jan 14, 2022 · 2 comments · Fixed by #104954
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Jan 14, 2022

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);
  |     ~~~~~~  ~~
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Jan 14, 2022
@vincenzopalazzo
Copy link
Member

@rustbot claim

@vincenzopalazzo
Copy link
Member

Mentoring @amustaque97 on this issue

@rustbot label +E-mentor

@rustbot rustbot added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Oct 29, 2022
@bors bors closed this as completed in 412f05c Nov 28, 2022
RalfJung pushed a commit to RalfJung/miri that referenced this issue Dec 3, 2022
make simple check of prinf function

Fixes rust-lang/rust#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants