Skip to content

Commit e8b6860

Browse files
authored
Unrolled build for rust-lang#127535
Rollup merge of rust-lang#127535 - spastorino:unsafe_code-unsafe_extern_blocks, r=oli-obk Fire unsafe_code lint on unsafe extern blocks Fixes rust-lang#126738
2 parents c6727fc + a3ef94e commit e8b6860

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

compiler/rustc_lint/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ lint_builtin_unreachable_pub = unreachable `pub` {$what}
163163
164164
lint_builtin_unsafe_block = usage of an `unsafe` block
165165
166+
lint_builtin_unsafe_extern_block = usage of an `unsafe extern` block
167+
166168
lint_builtin_unsafe_impl = implementation of an `unsafe` trait
167169
168170
lint_builtin_unsafe_trait = declaration of an `unsafe` trait

compiler/rustc_lint/src/builtin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ impl EarlyLintPass for UnsafeCode {
326326
self.report_unsafe(cx, it.span, BuiltinUnsafe::GlobalAsm);
327327
}
328328

329+
ast::ItemKind::ForeignMod(ForeignMod { safety, .. }) => {
330+
if let Safety::Unsafe(_) = safety {
331+
self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeExternBlock);
332+
}
333+
}
334+
329335
_ => {}
330336
}
331337
}

compiler/rustc_lint/src/lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub enum BuiltinUnsafe {
8181
AllowInternalUnsafe,
8282
#[diag(lint_builtin_unsafe_block)]
8383
UnsafeBlock,
84+
#[diag(lint_builtin_unsafe_extern_block)]
85+
UnsafeExternBlock,
8486
#[diag(lint_builtin_unsafe_trait)]
8587
UnsafeTrait,
8688
#[diag(lint_builtin_unsafe_impl)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(unsafe_extern_blocks)]
2+
#![deny(unsafe_code)]
3+
4+
#[allow(unsafe_code)]
5+
unsafe extern "C" {
6+
fn foo();
7+
}
8+
9+
unsafe extern "C" {
10+
//~^ ERROR usage of an `unsafe extern` block [unsafe_code]
11+
fn bar();
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: usage of an `unsafe extern` block
2+
--> $DIR/unsafe-extern-blocks.rs:9:1
3+
|
4+
LL | / unsafe extern "C" {
5+
LL | |
6+
LL | | fn bar();
7+
LL | | }
8+
| |_^
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/unsafe-extern-blocks.rs:2:9
12+
|
13+
LL | #![deny(unsafe_code)]
14+
| ^^^^^^^^^^^
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)