Skip to content

Commit bd3d1ae

Browse files
author
Lukas Markeffsky
committed
fix error (maybe), use short/inline suggestions
1 parent 09c6c54 commit bd3d1ae

File tree

2 files changed

+30
-45
lines changed

2 files changed

+30
-45
lines changed

compiler/rustc_typeck/src/check/check.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
2121
use rustc_middle::ty::subst::GenericArgKind;
2222
use rustc_middle::ty::util::{Discr, IntTypeExt};
2323
use rustc_middle::ty::{
24-
self, ParamEnv, ToPredicate, Ty, TyCtxt, TyKind, TypeFoldable, TypeSuperFoldable,
24+
self, Array, ParamEnv, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,
2525
};
2626
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
2727
use rustc_span::symbol::sym;
@@ -1206,17 +1206,17 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
12061206
for attr in tcx.get_attrs(def.did(), sym::repr) {
12071207
for r in attr::parse_repr_attr(&tcx.sess, attr) {
12081208
if let attr::ReprPacked(pack) = r
1209-
&& let Some(repr_pack) = repr.pack
1210-
&& pack as u64 != repr_pack.bytes()
1211-
{
1212-
struct_span_err!(
1213-
tcx.sess,
1214-
sp,
1215-
E0634,
1216-
"type has conflicting packed representation hints"
1217-
)
1218-
.emit();
1219-
}
1209+
&& let Some(repr_pack) = repr.pack
1210+
&& pack as u64 != repr_pack.bytes()
1211+
{
1212+
struct_span_err!(
1213+
tcx.sess,
1214+
sp,
1215+
E0634,
1216+
"type has conflicting packed representation hints"
1217+
)
1218+
.emit();
1219+
}
12201220
}
12211221
}
12221222
if repr.align.is_some() {
@@ -1330,7 +1330,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
13301330
// We are currently checking the type this field came from, so it must be local
13311331
let span = tcx.hir().span_if_local(field.did).unwrap();
13321332
let array_len = match ty.kind() {
1333-
TyKind::Array(_, len) => len.try_eval_usize(tcx, param_env),
1333+
Array(_, len) => len.try_eval_usize(tcx, param_env),
13341334
_ => None,
13351335
};
13361336
let zst = array_len == Some(0) || layout.map_or(false, |layout| layout.is_zst());
@@ -1365,9 +1365,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
13651365
{
13661366
for item in item_list {
13671367
if item.name_or_empty() == sym::transparent {
1368-
err.span_suggestion_verbose(
1368+
err.span_suggestion_short(
13691369
item.span(),
1370-
"Try using `#[repc(C)]` instead",
1370+
"Try using `repr(C)` instead",
13711371
"C",
13721372
Applicability::MachineApplicable,
13731373
);

src/test/ui/repr/repr-transparent.stderr

+15-30
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,26 @@ LL | pub struct StructWithProjection(f32, <f32 as Mirror>::It);
2121
error[E0691]: zero-sized field in transparent struct has alignment larger than 1
2222
--> $DIR/repr-transparent.rs:36:32
2323
|
24+
LL | #[repr(transparent)]
25+
| ----------- help: Try using `repr(C)` instead
2426
LL | struct NontrivialAlignZst(u32, [u16; 0]);
2527
| ^^^^^^^^ has alignment larger than 1
26-
|
27-
help: Try using `#[repc(C)]` instead
28-
|
29-
LL | #[repr(C)]
30-
| ~
3128

3229
error[E0691]: zero-sized field in transparent struct has alignment larger than 1
3330
--> $DIR/repr-transparent.rs:42:24
3431
|
32+
LL | #[repr(transparent)]
33+
| ----------- help: Try using `repr(C)` instead
3534
LL | struct GenericAlign<T>(ZstAlign32<T>, u32);
3635
| ^^^^^^^^^^^^^ has alignment larger than 1
37-
|
38-
help: Try using `#[repc(C)]` instead
39-
|
40-
LL | #[repr(C)]
41-
| ~
4236

4337
error[E0691]: zero-sized field in transparent struct has alignment larger than 1
4438
--> $DIR/repr-transparent.rs:45:33
4539
|
40+
LL | #[repr(transparent)]
41+
| ----------- help: Try using `repr(C)` instead
4642
LL | struct GenericAlignZeroArray<T>([T; 0], u32);
4743
| ^^^^^^ may have alignment larger than 1
48-
|
49-
help: Try using `#[repc(C)]` instead
50-
|
51-
LL | #[repr(C)]
52-
| ~
5344

5445
error[E0084]: unsupported representation for zero-variant enum
5546
--> $DIR/repr-transparent.rs:47:1
@@ -88,35 +79,29 @@ LL | Bar,
8879
error[E0691]: zero-sized field in transparent enum has alignment larger than 1
8980
--> $DIR/repr-transparent.rs:74:14
9081
|
82+
LL | #[repr(transparent)]
83+
| ----------- help: Try using `repr(C)` instead
84+
LL | enum NontrivialAlignZstEnum {
9185
LL | Foo(u32, [u16; 0]),
9286
| ^^^^^^^^ has alignment larger than 1
93-
|
94-
help: Try using `#[repc(C)]` instead
95-
|
96-
LL | #[repr(C)]
97-
| ~
9887

9988
error[E0691]: zero-sized field in transparent enum has alignment larger than 1
10089
--> $DIR/repr-transparent.rs:79:11
10190
|
91+
LL | #[repr(transparent)]
92+
| ----------- help: Try using `repr(C)` instead
93+
LL | enum GenericAlignEnum<T> {
10294
LL | Foo { bar: ZstAlign32<T>, baz: u32 }
10395
| ^^^^^^^^^^^^^^^^^^ has alignment larger than 1
104-
|
105-
help: Try using `#[repc(C)]` instead
106-
|
107-
LL | #[repr(C)]
108-
| ~
10996

11097
error[E0691]: zero-sized field in transparent enum has alignment larger than 1
11198
--> $DIR/repr-transparent.rs:84:11
11299
|
100+
LL | #[repr(transparent)]
101+
| ----------- help: Try using `repr(C)` instead
102+
LL | enum GenericAlignEnumZeroArray<T> {
113103
LL | Foo { bar: [T; 0], baz: u32 }
114104
| ^^^^^^^^^^^ may have alignment larger than 1
115-
|
116-
help: Try using `#[repc(C)]` instead
117-
|
118-
LL | #[repr(C)]
119-
| ~
120105

121106
error[E0690]: transparent union needs at most one non-zero-sized field, but has 2
122107
--> $DIR/repr-transparent.rs:93:1

0 commit comments

Comments
 (0)