From b9f272cdc2ac262f533ca1d1e648ec13c02404a4 Mon Sep 17 00:00:00 2001 From: sinkuu Date: Wed, 1 Nov 2017 21:10:48 +0900 Subject: [PATCH] Known problems --- clippy_lints/src/transmute.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index cc8c6d284451..eec633953c79 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -96,11 +96,20 @@ declare_lint! { "transmutes from an integer to a `char`" } -/// **What it does:** Checks for transmutes from a `&[u8] to a `&str`. +/// **What it does:** Checks for transmutes from a `&[u8]` to a `&str`. /// /// **Why is this bad?** Not every byte slice is a valid UTF-8 string. /// -/// **Known problems:** None. +/// **Known problems:** +/// - [`from_utf8`] which this lint suggests using is slower than `transmute` +/// as it needs to validate the input. +/// If you are certain that the input is always a valid UTF-8, +/// use [`from_utf8_unchecked`] which is as fast as `transmute` +/// but has a semantically meaningful name. +/// - You might want to handle errors returned from [`from_utf8`] instead of calling `unwrap`. +/// +/// [`from_utf8`]: https://doc.rust-lang.org/std/str/fn.from_utf8.html +/// [`from_utf8_unchecked`]: https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.html /// /// **Example:** /// ```rust