1
Fork 0

Allow unsafe extern on all editions

This commit is contained in:
Santiago Pastorino 2024-04-24 19:10:14 -03:00
parent 68b0b86c5b
commit 6d670b74e5
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
7 changed files with 11 additions and 36 deletions

View file

@ -1016,15 +1016,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
walk_list!(self, visit_attribute, &item.attrs); walk_list!(self, visit_attribute, &item.attrs);
return; // Avoid visiting again. return; // Avoid visiting again.
} }
ItemKind::ForeignMod(ForeignMod { abi, safety, .. }) => { ItemKind::ForeignMod(ForeignMod { abi, .. }) => {
let old_item = mem::replace(&mut self.extern_mod, Some(item)); let old_item = mem::replace(&mut self.extern_mod, Some(item));
self.visibility_not_permitted( self.visibility_not_permitted(
&item.vis, &item.vis,
errors::VisibilityNotPermittedNote::IndividualForeignItems, errors::VisibilityNotPermittedNote::IndividualForeignItems,
); );
if let &Safety::Unsafe(span) = safety {
self.dcx().emit_err(errors::UnsafeItem { span, kind: "extern block" });
}
if abi.is_none() { if abi.is_none() {
self.maybe_lint_missing_abi(item.span, item.id); self.maybe_lint_missing_abi(item.span, item.id);
} }

View file

@ -1,8 +1,7 @@
extern "C" unsafe { extern "C" unsafe {
//~^ ERROR expected `{`, found keyword `unsafe` //~^ ERROR expected `{`, found keyword `unsafe`
//~| ERROR extern block cannot be declared unsafe
unsafe fn foo(); unsafe fn foo();
//~^ ERROR functions in `extern` blocks cannot have qualifiers //~^ ERROR functions in `extern` blocks cannot have qualifiers
} }
fn main() {} fn main() {}

View file

@ -4,20 +4,14 @@ error: expected `{`, found keyword `unsafe`
LL | extern "C" unsafe { LL | extern "C" unsafe {
| ^^^^^^ expected `{` | ^^^^^^ expected `{`
error: extern block cannot be declared unsafe
--> $DIR/unsafe-foreign-mod-2.rs:1:12
|
LL | extern "C" unsafe {
| ^^^^^^
error: functions in `extern` blocks cannot have qualifiers error: functions in `extern` blocks cannot have qualifiers
--> $DIR/unsafe-foreign-mod-2.rs:4:5 --> $DIR/unsafe-foreign-mod-2.rs:3:5
| |
LL | extern "C" unsafe { LL | extern "C" unsafe {
| ----------------- in this `extern` block | ----------------- in this `extern` block
... LL |
LL | unsafe fn foo(); LL | unsafe fn foo();
| ^^^^^^ help: remove this qualifier | ^^^^^^ help: remove this qualifier
error: aborting due to 3 previous errors error: aborting due to 2 previous errors

View file

@ -1,5 +1,5 @@
unsafe extern "C" { //@ build-pass
//~^ ERROR extern block cannot be declared unsafe
} unsafe extern "C" {}
fn main() {} fn main() {}

View file

@ -1,8 +0,0 @@
error: extern block cannot be declared unsafe
--> $DIR/unsafe-foreign-mod.rs:1:1
|
LL | unsafe extern "C" {
| ^^^^^^
error: aborting due to 1 previous error

View file

@ -1,10 +1,11 @@
//@ build-pass
extern "C" { extern "C" {
static TEST1: i32; static TEST1: i32;
fn test1(i: i32); fn test1(i: i32);
} }
unsafe extern "C" { unsafe extern "C" {
//~^ ERROR: extern block cannot be declared unsafe
static TEST2: i32; static TEST2: i32;
fn test2(i: i32); fn test2(i: i32);
} }

View file

@ -1,8 +0,0 @@
error: extern block cannot be declared unsafe
--> $DIR/extern-items.rs:6:1
|
LL | unsafe extern "C" {
| ^^^^^^
error: aborting due to 1 previous error