Skip to content

Commit cf5e0b0

Browse files
Rollup merge of rust-lang#112401 - WaffleLapkin:dont_compile_error, r=Nilstrieb
Don't `use compile_error as print` I've spent **1.5 hours** debugging this while trying to compile rust-lang#112400, if we use `compile_error!`, we should not just forward user input to it, but issue a reasonable error message. The better solution would be to use a lint like `clippy::print_stdout`, but since we don't have clippy in CI, let's at least make the macro error better. Also note that some functions called here actually do use `println` (see for example `print_type_sizes` function).
2 parents b3d1a83 + fbe3a47 commit cf5e0b0

File tree

1 file changed

+8
-1
lines changed
  • compiler/rustc_driver_impl/src

1 file changed

+8
-1
lines changed

compiler/rustc_driver_impl/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,18 @@ use std::str;
5858
use std::sync::OnceLock;
5959
use std::time::Instant;
6060

61+
#[allow(unused_macros)]
62+
macro do_not_use_print($($t:tt)*) {
63+
std::compile_error!(
64+
"Don't use `print` or `println` here, use `safe_print` or `safe_println` instead"
65+
)
66+
}
67+
6168
// This import blocks the use of panicking `print` and `println` in all the code
6269
// below. Please use `safe_print` and `safe_println` to avoid ICE when
6370
// encountering an I/O error during print.
6471
#[allow(unused_imports)]
65-
use std::{compile_error as print, compile_error as println};
72+
use {do_not_use_print as print, do_not_use_print as println};
6673

6774
pub mod args;
6875
pub mod pretty;

0 commit comments

Comments
 (0)