Skip to content

Commit 98d2c51

Browse files
committed
safe_extern_static -> error
1 parent 79b35e9 commit 98d2c51

File tree

13 files changed

+57
-94
lines changed

13 files changed

+57
-94
lines changed

src/doc/rustc/src/lints/listing/deny-by-default.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ To fix it, remove the `()`s.
151151

152152
This lint detects a specific situation of re-exporting a private `extern crate`;
153153

154-
## safe-extern-statics
155-
156-
In older versions of Rust, there was a soundness issue where `extern static`s were allowed
157-
to be accessed in safe code. This lint now catches and denies this kind of code.
158-
159154
## unknown-crate-types
160155

161156
This lint detects an unknown crate type found in a `#[crate_type]` directive. Some

src/librustc/lint/builtin.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,6 @@ declare_lint! {
177177
"lints that have been renamed or removed"
178178
}
179179

180-
declare_lint! {
181-
pub SAFE_EXTERN_STATICS,
182-
Deny,
183-
"safe access to extern statics was erroneously allowed",
184-
@future_incompatible = FutureIncompatibleInfo {
185-
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/36247>",
186-
edition: None,
187-
};
188-
}
189-
190180
declare_lint! {
191181
pub SAFE_PACKED_BORROWS,
192182
Warn,
@@ -535,7 +525,6 @@ declare_lint_pass! {
535525
INVALID_TYPE_PARAM_DEFAULT,
536526
CONST_ERR,
537527
RENAMED_AND_REMOVED_LINTS,
538-
SAFE_EXTERN_STATICS,
539528
SAFE_PACKED_BORROWS,
540529
PATTERNS_IN_FNS_WITHOUT_BODY,
541530
MISSING_FRAGMENT_SPECIFIER,

src/librustc/mir/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,6 @@ pub enum UnsafetyViolationKind {
27012701
General,
27022702
/// Permitted both in `const fn`s and regular `fn`s.
27032703
GeneralAndConstFn,
2704-
ExternStatic(hir::HirId),
27052704
BorrowPacked(hir::HirId),
27062705
}
27072706

src/librustc_lint/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) {
338338
"converted into hard error, see https://github.com/rust-lang/rust/issues/39207");
339339
store.register_removed("legacy_disrectory_ownership",
340340
"converted into hard error, see https://github.com/rust-lang/rust/issues/37872");
341+
store.register_removed("safe_extern_statics",
342+
"converted into hard error, see https://github.com/rust-lang/rust/issues/36247");
341343
}
342344

343345
fn register_internals(store: &mut lint::LintStore) {

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc::ty::cast::CastTy;
88
use rustc::hir;
99
use rustc::hir::Node;
1010
use rustc::hir::def_id::DefId;
11-
use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSAFE};
11+
use rustc::lint::builtin::{SAFE_PACKED_BORROWS, UNUSED_UNSAFE};
1212
use rustc::mir::*;
1313
use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext};
1414

