Skip to content

Commit 32cdc4d

Browse files
Fix tests in tests/ui/transmute
Signed-off-by: FedericoBruzzone <[email protected]>
1 parent ec20898 commit 32cdc4d

File tree

5 files changed

+58
-26
lines changed

5 files changed

+58
-26
lines changed

compiler/rustc_hir_typeck/src/intrinsicck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
143143
err.note(format!("`{from}` does not have a fixed size"));
144144
err.emit();
145145
} else {
146-
err.note(format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
147-
.note(format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
146+
err.note(format!("source type: `{}`\n{}", from, skeleton_string(from, sk_from)))
147+
.note(format!("target type: `{}`\n{}", to, skeleton_string(to, sk_to)));
148148
if let Err(LayoutError::ReferencesError(_)) = sk_from {
149149
err.delay_as_bug();
150150
} else if let Err(LayoutError::ReferencesError(_)) = sk_to {

compiler/rustc_middle/messages.ftl

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ middle_strict_coherence_needs_negative_coherence =
101101
.label = due to this attribute
102102
103103
middle_too_generic =
104-
cannot determine the layout of the type `{$ty}`; too generic
104+
the type `{$ty}` is too generic to determine its layout
105+
the size of this type is unknown at compile-time
105106
106107
middle_type_length_limit = reached the type-length limit while instantiating `{$shrunk}`
107108

compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
276276
match *self {
277277
LayoutError::Unknown(ty) => write!(f, "the type `{ty}` has an unknown layout"),
278278
LayoutError::TooGeneric(ty) => {
279-
write!(f, "cannot determine the layout for the type `{ty}`; too generic")
279+
write!(f, "the type `{ty}` is too generic to determine its layout\nthe size of this type is unknown at compile-time")
280280
}
281281
LayoutError::SizeOverflow(ty) => {
282282
write!(f, "values of the type `{ty}` are too big for the target architecture")

tests/ui/transmute/transmute-different-sizes.stderr

+23-10
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,57 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
44
LL | let _: i8 = transmute(16i16);
55
| ^^^^^^^^^
66
|
7-
= note: source type: `i16` (N bits)
8-
= note: target type: `i8` (N bits)
7+
= note: source type: `i16`
8+
N bits
9+
= note: target type: `i8`
10+
N bits
911

1012
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
1113
--> $DIR/transmute-different-sizes.rs:16:17
1214
|
1315
LL | let _: i8 = transmute(x);
1416
| ^^^^^^^^^
1517
|
16-
= note: source type: `&T` (N bits)
17-
= note: target type: `i8` (N bits)
18+
= note: source type: `&T`
19+
N bits
20+
= note: target type: `i8`
21+
N bits
1822

1923
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2024
--> $DIR/transmute-different-sizes.rs:27:5
2125
|
2226
LL | transmute(x)
2327
| ^^^^^^^^^
2428
|
25-
= note: source type: `u16` (N bits)
26-
= note: target type: `<T as Specializable>::Output` (this type does not have a fixed size)
29+
= note: source type: `u16`
30+
N bits
31+
= note: target type: `<T as Specializable>::Output`
32+
the type `<T as Specializable>::Output` is too generic to determine its layout
33+
the size of this type is unknown at compile-time
2734

2835
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2936
--> $DIR/transmute-different-sizes.rs:38:5
3037
|
3138
LL | transmute(from)
3239
| ^^^^^^^^^
3340
|
34-
= note: source type: `*mut T` (pointer to `T`)
35-
= note: target type: `PtrAndOverAlignZST<T>` (size can vary because of <T as Pointee>::Metadata)
41+
= note: source type: `*mut T`
42+
pointer to `T`
43+
= note: target type: `PtrAndOverAlignZST<T>`
44+
the type `<T as Pointee>::Metadata` is too generic to determine its layout
45+
the size of this type is unknown at compile-time
3646

3747
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
3848
--> $DIR/transmute-different-sizes.rs:47:5
3949
|
4050
LL | std::mem::transmute(from)
4151
| ^^^^^^^^^^^^^^^^^^^
4252
|
43-
= note: source type: `*mut T` (pointer to `T`)
44-
= note: target type: `PtrAndEmptyArray<T>` (size can vary because of <T as Pointee>::Metadata)
53+
= note: source type: `*mut T`
54+
pointer to `T`
55+
= note: target type: `PtrAndEmptyArray<T>`
56+
the type `<T as Pointee>::Metadata` is too generic to determine its layout
57+
the size of this type is unknown at compile-time
4558

4659
error: aborting due to 5 previous errors
4760

tests/ui/transmute/transmute-type-parameters.stderr

+30-12
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,71 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
44
LL | let _: i32 = transmute(x);
55
| ^^^^^^^^^
66
|
7-
= note: source type: `T` (this type does not have a fixed size)
8-
= note: target type: `i32` (32 bits)
7+
= note: source type: `T`
8+
the type `T` is too generic to determine its layout
9+
the size of this type is unknown at compile-time
10+
= note: target type: `i32`
11+
32 bits
912

1013
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
1114
--> $DIR/transmute-type-parameters.rs:11:18
1215
|
1316
LL | let _: i32 = transmute(x);
1417
| ^^^^^^^^^
1518
|
16-
= note: source type: `(T, i32)` (size can vary because of T)
17-
= note: target type: `i32` (32 bits)
19+
= note: source type: `(T, i32)`
20+
the type `T` is too generic to determine its layout
21+
the size of this type is unknown at compile-time
22+
= note: target type: `i32`
23+
32 bits
1824

1925
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2026
--> $DIR/transmute-type-parameters.rs:16:18
2127
|
2228
LL | let _: i32 = transmute(x);
2329
| ^^^^^^^^^
2430
|
25-
= note: source type: `[T; 10]` (size can vary because of T)
26-
= note: target type: `i32` (32 bits)
31+
= note: source type: `[T; 10]`
32+
the type `T` is too generic to determine its layout
33+
the size of this type is unknown at compile-time
34+
= note: target type: `i32`
35+
32 bits
2736

2837
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2938
--> $DIR/transmute-type-parameters.rs:25:18
3039
|
3140
LL | let _: i32 = transmute(x);
3241
| ^^^^^^^^^
3342
|
34-
= note: source type: `Bad<T>` (size can vary because of T)
35-
= note: target type: `i32` (32 bits)
43+
= note: source type: `Bad<T>`
44+
the type `T` is too generic to determine its layout
45+
the size of this type is unknown at compile-time
46+
= note: target type: `i32`
47+
32 bits
3648

3749
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
3850
--> $DIR/transmute-type-parameters.rs:35:18
3951
|
4052
LL | let _: i32 = transmute(x);
4153
| ^^^^^^^^^
4254
|
43-
= note: source type: `Worse<T>` (size can vary because of T)
44-
= note: target type: `i32` (32 bits)
55+
= note: source type: `Worse<T>`
56+
the type `T` is too generic to determine its layout
57+
the size of this type is unknown at compile-time
58+
= note: target type: `i32`
59+
32 bits
4560

4661
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
4762
--> $DIR/transmute-type-parameters.rs:40:18
4863
|
4964
LL | let _: i32 = transmute(x);
5065
| ^^^^^^^^^
5166
|
52-
= note: source type: `Option<T>` (size can vary because of T)
53-
= note: target type: `i32` (32 bits)
67+
= note: source type: `Option<T>`
68+
the type `T` is too generic to determine its layout
69+
the size of this type is unknown at compile-time
70+
= note: target type: `i32`
71+
32 bits
5472

5573
error: aborting due to 6 previous errors
5674

0 commit comments

Comments
 (0)