Skip to content

Commit 24d6a9a

Browse files
committed
for crater: make this lint a hard error
1 parent 5bd164b commit 24d6a9a

File tree

5 files changed

+32
-106
lines changed

5 files changed

+32
-106
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_hir::def::{CtorKind, DefKind};
1212
use rustc_hir::{LangItem, Node, attrs, find_attr, intravisit};
1313
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
1414
use rustc_infer::traits::{Obligation, ObligationCauseCode, WellFormedLoc};
15-
use rustc_lint_defs::builtin::{
16-
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, UNSUPPORTED_CALLING_CONVENTIONS,
17-
};
15+
use rustc_lint_defs::builtin::UNSUPPORTED_CALLING_CONVENTIONS;
1816
use rustc_middle::hir::nested_filter;
1917
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
2018
use rustc_middle::middle::stability::EvalResult;
@@ -1603,29 +1601,24 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
16031601
// If there are any non-trivial fields, then there can be no non-exhaustive 1-zsts.
16041602
// Otherwise, it's only an issue if there's >1 non-exhaustive 1-zst.
16051603
if non_trivial_count > 0 || prev_unsuited_1zst {
1606-
tcx.node_span_lint(
1607-
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
1608-
tcx.local_def_id_to_hir_id(adt.did().expect_local()),
1604+
let mut diag = tcx.dcx().struct_span_err(
16091605
span,
1610-
|lint| {
1611-
lint.primary_message(
1612-
"zero-sized fields in `repr(transparent)` cannot \
1606+
"zero-sized fields in `repr(transparent)` cannot \
16131607
contain external non-exhaustive types",
1614-
);
1615-
let note = match unsuited.reason {
1616-
UnsuitedReason::NonExhaustive => "is marked with `#[non_exhaustive]`",
1617-
UnsuitedReason::PrivateField => "contains private fields",
1618-
UnsuitedReason::ReprC => "is marked with `#[repr(C)]`",
1619-
};
1620-
let field_ty = tcx.def_path_str_with_args(unsuited.def_id, unsuited.args);
1621-
lint.note(format!(
1622-
"this {descr} contains `{field_ty}`, which {note}, \
1608+
);
1609+
let note = match unsuited.reason {
1610+
UnsuitedReason::NonExhaustive => "is marked with `#[non_exhaustive]`",
1611+
UnsuitedReason::PrivateField => "contains private fields",
1612+
UnsuitedReason::ReprC => "is marked with `#[repr(C)]`",
1613+
};
1614+
let field_ty = tcx.def_path_str_with_args(unsuited.def_id, unsuited.args);
1615+
diag.note(format!(
1616+
"this {descr} contains `{field_ty}`, which {note}, \
16231617
and makes it not a breaking change to become \
16241618
non-zero-sized in the future.",
1625-
descr = unsuited.descr,
1626-
));
1627-
},
1628-
)
1619+
descr = unsuited.descr,
1620+
));
1621+
diag.emit();
16291622
} else {
16301623
prev_unsuited_1zst = true;
16311624
}

