Skip to content

Commit 491bfd6

Browse files
committed
for crater: make this a hard error
1 parent f2a830b commit 491bfd6

File tree

6 files changed

+9
-35
lines changed

6 files changed

+9
-35
lines changed

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,16 +638,12 @@ pub(super) fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: LocalDefId) {
638638
let c_int = Size::from_bits(tcx.sess.target.c_int_width);
639639
if discr_val < c_int.signed_int_min() || discr_val > c_int.signed_int_max() {
640640
let span = tcx.def_span(variant.def_id);
641-
tcx.node_span_lint(
642-
rustc_session::lint::builtin::REPR_C_ENUMS_LARGER_THAN_INT,
643-
tcx.local_def_id_to_hir_id(def_id),
644-
span,
645-
|d| {
646-
d.primary_message("`repr(C)` enum discriminant does not fit into C `int`")
647-
.note("`repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C")
648-
.help("use `repr($int_ty)` instead to explicitly set the size of this enum");
649-
}
650-
);
641+
let mut d = tcx
642+
.dcx()
643+
.struct_span_err(span, "`repr(C)` enum discriminant does not fit into C `int`");
644+
d.note("`repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C")
645+
.help("use `repr($int_ty)` instead to explicitly set the size of this enum");
646+
d.emit();
651647
}
652648
}
653649

tests/ui/enum-discriminant/repr-c-big-discriminant1.ptr32.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | A = 9223372036854775807, // i64::MAX
88
= note: `#[deny(overflowing_literals)]` on by default
99

1010
error: literal out of range for `isize`
11-
--> $DIR/repr-c-big-discriminant1.rs:24:9
11+
--> $DIR/repr-c-big-discriminant1.rs:23:9
1212
|
1313
LL | A = -2147483649, // i32::MIN-1
1414
| ^^^^^^^^^^^

tests/ui/enum-discriminant/repr-c-big-discriminant1.ptr64.stderr

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,24 @@ error: `repr(C)` enum discriminant does not fit into C `int`
44
LL | A = 9223372036854775807, // i64::MAX
55
| ^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #124403 <https://github.com/rust-lang/rust/issues/124403>
97
= note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C
108
= help: use `repr($int_ty)` instead to explicitly set the size of this enum
11-
note: the lint level is defined here
12-
--> $DIR/repr-c-big-discriminant1.rs:6:9
13-
|
14-
LL | #![deny(repr_c_enums_larger_than_int)]
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
169

1710
error: `repr(C)` enum discriminant does not fit into C `int`
18-
--> $DIR/repr-c-big-discriminant1.rs:24:5
11+
--> $DIR/repr-c-big-discriminant1.rs:23:5
1912
|
2013
LL | A = -2147483649, // i32::MIN-1
2114
| ^
2215
|
23-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24-
= note: for more information, see issue #124403 <https://github.com/rust-lang/rust/issues/124403>
2516
= note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C
2617
= help: use `repr($int_ty)` instead to explicitly set the size of this enum
2718

2819
error: `repr(C)` enum discriminant does not fit into C `int`
29-
--> $DIR/repr-c-big-discriminant1.rs:34:5
20+
--> $DIR/repr-c-big-discriminant1.rs:32:5
3021
|
3122
LL | A = I64_MAX as isize,
3223
| ^
3324
|
34-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
35-
= note: for more information, see issue #124403 <https://github.com/rust-lang/rust/issues/124403>
3625
= note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C
3726
= help: use `repr($int_ty)` instead to explicitly set the size of this enum
3827

tests/ui/enum-discriminant/repr-c-big-discriminant1.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ enum OverflowingEnum1 {
1616
A = 9223372036854775807, // i64::MAX
1717
//[ptr32]~^ ERROR: literal out of range
1818
//[ptr64]~^^ ERROR: discriminant does not fit into C `int`
19-
//[ptr64]~^^^ WARN: previously accepted
2019
}
2120

2221
#[repr(C)]
2322
enum OverflowingEnum2 {
2423
A = -2147483649, // i32::MIN-1
2524
//[ptr32]~^ ERROR: literal out of range
2625
//[ptr64]~^^ ERROR: discriminant does not fit into C `int`
27-
//[ptr64]~^^^ WARN: previously accepted
2826
}
2927

3028
const I64_MAX: i64 = 9223372036854775807;
@@ -33,7 +31,6 @@ const I64_MAX: i64 = 9223372036854775807;
3331
enum OverflowingEnum3 {
3432
A = I64_MAX as isize,
3533
//[ptr64]~^ ERROR: discriminant does not fit into C `int`
36-
//[ptr64]~^^ WARN: previously accepted
3734
// No warning/error on 32bit targets, but the `as isize` hints that wrapping is occurring.
3835
}
3936

tests/ui/enum-discriminant/repr-c-big-discriminant2.ptr64.stderr

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@ error: `repr(C)` enum discriminant does not fit into C `int`
44
LL | B, // +1
55
| ^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #124403 <https://github.com/rust-lang/rust/issues/124403>
97
= note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C
108
= help: use `repr($int_ty)` instead to explicitly set the size of this enum
11-
note: the lint level is defined here
12-
--> $DIR/repr-c-big-discriminant2.rs:6:9
13-
|
14-
LL | #![deny(repr_c_enums_larger_than_int)]
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
169

1710
error: aborting due to 1 previous error
1811

tests/ui/enum-discriminant/repr-c-big-discriminant2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ enum OverflowingEnum {
1919
B, // +1
2020
//[ptr32]~^ ERROR: enum discriminant overflowed
2121
//[ptr64]~^^ ERROR: discriminant does not fit into C `int`
22-
//[ptr64]~^^^ WARN: previously accepted
2322
}
2423

2524
fn main() {}

0 commit comments

Comments
 (0)