`print!` requires at least a format string argument, this error originates ...
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
print!();
Current output
error: requires at least a format string argument
--> src\main.rs:4:5
|
4 | print!();
| ^^^^^^^^
|
= note: this error originates in the macro `$crate::format_args` which comes from the expansion of the macro `print` (in Nightly builds, run with -Z macro-backtrace for more info)
Desired output
error: Printing nothing would have no effect
--> src\main.rs:3:9
|
3 | compile_error!("Printing nothing would have no effect")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
13 | print!()
| -------- in this macro invocation
|
= note: this error originates in the macro `print` (in Nightly builds, run with -Z macro-backtrace for more info)
Rationale and extra context
Either error directly in the print! macro, like shown above, or even better just a warning, that invoking the macro without arguments would do nothing.
I found this inconsistency, when trying to explain Rust to someone, who never wrote a single line of code.
println! without arguments prints an new line, but print! have no special case for no arguments, and it fails inside of an macro, that have no visible implementation (/* compiler built-in */), so look at it from the eyes of someone who never wrote a code, but already knows how to navigate to the implementation of the macro. The macro states ($($arg:tt)*) that it can accept 0 inputs, but then fails with 0 inputs. I think both macros should be changed to ($($arg:tt)+) instead, and have explicit empty case, that will print an error like I shown above (but probably bit more polished wording, English is not my native language).
Maybe just removing the note section of the error would already be an improvement, because that is main source of the confusion.
Also why are we being told about Nightly, when we are writing first code using stable?
Other cases
Rust Version
rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: x86_64-pc-windows-msvc
release: 1.84.1
LLVM version: 19.1.5
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing print!(); with the reported Rust 1.84.1 toolchain and inspect the compiler-built-in print macro expansion and its diagnostic path. The issue proposes changing the empty invocation handling or improving the diagnostic and removing confusing notes; done means an empty print!() receives a clearer, intentional diagnostic or warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100