]> git.lizzy.rs Git - rust.git/commit
std: Enforce Unicode in fmt::Writer
authorAlex Crichton <alex@alexcrichton.com>
Fri, 12 Dec 2014 18:59:41 +0000 (10:59 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 2 Jan 2015 06:04:46 +0000 (22:04 -0800)
commite423fcf0e0166da55f88233e0be5eacba55bc0bc
tree0c4a4ffadfa870dcf23e1d55b224a1d7c2805f2a
parentcd614164e692cca3a1460737f581fcb6d4630baf
std: Enforce Unicode in fmt::Writer

This commit is an implementation of [RFC 526][rfc] which is a change to alter
the definition of the old `fmt::FormatWriter`. The new trait, renamed to
`Writer`, now only exposes one method `write_str` in order to guarantee that all
implementations of the formatting traits can only produce valid Unicode.

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0526-fmt-text-writer.md

One of the primary improvements of this patch is the performance of the
`.to_string()` method by avoiding an almost-always redundant UTF-8 check. This
is a breaking change due to the renaming of the trait as well as the loss of the
`write` method, but migration paths should be relatively easy:

* All usage of `write` should move to `write_str`. If truly binary data was
  being written in an implementation of `Show`, then it will need to use a
  different trait or an altogether different code path.

* All usage of `write!` should continue to work as-is with no modifications.

* All usage of `Show` where implementations just delegate to another should
  continue to work as-is.

[breaking-change]

Closes #20352
25 files changed:
src/libcollections/string.rs
src/libcollections/vec.rs
src/libcore/fmt/float.rs
src/libcore/fmt/mod.rs
src/libcore/fmt/num.rs
src/librustc_driver/driver.rs
src/librustdoc/html/escape.rs
src/librustdoc/html/format.rs
src/librustdoc/html/markdown.rs
src/librustdoc/html/render.rs
src/librustdoc/lib.rs
src/libserialize/json.rs
src/libstd/failure.rs
src/libstd/fmt.rs
src/libstd/io/mod.rs
src/libstd/rt/unwind.rs
src/libstd/rt/util.rs
src/libsyntax/ast.rs
src/libtest/lib.rs
src/test/compile-fail/variance-trait-matching-2.rs
src/test/run-fail/panic-non-utf8.rs [deleted file]
src/test/run-pass/colorful-write-macros.rs
src/test/run-pass/ifmt.rs
src/test/run-pass/issue-11881.rs
src/test/run-pass/issue-15924.rs