@@ -208,23 +208,20 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
208208
}
209209
PlaceBase::Static(box Static { kind: StaticKind::Static, def_id, .. }) => {
210210
if self.tcx.is_mutable_static(def_id) {
211-
self.require_unsafe("use of mutable static",
211+
self.require_unsafe(
212+
"use of mutable static",
212213
"mutable statics can be mutated by multiple threads: aliasing \
213-
violations or data races will cause undefined behavior",
214-
UnsafetyViolationKind::General);
214+
violations or data races will cause undefined behavior",
215+
UnsafetyViolationKind::General,
216+
);
215217
} else if self.tcx.is_foreign_item(def_id) {
216-
let source_info = self.source_info;
217-
let lint_root =
218-
self.source_scope_local_data[source_info.scope].lint_root;
219-
self.register_violations(&[UnsafetyViolation {
220-
source_info,
221-
description: Symbol::intern("use of extern static"),
222-
details: Symbol::intern(
223-
"extern statics are not controlled by the Rust type system: \
224-
invalid data, aliasing violations or data races will cause \
225-
undefined behavior"),
226-
kind: UnsafetyViolationKind::ExternStatic(lint_root)
227-
}], &[]);
218+
self.require_unsafe(
219+
"use of extern static",
220+
"extern statics are not controlled by the Rust type system: \
221+
invalid data, aliasing violations or data races will cause \
222+
undefined behavior",
223+
UnsafetyViolationKind::General,
224+
);
228225
}
229226
}
230227
}
@@ -351,8 +348,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
351348
match violation.kind {
352349
UnsafetyViolationKind::GeneralAndConstFn |
353350
UnsafetyViolationKind::General => {},
354-
UnsafetyViolationKind::BorrowPacked(_) |
355-
UnsafetyViolationKind::ExternStatic(_) => if self.min_const_fn {
351+
UnsafetyViolationKind::BorrowPacked(_) => if self.min_const_fn {
356352
// const fns don't need to be backwards compatible and can
357353
// emit these violations as a hard error instead of a backwards
358354
// compat lint
@@ -380,8 +376,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
380376
UnsafetyViolationKind::GeneralAndConstFn => {},
381377
// these things are forbidden in const fns
382378
UnsafetyViolationKind::General |
383-
UnsafetyViolationKind::BorrowPacked(_) |
384-
UnsafetyViolationKind::ExternStatic(_) => {
379+
UnsafetyViolationKind::BorrowPacked(_) => {
385380
let mut violation = violation.clone();
386381
// const fns don't need to be backwards compatible and can
387382
// emit these violations as a hard error instead of a backwards
@@ -646,14 +641,6 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
646641
.note(&details.as_str())
647642
.emit();
648643
}
649-
UnsafetyViolationKind::ExternStatic(lint_hir_id) => {
650-
tcx.lint_node_note(SAFE_EXTERN_STATICS,
651-
lint_hir_id,
652-
source_info.span,
653-
&format!("{} is unsafe and requires unsafe function or block \
654-
(error E0133)", description),
655-
&details.as_str());
656-
}
657644
UnsafetyViolationKind::BorrowPacked(lint_hir_id) => {
658645
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
659646
tcx.unsafe_derive_on_repr_packed(impl_def_id);

src/test/ui/issues/issue-14227.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
#![allow(safe_extern_statics, warnings)]
2-
31
extern {
42
pub static symbol: u32;
53
}
64
static CRASH: u32 = symbol;
7-
//~^ ERROR could not evaluate static initializer
8-
//~| tried to read from foreign (extern) static
5+
//~^ ERROR use of extern static is unsafe and requires
96

107
fn main() {}

src/test/ui/issues/issue-14227.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
error[E0080]: could not evaluate static initializer
2-
--> $DIR/issue-14227.rs:6:21
1+
error[E0133]: use of extern static is unsafe and requires unsafe function or block
2+
--> $DIR/issue-14227.rs:4:21
33
|
44
LL | static CRASH: u32 = symbol;
5-
| ^^^^^^ tried to read from foreign (extern) static
5+
| ^^^^^^ use of extern static
6+
|
7+
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
68

79
error: aborting due to previous error
810

9-
For more information about this error, try `rustc --explain E0080`.
11+
For more information about this error, try `rustc --explain E0133`.

src/test/ui/issues/issue-16538.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(safe_extern_statics)]
2-
31
mod Y {
42
pub type X = usize;
53
extern {
@@ -13,5 +11,6 @@ mod Y {
1311
static foo: *const Y::X = Y::foo(Y::x as *const Y::X);
1412
//~^ ERROR `*const usize` cannot be shared between threads safely [E0277]
1513
//~| ERROR E0015
14+
//~| ERROR use of extern static is unsafe and requires
1615

1716
fn main() {}

src/test/ui/issues/issue-16538.stderr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
2-
--> $DIR/issue-16538.rs:13:27
2+
--> $DIR/issue-16538.rs:11:27
33
|
44
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error[E0277]: `*const usize` cannot be shared between threads safely
8-
--> $DIR/issue-16538.rs:13:1
8+
--> $DIR/issue-16538.rs:11:1
99
|
1010
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X);
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely
1212
|
1313
= help: the trait `std::marker::Sync` is not implemented for `*const usize`
1414
= note: shared static variables must have a type that implements `Sync`
1515

16-
error: aborting due to 2 previous errors
16+
error[E0133]: use of extern static is unsafe and requires unsafe function or block
17+
--> $DIR/issue-16538.rs:11:34
18+
|
19+
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X);
20+
| ^^^^ use of extern static
21+
|
22+
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
23+
24+
error: aborting due to 3 previous errors
1725

18-
Some errors have detailed explanations: E0015, E0277.
26+
Some errors have detailed explanations: E0015, E0133, E0277.
1927
For more information about an error, try `rustc --explain E0015`.

src/test/ui/issues/issue-28324.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#![allow(safe_extern_statics)]
2-
31
extern {
42
static error_message_count: u32;
53
}
64

75
pub static BAZ: u32 = *&error_message_count;
8-
//~^ ERROR could not evaluate static initializer
9-
//~| tried to read from foreign (extern) static
6+
//~^ ERROR use of extern static is unsafe and requires
107

118
fn main() {}

src/test/ui/issues/issue-28324.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
error[E0080]: could not evaluate static initializer
2-
--> $DIR/issue-28324.rs:7:23
1+
error[E0133]: use of extern static is unsafe and requires unsafe function or block
2+
--> $DIR/issue-28324.rs:5:24
33
|
44
LL | pub static BAZ: u32 = *&error_message_count;
5-
| ^^^^^^^^^^^^^^^^^^^^^ tried to read from foreign (extern) static
5+
| ^^^^^^^^^^^^^^^^^^^^ use of extern static
6+
|
7+
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
68

79
error: aborting due to previous error
810

9-
For more information about this error, try `rustc --explain E0080`.
11+
For more information about this error, try `rustc --explain E0133`.

src/test/ui/safe-extern-statics.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// aux-build:extern-statics.rs
22

3-
#![allow(unused)]
4-
53
extern crate extern_statics;
64
use extern_statics::*;
75

@@ -11,11 +9,7 @@ extern {
119

1210
fn main() {
1311
let a = A; //~ ERROR use of extern static is unsafe
14-
//~^ WARN this was previously accepted by the compiler
1512
let ra = &A; //~ ERROR use of extern static is unsafe
16-
//~^ WARN this was previously accepted by the compiler
1713
let xa = XA; //~ ERROR use of extern static is unsafe
18-
//~^ WARN this was previously accepted by the compiler
1914
let xra = &XA; //~ ERROR use of extern static is unsafe
20-
//~^ WARN this was previously accepted by the compiler
2115
}
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,35 @@
1-
error: use of extern static is unsafe and requires unsafe function or block (error E0133)
2-
--> $DIR/safe-extern-statics.rs:13:13
1+
error[E0133]: use of extern static is unsafe and requires unsafe function or block
2+
--> $DIR/safe-extern-statics.rs:11:13
33
|
44
LL | let a = A;
5-
| ^
5+
| ^ use of extern static
66
|
7-
= note: `#[deny(safe_extern_statics)]` on by default
8-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9-
= note: for more information, see issue #36247 <https://github.com/rust-lang/rust/issues/36247>
107
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
118

12-
error: use of extern static is unsafe and requires unsafe function or block (error E0133)
13-
--> $DIR/safe-extern-statics.rs:15:14
9+
error[E0133]: use of extern static is unsafe and requires unsafe function or block
10+
--> $DIR/safe-extern-statics.rs:12:14
1411
|
1512
LL | let ra = &A;
16-
| ^^
13+
| ^^ use of extern static
1714
|
18-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
19-
= note: for more information, see issue #36247 <https://github.com/rust-lang/rust/issues/36247>
2015
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
2116

22-
error: use of extern static is unsafe and requires unsafe function or block (error E0133)
23-
--> $DIR/safe-extern-statics.rs:17:14
17+
error[E0133]: use of extern static is unsafe and requires unsafe function or block
18+
--> $DIR/safe-extern-statics.rs:13:14
2419
|
2520
LL | let xa = XA;
26-
| ^^
21+
| ^^ use of extern static
2722
|
28-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
29-
= note: for more information, see issue #36247 <https://github.com/rust-lang/rust/issues/36247>
3023
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
3124

32-
error: use of extern static is unsafe and requires unsafe function or block (error E0133)
33-
--> $DIR/safe-extern-statics.rs:19:15
25+
error[E0133]: use of extern static is unsafe and requires unsafe function or block
26+
--> $DIR/safe-extern-statics.rs:14:15
3427
|
3528
LL | let xra = &XA;
36-
| ^^^
29+
| ^^^ use of extern static
3730
|
38-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
39-
= note: for more information, see issue #36247 <https://github.com/rust-lang/rust/issues/36247>
4031
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
4132

4233
error: aborting due to 4 previous errors
4334

35+
For more information about this error, try `rustc --explain E0133`.

0 commit comments

Comments
 (0)