Add note about unsafe functions body not being unsafe

This commit is contained in:
Wim Looman 2023-05-27 22:20:14 +02:00
parent 62a712a8bb
commit 8f3e876e52
No known key found for this signature in database
GPG key ID: C6F5748C6DD1607B
7 changed files with 89 additions and 22 deletions

View file

@ -131,7 +131,12 @@ impl RequiresUnsafeDetail {
pub(crate) struct UnsafeOpInUnsafeFn {
pub details: RequiresUnsafeDetail,
pub suggest_unsafe_block: Option<(Span, Span)>,
/// These spans point to:
/// 1. the start of the function body
/// 2. the end of the function body
/// 3. the function signature
pub suggest_unsafe_block: Option<(Span, Span, Span)>,
}
impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
@ -146,7 +151,8 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
diag.span_label(self.details.span, self.details.label());
diag.note(self.details.note());
if let Some((start, end)) = self.suggest_unsafe_block {
if let Some((start, end, fn_sig)) = self.suggest_unsafe_block {
diag.span_note(fn_sig, crate::fluent_generated::mir_transform_note);
diag.tool_only_multipart_suggestion(
crate::fluent_generated::mir_transform_suggestion,
vec![(start, " unsafe {".into()), (end, "}".into())],