Fix unused_unsafe
in THIR unsafeck
This commit is contained in:
parent
b0835410bb
commit
f7916b4c9e
@ -42,7 +42,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
|
||||
self.warn_unused_unsafe(
|
||||
hir_id,
|
||||
block_span,
|
||||
Some(self.tcx.sess.source_map().guess_head_span(enclosing_span)),
|
||||
Some((self.tcx.sess.source_map().guess_head_span(enclosing_span), "block")),
|
||||
);
|
||||
f(self);
|
||||
} else {
|
||||
@ -52,7 +52,15 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
|
||||
f(self);
|
||||
|
||||
if let SafetyContext::UnsafeBlock { used: false, span, hir_id } = self.safety_context {
|
||||
self.warn_unused_unsafe(hir_id, span, self.body_unsafety.unsafe_fn_sig_span());
|
||||
self.warn_unused_unsafe(
|
||||
hir_id,
|
||||
span,
|
||||
if self.unsafe_op_in_unsafe_fn_allowed() {
|
||||
self.body_unsafety.unsafe_fn_sig_span().map(|span| (span, "fn"))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
);
|
||||
}
|
||||
self.safety_context = prev_context;
|
||||
return;
|
||||
@ -108,18 +116,15 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
|
||||
&self,
|
||||
hir_id: hir::HirId,
|
||||
block_span: Span,
|
||||
enclosing_span: Option<Span>,
|
||||
enclosing_unsafe: Option<(Span, &'static str)>,
|
||||
) {
|
||||
let block_span = self.tcx.sess.source_map().guess_head_span(block_span);
|
||||
self.tcx.struct_span_lint_hir(UNUSED_UNSAFE, hir_id, block_span, |lint| {
|
||||
let msg = "unnecessary `unsafe` block";
|
||||
let mut db = lint.build(msg);
|
||||
db.span_label(block_span, msg);
|
||||
if let Some(enclosing_span) = enclosing_span {
|
||||
db.span_label(
|
||||
enclosing_span,
|
||||
format!("because it's nested under this `unsafe` block"),
|
||||
);
|
||||
if let Some((span, kind)) = enclosing_unsafe {
|
||||
db.span_label(span, format!("because it's nested under this `unsafe` {}", kind));
|
||||
}
|
||||
db.emit();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user