Change:
The following all compile and run for example: I would expect them to produce "error: format argument must be a string literal." like does. This is because they use things like but accepts other literals not just . I assume this isn't intentional.
One way to fix this is to replace 's definition with I would prefer to force and friends to take strings but at least this keeps it consistent. EDIT: I honestly don't like how automatically stringifies, it seems kinda ugly and I feel like there should be a separate macro that does compile-time stringification. This would almost certainly be super backwards-incompatible though.
awesome! Why do the places that need 's stringifying functionality not use so doesn't duplicate functionality? That would solve this issue. EDIT: Turns out is different to , the latter only accepts literals whereas the former will verbatim stringify token trees, such as .
Seems like it'd be a breaking change to "fix" this.
For it is explicit and by design, so that part is no problem.
good point, actually has it's own unintuitive behaviour similar but different to .
Why do we consider that the code like works to be a bug? I understand that forbidding it will make more consistent and explicit but we're trading in some convenience here. The other option could be to make behave in same way.
it's not documented so technically something needs to fixed, even if it's just the documentation. If we make behave the same then surely we'd have to change and as well to keep things consistent and I don't think that's a good idea as this isn't even useful. I think this should either be fixed as a breaking change, I doubt it will break much if any real world code, or just depreciated.
thanks for the clarifications, thats makes sense now. I'm not sure and should behave exactly as and as the two groups of macros serve different purposes. Maybe one more special case doesn't worth it however.
Libs team consensus: while it may be desirable to clean this up, this is not breakage we're willing to take on during the Rust 1.x series. I've a new tag, closed-as-desirable-breakage, to help us track issues like this that we might want to revisit if we ever produce a 2.0 release.
related issue: accepts non-bools
Sadly, has been implemented with this bug, so is also affected: .
This would be improved by

Discussion:
/// ``` #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] <ins> #[allow_internal_unstable] </ins> macro_rules! writeln { ($dst:expr) => ( write!($dst, "n")

($dst:expr,) => ( writeln!($dst) ); <del> ($dst:expr, $fmt:expr) => ( write!($dst, concat!($fmt, "n")) ); ($dst:expr, $fmt:expr, $($arg:tt)*) => ( write!($dst, concat!($fmt, "n"), $($arg)*) </del> <ins> ($dst:expr, $($arg:tt)*) => ( $dst.write_fmt(format_args_nl!($($arg)*)) </ins> ); }

<ins> // Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. use std::fmt::Write; fn main() { println!(0); //~^ ERROR format argument must be a string literal eprintln!('a'); //~^ ERROR format argument must be a string literal let mut s = String::new(); writeln!(s, true).unwrap(); //~^ ERROR format argument must be a string literal } </ins>

<ins> error: format argument must be a string literal --> $DIR/issue-30143.rs:14:14 | LL |     println!(0); |              ^ help: you might be missing a string literal to format with | LL |     println!("{}", 0); |              ^^^^^ error: format argument must be a string literal --> $DIR/issue-30143.rs:16:15 | LL |     eprintln!('a'); |               ^^^ help: you might be missing a string literal to format with | LL |     eprintln!("{}", 'a'); |               ^^^^^ error: format argument must be a string literal --> $DIR/issue-30143.rs:19:17 | LL |     writeln!(s, true).unwrap(); |                 ^^^^ help: you might be missing a string literal to format with | LL |     writeln!(s, "{}", true).unwrap(); |                 ^^^^^ error: aborting due to 3 previous errors </ins>