Don't unnecessarily suggest unsafe block

This commit is contained in:
SabrinaJewson 2022-04-01 06:32:22 +01:00
parent 7a80c23f83
commit 11045f94e2
No known key found for this signature in database
GPG Key ID: 3D5438FFA5F05564
2 changed files with 2 additions and 2 deletions

View File

@ -41,7 +41,7 @@ pub(super) fn check<'tcx>(
&format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
"consider using",
if const_context {
format!("unsafe {{ std::str::from_utf8_unchecked{postfix}({snippet}) }}")
format!("std::str::from_utf8_unchecked{postfix}({snippet})")
} else {
format!("std::str::from_utf8{postfix}({snippet}).unwrap()")
},

View File

@ -244,7 +244,7 @@ error: transmute from a `&[u8]` to a `&str`
--> $DIR/transmute.rs:142:30
|
LL | const _: &str = unsafe { std::mem::transmute(B) };
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `unsafe { std::str::from_utf8_unchecked(B) }`
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)`
error: aborting due to 39 previous errors