Skip to content

Commit 9b1f20d

Browse files
committed
deny-by-default & report in deps uninhabited_static
1 parent 8931f23 commit 9b1f20d

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,12 +2718,13 @@ declare_lint! {
27182718
///
27192719
/// ### Example
27202720
///
2721-
/// ```rust
2721+
#[cfg_attr(bootstrap, doc = "```rust")]
2722+
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
27222723
/// enum Void {}
27232724
/// unsafe extern {
27242725
/// static EXTERN: Void;
27252726
/// }
2726-
/// ```
2727+
#[doc = "```"]
27272728
///
27282729
/// {{produces}}
27292730
///
@@ -2734,10 +2735,11 @@ declare_lint! {
27342735
/// compiler which assumes that there are no initialized uninhabited places (such as locals or
27352736
/// statics). This was accidentally allowed, but is being phased out.
27362737
pub UNINHABITED_STATIC,
2737-
Warn,
2738+
Deny,
27382739
"uninhabited static",
27392740
@future_incompatible = FutureIncompatibleInfo {
27402741
reason: fcw!(FutureReleaseError #74840),
2742+
report_in_deps: true,
27412743
};
27422744
}
27432745

tests/ui/statics/uninhabited-static.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(never_type)]
2-
#![deny(uninhabited_static)]
32

43
enum Void {}
54
extern "C" {
Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
error: static of uninhabited type
2-
--> $DIR/uninhabited-static.rs:12:1
2+
--> $DIR/uninhabited-static.rs:11:1
33
|
44
LL | static VOID2: Void = unsafe { std::mem::transmute(()) };
55
| ^^^^^^^^^^^^^^^^^^
66
|
77
= note: uninhabited statics cannot be initialized, and any access would be an immediate error
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
10-
note: the lint level is defined here
11-
--> $DIR/uninhabited-static.rs:2:9
12-
|
13-
LL | #![deny(uninhabited_static)]
14-
| ^^^^^^^^^^^^^^^^^^
10+
= note: `#[deny(uninhabited_static)]` (part of `#[deny(future_incompatible)]`) on by default
1511

1612
error: static of uninhabited type
17-
--> $DIR/uninhabited-static.rs:15:1
13+
--> $DIR/uninhabited-static.rs:14:1
1814
|
1915
LL | static NEVER2: Void = unsafe { std::mem::transmute(()) };
2016
| ^^^^^^^^^^^^^^^^^^^
@@ -24,7 +20,7 @@ LL | static NEVER2: Void = unsafe { std::mem::transmute(()) };
2420
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
2521

2622
error: static of uninhabited type
27-
--> $DIR/uninhabited-static.rs:6:5
23+
--> $DIR/uninhabited-static.rs:5:5
2824
|
2925
LL | static VOID: Void;
3026
| ^^^^^^^^^^^^^^^^^
@@ -34,7 +30,7 @@ LL | static VOID: Void;
3430
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
3531

3632
error: static of uninhabited type
37-
--> $DIR/uninhabited-static.rs:8:5
33+
--> $DIR/uninhabited-static.rs:7:5
3834
|
3935
LL | static NEVER: !;
4036
| ^^^^^^^^^^^^^^^
@@ -44,17 +40,65 @@ LL | static NEVER: !;
4440
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
4541

4642
error[E0080]: constructing invalid value of type Void: encountered a value of uninhabited type `Void`
47-
--> $DIR/uninhabited-static.rs:12:31
43+
--> $DIR/uninhabited-static.rs:11:31
4844
|
4945
LL | static VOID2: Void = unsafe { std::mem::transmute(()) };
5046
| ^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `VOID2` failed here
5147

5248
error[E0080]: constructing invalid value of type Void: encountered a value of uninhabited type `Void`
53-
--> $DIR/uninhabited-static.rs:15:32
49+
--> $DIR/uninhabited-static.rs:14:32
5450
|
5551
LL | static NEVER2: Void = unsafe { std::mem::transmute(()) };
5652
| ^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `NEVER2` failed here
5753

5854
error: aborting due to 6 previous errors
5955

6056
For more information about this error, try `rustc --explain E0080`.
57+
Future incompatibility report: Future breakage diagnostic:
58+
error: static of uninhabited type
59+
--> $DIR/uninhabited-static.rs:11:1
60+
|
61+
LL | static VOID2: Void = unsafe { std::mem::transmute(()) };
62+
| ^^^^^^^^^^^^^^^^^^
63+
|
64+
= note: uninhabited statics cannot be initialized, and any access would be an immediate error
65+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
66+
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
67+
= note: `#[deny(uninhabited_static)]` (part of `#[deny(future_incompatible)]`) on by default
68+
69+
Future breakage diagnostic:
70+
error: static of uninhabited type
71+
--> $DIR/uninhabited-static.rs:14:1
72+
|
73+
LL | static NEVER2: Void = unsafe { std::mem::transmute(()) };
74+
| ^^^^^^^^^^^^^^^^^^^
75+
|
76+
= note: uninhabited statics cannot be initialized, and any access would be an immediate error
77+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
78+
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
79+
= note: `#[deny(uninhabited_static)]` (part of `#[deny(future_incompatible)]`) on by default
80+
81+
Future breakage diagnostic:
82+
error: static of uninhabited type
83+
--> $DIR/uninhabited-static.rs:5:5
84+
|
85+
LL | static VOID: Void;
86+
| ^^^^^^^^^^^^^^^^^
87+
|
88+
= note: uninhabited statics cannot be initialized, and any access would be an immediate error
89+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
90+
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
91+
= note: `#[deny(uninhabited_static)]` (part of `#[deny(future_incompatible)]`) on by default
92+
93+
Future breakage diagnostic:
94+
error: static of uninhabited type
95+
--> $DIR/uninhabited-static.rs:7:5
96+
|
97+
LL | static NEVER: !;
98+
| ^^^^^^^^^^^^^^^
99+
|
100+
= note: uninhabited statics cannot be initialized, and any access would be an immediate error
101+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
102+
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
103+
= note: `#[deny(uninhabited_static)]` (part of `#[deny(future_incompatible)]`) on by default
104+

0 commit comments

Comments
 (0)