tests/ui/repr/repr-transparent-non-exhaustive.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,82 +36,66 @@ pub struct T4(Sized, ExternalIndirection<(InternalPrivate, InternalNonExhaustive
3636
#[repr(transparent)]
3737
pub struct T5(Sized, Private);
3838
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
39-
//~| WARN this was previously accepted by the compiler
4039

4140
#[repr(transparent)]
4241
pub struct T6(Sized, NonExhaustive);
4342
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
44-
//~| WARN this was previously accepted by the compiler
4543

4644
#[repr(transparent)]
4745
pub struct T7(Sized, NonExhaustiveEnum);
4846
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
49-
//~| WARN this was previously accepted by the compiler
5047

5148
#[repr(transparent)]
5249
pub struct T8(Sized, NonExhaustiveVariant);
5350
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
54-
//~| WARN this was previously accepted by the compiler
5551

5652
#[repr(transparent)]
5753
pub struct T9(Sized, InternalIndirection<Private>);
5854
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
59-
//~| WARN this was previously accepted by the compiler
6055

6156
#[repr(transparent)]
6257
pub struct T10(Sized, InternalIndirection<NonExhaustive>);
6358
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
64-
//~| WARN this was previously accepted by the compiler
6559

6660
#[repr(transparent)]
6761
pub struct T11(Sized, InternalIndirection<NonExhaustiveEnum>);
6862
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
69-
//~| WARN this was previously accepted by the compiler
7063

7164
#[repr(transparent)]
7265
pub struct T12(Sized, InternalIndirection<NonExhaustiveVariant>);
7366
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
74-
//~| WARN this was previously accepted by the compiler
7567

7668
#[repr(transparent)]
7769
pub struct T13(Sized, ExternalIndirection<Private>);
7870
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
79-
//~| WARN this was previously accepted by the compiler
8071

8172
#[repr(transparent)]
8273
pub struct T14(Sized, ExternalIndirection<NonExhaustive>);
8374
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
84-
//~| WARN this was previously accepted by the compiler
8575

8676
#[repr(transparent)]
8777
pub struct T15(Sized, ExternalIndirection<NonExhaustiveEnum>);
8878
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
89-
//~| WARN this was previously accepted by the compiler
9079

9180
#[repr(transparent)]
9281
pub struct T16(Sized, ExternalIndirection<NonExhaustiveVariant>);
9382
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
94-
//~| WARN this was previously accepted by the compiler
9583

9684
#[repr(transparent)]
9785
pub struct T17(NonExhaustive, Sized);
9886
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
99-
//~| WARN this was previously accepted by the compiler
10087

10188
#[repr(transparent)]
10289
pub struct T18(NonExhaustive, NonExhaustive);
10390
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
104-
//~| WARN this was previously accepted by the compiler
10591

10692
#[repr(transparent)]
10793
pub struct T19(NonExhaustive, Private);
10894
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
109-
//~| WARN this was previously accepted by the compiler
11095

11196
#[repr(transparent)]
11297
pub struct T19Flipped(Private, NonExhaustive);
11398
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
114-
//~| WARN this was previously accepted by the compiler
11599

116100
#[repr(transparent)]
117101
pub struct T20(NonExhaustive);

tests/ui/repr/repr-transparent-non-exhaustive.stderr

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,163 +4,126 @@ error: zero-sized fields in `repr(transparent)` cannot contain external non-exha
44
LL | pub struct T5(Sized, Private);
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 #78586 <https://github.com/rust-lang/rust/issues/78586>
97
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
10-
note: the lint level is defined here
11-
--> $DIR/repr-transparent-non-exhaustive.rs:1:9
12-
|
13-
LL | #![deny(repr_transparent_external_private_fields)]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158

169
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
17-
--> $DIR/repr-transparent-non-exhaustive.rs:42:22
10+
--> $DIR/repr-transparent-non-exhaustive.rs:41:22
1811
|
1912
LL | pub struct T6(Sized, NonExhaustive);
2013
| ^^^^^^^^^^^^^
2114
|
22-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
2415
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
2516

2617
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
27-
--> $DIR/repr-transparent-non-exhaustive.rs:47:22
18+
--> $DIR/repr-transparent-non-exhaustive.rs:45:22
2819
|
2920
LL | pub struct T7(Sized, NonExhaustiveEnum);
3021
| ^^^^^^^^^^^^^^^^^
3122
|
32-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
33-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3423
= note: this enum contains `NonExhaustiveEnum`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
3524

3625
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
37-
--> $DIR/repr-transparent-non-exhaustive.rs:52:22
26+
--> $DIR/repr-transparent-non-exhaustive.rs:49:22
3827
|
3928
LL | pub struct T8(Sized, NonExhaustiveVariant);
4029
| ^^^^^^^^^^^^^^^^^^^^
4130
|
42-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
43-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
4431
= note: this enum contains `NonExhaustiveVariant`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
4532

4633
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
47-
--> $DIR/repr-transparent-non-exhaustive.rs:57:22
34+
--> $DIR/repr-transparent-non-exhaustive.rs:53:22
4835
|
4936
LL | pub struct T9(Sized, InternalIndirection<Private>);
5037
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5138
|
52-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
53-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
5439
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
5540

5641
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
57-
--> $DIR/repr-transparent-non-exhaustive.rs:62:23
42+
--> $DIR/repr-transparent-non-exhaustive.rs:57:23
5843
|
5944
LL | pub struct T10(Sized, InternalIndirection<NonExhaustive>);
6045
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6146
|
62-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
63-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
6447
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
6548

6649
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
67-
--> $DIR/repr-transparent-non-exhaustive.rs:67:23
50+
--> $DIR/repr-transparent-non-exhaustive.rs:61:23
6851
|
6952
LL | pub struct T11(Sized, InternalIndirection<NonExhaustiveEnum>);
7053
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7154
|
72-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
73-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
7455
= note: this enum contains `NonExhaustiveEnum`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
7556

7657
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
77-
--> $DIR/repr-transparent-non-exhaustive.rs:72:23
58+
--> $DIR/repr-transparent-non-exhaustive.rs:65:23
7859
|
7960
LL | pub struct T12(Sized, InternalIndirection<NonExhaustiveVariant>);
8061
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8162
|
82-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
83-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
8463
= note: this enum contains `NonExhaustiveVariant`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
8564

8665
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
87-
--> $DIR/repr-transparent-non-exhaustive.rs:77:23
66+
--> $DIR/repr-transparent-non-exhaustive.rs:69:23
8867
|
8968
LL | pub struct T13(Sized, ExternalIndirection<Private>);
9069
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9170
|
92-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
93-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
9471
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
9572

9673
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
97-
--> $DIR/repr-transparent-non-exhaustive.rs:82:23
74+
--> $DIR/repr-transparent-non-exhaustive.rs:73:23
9875
|
9976
LL | pub struct T14(Sized, ExternalIndirection<NonExhaustive>);
10077
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10178
|
102-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
103-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
10479
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
10580

10681
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
107-
--> $DIR/repr-transparent-non-exhaustive.rs:87:23
82+
--> $DIR/repr-transparent-non-exhaustive.rs:77:23
10883
|
10984
LL | pub struct T15(Sized, ExternalIndirection<NonExhaustiveEnum>);
11085
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11186
|
112-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
113-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
11487
= note: this enum contains `NonExhaustiveEnum`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
11588

11689
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
117-
--> $DIR/repr-transparent-non-exhaustive.rs:92:23
90+
--> $DIR/repr-transparent-non-exhaustive.rs:81:23
11891
|
11992
LL | pub struct T16(Sized, ExternalIndirection<NonExhaustiveVariant>);
12093
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12194
|
122-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
12495
= note: this enum contains `NonExhaustiveVariant`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
12596

12697
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
127-
--> $DIR/repr-transparent-non-exhaustive.rs:97:16
98+
--> $DIR/repr-transparent-non-exhaustive.rs:85:16
12899
|
129100
LL | pub struct T17(NonExhaustive, Sized);
130101
| ^^^^^^^^^^^^^
131102
|
132-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
133-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
134103
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
135104

136105
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
137-
--> $DIR/repr-transparent-non-exhaustive.rs:102:31
106+
--> $DIR/repr-transparent-non-exhaustive.rs:89:31
138107
|
139108
LL | pub struct T18(NonExhaustive, NonExhaustive);
140109
| ^^^^^^^^^^^^^
141110
|
142-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
143-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
144111
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
145112

146113
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
147-
--> $DIR/repr-transparent-non-exhaustive.rs:107:31
114+
--> $DIR/repr-transparent-non-exhaustive.rs:93:31
148115
|
149116
LL | pub struct T19(NonExhaustive, Private);
150117
| ^^^^^^^
151118
|
152-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
153-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
154119
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
155120

156121
error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
157-
--> $DIR/repr-transparent-non-exhaustive.rs:112:32
122+
--> $DIR/repr-transparent-non-exhaustive.rs:97:32
158123
|
159124
LL | pub struct T19Flipped(Private, NonExhaustive);
160125
| ^^^^^^^^^^^^^
161126
|
162-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
163-
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
164127
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
165128

166129
error: aborting due to 16 previous errors

tests/ui/repr/repr-transparent-repr-c.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ pub struct T3(ReprC1Zst, ());
1717
#[repr(transparent)]
1818
pub struct T5(Sized, ReprC1Zst);
1919
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
20-
//~| WARN this was previously accepted by the compiler
2120

2221
#[repr(transparent)]
2322
pub struct T6(ReprC1Zst, Sized);
2423
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
25-
//~| WARN this was previously accepted by the compiler
2624

2725
#[repr(transparent)]
2826
pub struct T7(T1, Sized); // still wrong, even when the repr(C) is hidden inside another type
2927
//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
30-
//~| WARN this was previously accepted by the compiler
3128

3229
fn main() {}

0 commit comments

Comments
 (0)