Skip to content

Commit 7eb6ce7

Browse files
authored
Fix {,e}println!() (rust-lang#3209)
GitHub closed the previous PR (rust-lang#3205) after I renamed a branch, hooray. Change the implementation of `println!` & `eprintln!` with no arguments to call `print!("\n")` & `eprint!("\n")` respectively instead of producing no tokens. This is what std does. [^println][^eprintln] [^println]: https://github.com/rust-lang/rust/blob/8c127df75fde3d5ad8ef9af664962a7676288b52/library/std/src/macros.rs#L140 [^eprintln]: https://github.com/rust-lang/rust/blob/8c127df75fde3d5ad8ef9af664962a7676288b52/library/std/src/macros.rs#L218 Resolves rust-lang#3204. A test included, as per model-checking/kani#3205 (comment)
1 parent f10e61c commit 7eb6ce7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

library/std/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ macro_rules! eprint {
135135
#[cfg(not(feature = "concrete_playback"))]
136136
#[macro_export]
137137
macro_rules! println {
138-
() => { };
138+
() => { $crate::print!("\n") };
139139
($($x:tt)*) => {{ let _ = format_args!($($x)*); }};
140140
}
141141

142142
#[cfg(not(feature = "concrete_playback"))]
143143
#[macro_export]
144144
macro_rules! eprintln {
145-
() => { };
145+
() => { $crate::eprint!("\n") };
146146
($($x:tt)*) => {{ let _ = format_args!($($x)*); }};
147147
}
148148

tests/kani/Print/no_semicolon.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// This test checks that the (e)println with no arguments do not require a trailing semicolon
5+
6+
fn println() {
7+
println!()
8+
}
9+
fn eprintln() {
10+
eprintln!()
11+
}
12+
13+
#[kani::proof]
14+
fn main() {
15+
println();
16+
eprintln();
17+
}

0 commit comments

Comments
 (0)