Skip to content

Commit 11045f9

Browse files
committed
Don't unnecessarily suggest unsafe block
1 parent 7a80c23 commit 11045f9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

clippy_lints/src/transmute/transmute_ref_to_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(super) fn check<'tcx>(
4141
&format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
4242
"consider using",
4343
if const_context {
44-
format!("unsafe {{ std::str::from_utf8_unchecked{postfix}({snippet}) }}")
44+
format!("std::str::from_utf8_unchecked{postfix}({snippet})")
4545
} else {
4646
format!("std::str::from_utf8{postfix}({snippet}).unwrap()")
4747
},

tests/ui/transmute.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ error: transmute from a `&[u8]` to a `&str`
244244
--> $DIR/transmute.rs:142:30
245245
|
246246
LL | const _: &str = unsafe { std::mem::transmute(B) };
247-
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `unsafe { std::str::from_utf8_unchecked(B) }`
247+
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)`
248248

249249
error: aborting due to 39 previous errors
250250

0 commit comments

Comments
 (0)