diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index da5abe9578759..8d50f5efa48fe 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -308,6 +308,13 @@ For integral types, this has no meaning currently. For floating-point types, this indicates how many digits after the decimal point should be printed. +## Escaping + +The literal characters `{`, `}`, or `#` may be included in a string by +preceding them with the `\` character. Since `\` is already an +escape character in Rust strings, a string literal using this escape +will look like `"\\{"`. + */ use prelude::*; diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 236fa44939a38..8ed93a13d6088 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -213,6 +213,12 @@ pub fn main() { t!(format!("{:+10.3f}", 1.0f), " +1.000"); t!(format!("{:+10.3f}", -1.0f), " -1.000"); + // Escaping + t!(format!("\\{"), "{"); + t!(format!("\\}"), "}"); + t!(format!("\\#"), "#"); + t!(format!("\\\\"), "\\"); + test_write(); test_print();