mirror of
https://github.com/rust-lang/rust
synced 2024-10-04 15:50:51 +00:00
Avoid suggesting to add unsafe when the extern block is already unsafe
This commit is contained in:
parent
a62cbda57e
commit
15d5dac32e
|
@ -459,13 +459,18 @@ fn check_decl_self_param(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
|
|||
fn check_item_safety(&self, span: Span, safety: Safety) {
|
||||
match self.extern_mod_safety {
|
||||
Some(extern_safety) => {
|
||||
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
|
||||
&& (extern_safety == Safety::Default || !self.features.unsafe_extern_blocks)
|
||||
{
|
||||
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_)) {
|
||||
if extern_safety == Safety::Default {
|
||||
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
|
||||
item_span: span,
|
||||
block: self.current_extern_span().shrink_to_lo(),
|
||||
block: Some(self.current_extern_span().shrink_to_lo()),
|
||||
});
|
||||
} else if !self.features.unsafe_extern_blocks {
|
||||
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
|
||||
item_span: span,
|
||||
block: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
|
|
@ -222,7 +222,7 @@ pub struct InvalidSafetyOnExtern {
|
|||
#[primary_span]
|
||||
pub item_span: Span,
|
||||
#[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
|
||||
pub block: Span,
|
||||
pub block: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
@ -19,11 +19,6 @@ error: items in unadorned `extern` blocks cannot have safety qualifiers
|
|||
|
|
||||
LL | unsafe fn foo();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" unsafe {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue