Skip to content

Commit b482523

Browse files
authored
Rollup merge of #122560 - jswrenn:not-yet-supported, r=compiler-errors
Safe Transmute: Use 'not yet supported', not 'unspecified' in errors We can (and will) support analyzing the transmutability of types whose layouts aren't completely specified by its repr. This change ensures that the error messages remain sensible after this support lands. r? ``@compiler-errors``
2 parents 82d5b56 + 107807d commit b482523

28 files changed

+200
-200
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3073,29 +3073,29 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
30733073
let src = trait_ref.args.type_at(1);
30743074
let err_msg = format!("`{src}` cannot be safely transmuted into `{dst}`");
30753075
let safe_transmute_explanation = match reason {
3076-
rustc_transmute::Reason::SrcIsUnspecified => {
3077-
format!("`{src}` does not have a well-specified layout")
3076+
rustc_transmute::Reason::SrcIsNotYetSupported => {
3077+
format!("analyzing the transmutability of `{src}` is not yet supported.")
30783078
}
30793079

3080-
rustc_transmute::Reason::DstIsUnspecified => {
3081-
format!("`{dst}` does not have a well-specified layout")
3080+
rustc_transmute::Reason::DstIsNotYetSupported => {
3081+
format!("analyzing the transmutability of `{dst}` is not yet supported.")
30823082
}
30833083

30843084
rustc_transmute::Reason::DstIsBitIncompatible => {
3085-
format!("At least one value of `{src}` isn't a bit-valid value of `{dst}`")
3085+
format!("at least one value of `{src}` isn't a bit-valid value of `{dst}`")
30863086
}
30873087

30883088
rustc_transmute::Reason::DstMayHaveSafetyInvariants => {
30893089
format!("`{dst}` may carry safety invariants")
30903090
}
30913091
rustc_transmute::Reason::DstIsTooBig => {
3092-
format!("The size of `{src}` is smaller than the size of `{dst}`")
3092+
format!("the size of `{src}` is smaller than the size of `{dst}`")
30933093
}
30943094
rustc_transmute::Reason::DstRefIsTooBig { src, dst } => {
30953095
let src_size = src.size;
30963096
let dst_size = dst.size;
30973097
format!(
3098-
"The referent size of `{src}` ({src_size} bytes) is smaller than that of `{dst}` ({dst_size} bytes)"
3098+
"the referent size of `{src}` ({src_size} bytes) is smaller than that of `{dst}` ({dst_size} bytes)"
30993099
)
31003100
}
31013101
rustc_transmute::Reason::SrcSizeOverflow => {
@@ -3113,7 +3113,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
31133113
dst_min_align,
31143114
} => {
31153115
format!(
3116-
"The minimum alignment of `{src}` ({src_min_align}) should be greater than that of `{dst}` ({dst_min_align})"
3116+
"the minimum alignment of `{src}` ({src_min_align}) should be greater than that of `{dst}` ({dst_min_align})"
31173117
)
31183118
}
31193119
rustc_transmute::Reason::DstIsMoreUnique => {

compiler/rustc_transmute/src/layout/tree.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ pub(crate) mod rustc {
186186

187187
#[derive(Debug, Copy, Clone)]
188188
pub(crate) enum Err {
189-
/// The layout of the type is unspecified.
190-
Unspecified,
189+
/// The layout of the type is not yet supported.
190+
NotYetSupported,
191191
/// This error will be surfaced elsewhere by rustc, so don't surface it.
192192
UnknownLayout,
193193
/// Overflow size
@@ -288,14 +288,14 @@ pub(crate) mod rustc {
288288
if members.len() == 0 {
289289
Ok(Tree::unit())
290290
} else {
291-
Err(Err::Unspecified)
291+
Err(Err::NotYetSupported)
292292
}
293293
}
294294

295295
ty::Array(ty, len) => {
296296
let len = len
297297
.try_eval_target_usize(tcx, ParamEnv::reveal_all())
298-
.ok_or(Err::Unspecified)?;
298+
.ok_or(Err::NotYetSupported)?;
299299
let elt = Tree::from_ty(*ty, tcx)?;
300300
Ok(std::iter::repeat(elt)
301301
.take(len as usize)
@@ -307,7 +307,7 @@ pub(crate) mod rustc {
307307

308308
// If the layout is ill-specified, halt.
309309
if !(adt_def.repr().c() || adt_def.repr().int.is_some()) {
310-
return Err(Err::Unspecified);
310+
return Err(Err::NotYetSupported);
311311
}
312312

313313
// Compute a summary of the type's layout.
@@ -348,7 +348,7 @@ pub(crate) mod rustc {
348348
AdtKind::Union => {
349349
// is the layout well-defined?
350350
if !adt_def.repr().c() {
351-
return Err(Err::Unspecified);
351+
return Err(Err::NotYetSupported);
352352
}
353353

354354
let ty_layout = layout_of(tcx, ty)?;
@@ -384,7 +384,7 @@ pub(crate) mod rustc {
384384
}))
385385
}
386386

387-
_ => Err(Err::Unspecified),
387+
_ => Err(Err::NotYetSupported),
388388
}
389389
}
390390

compiler/rustc_transmute/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ pub enum Condition<R> {
4343
/// Answers "why wasn't the source type transmutable into the destination type?"
4444
#[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone)]
4545
pub enum Reason<T> {
46-
/// The layout of the source type is unspecified.
47-
SrcIsUnspecified,
48-
/// The layout of the destination type is unspecified.
49-
DstIsUnspecified,
46+
/// The layout of the source type is not yet supported.
47+
SrcIsNotYetSupported,
48+
/// The layout of the destination type is not yet supported.
49+
DstIsNotYetSupported,
5050
/// The layout of the destination type is bit-incompatible with the source type.
5151
DstIsBitIncompatible,
5252
/// The destination type may carry safety invariants.

compiler/rustc_transmute/src/maybe_transmutable/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ mod rustc {
5656
}
5757
(Err(Err::UnknownLayout), _) => Answer::No(Reason::SrcLayoutUnknown),
5858
(_, Err(Err::UnknownLayout)) => Answer::No(Reason::DstLayoutUnknown),
59-
(Err(Err::Unspecified), _) => Answer::No(Reason::SrcIsUnspecified),
60-
(_, Err(Err::Unspecified)) => Answer::No(Reason::DstIsUnspecified),
59+
(Err(Err::NotYetSupported), _) => Answer::No(Reason::SrcIsNotYetSupported),
60+
(_, Err(Err::NotYetSupported)) => Answer::No(Reason::DstIsNotYetSupported),
6161
(Err(Err::SizeOverflow), _) => Answer::No(Reason::SrcSizeOverflow),
6262
(_, Err(Err::SizeOverflow)) => Answer::No(Reason::DstSizeOverflow),
6363
(Ok(src), Ok(dst)) => MaybeTransmutableQuery { src, dst, assume, context }.answer(),

tests/ui/transmutability/alignment/align-fail.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: `&[u8; 0]` cannot be safely transmuted into `&[u16; 0]`
22
--> $DIR/align-fail.rs:21:55
33
|
44
LL | ...tatic [u8; 0], &'static [u16; 0]>();
5-
| ^^^^^^^^^^^^^^^^^ The minimum alignment of `&[u8; 0]` (1) should be greater than that of `&[u16; 0]` (2)
5+
| ^^^^^^^^^^^^^^^^^ the minimum alignment of `&[u8; 0]` (1) should be greater than that of `&[u16; 0]` (2)
66
|
77
note: required by a bound in `is_maybe_transmutable`
88
--> $DIR/align-fail.rs:9:14

tests/ui/transmutability/arrays/should_require_well_defined_layout.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: `[String; 0]` cannot be safely transmuted into `()`
22
--> $DIR/should_require_well_defined_layout.rs:25:52
33
|
44
LL | assert::is_maybe_transmutable::<repr_rust, ()>();
5-
| ^^ `[String; 0]` does not have a well-specified layout
5+
| ^^ analyzing the transmutability of `[String; 0]` is not yet supported.
66
|
77
note: required by a bound in `is_maybe_transmutable`
88
--> $DIR/should_require_well_defined_layout.rs:12:14
@@ -23,7 +23,7 @@ error[E0277]: `u128` cannot be safely transmuted into `[String; 0]`
2323
--> $DIR/should_require_well_defined_layout.rs:26:47
2424
|
2525
LL | assert::is_maybe_transmutable::<u128, repr_rust>();
26-
| ^^^^^^^^^ `[String; 0]` does not have a well-specified layout
26+
| ^^^^^^^^^ analyzing the transmutability of `[String; 0]` is not yet supported.
2727
|
2828
note: required by a bound in `is_maybe_transmutable`
2929
--> $DIR/should_require_well_defined_layout.rs:12:14
@@ -44,7 +44,7 @@ error[E0277]: `[String; 1]` cannot be safely transmuted into `()`
4444
--> $DIR/should_require_well_defined_layout.rs:31:52
4545
|
4646
LL | assert::is_maybe_transmutable::<repr_rust, ()>();
47-
| ^^ `[String; 1]` does not have a well-specified layout
47+
| ^^ analyzing the transmutability of `[String; 1]` is not yet supported.
4848
|
4949
note: required by a bound in `is_maybe_transmutable`
5050
--> $DIR/should_require_well_defined_layout.rs:12:14
@@ -65,7 +65,7 @@ error[E0277]: `u128` cannot be safely transmuted into `[String; 1]`
6565
--> $DIR/should_require_well_defined_layout.rs:32:47
6666
|
6767
LL | assert::is_maybe_transmutable::<u128, repr_rust>();
68-
| ^^^^^^^^^ `[String; 1]` does not have a well-specified layout
68+
| ^^^^^^^^^ analyzing the transmutability of `[String; 1]` is not yet supported.
6969
|
7070
note: required by a bound in `is_maybe_transmutable`
7171
--> $DIR/should_require_well_defined_layout.rs:12:14
@@ -86,7 +86,7 @@ error[E0277]: `[String; 2]` cannot be safely transmuted into `()`
8686
--> $DIR/should_require_well_defined_layout.rs:37:52
8787
|
8888
LL | assert::is_maybe_transmutable::<repr_rust, ()>();
89-
| ^^ `[String; 2]` does not have a well-specified layout
89+
| ^^ analyzing the transmutability of `[String; 2]` is not yet supported.
9090
|
9191
note: required by a bound in `is_maybe_transmutable`
9292
--> $DIR/should_require_well_defined_layout.rs:12:14
@@ -107,7 +107,7 @@ error[E0277]: `u128` cannot be safely transmuted into `[String; 2]`
107107
--> $DIR/should_require_well_defined_layout.rs:38:47
108108
|
109109
LL | assert::is_maybe_transmutable::<u128, repr_rust>();
110-
| ^^^^^^^^^ `[String; 2]` does not have a well-specified layout
110+
| ^^^^^^^^^ analyzing the transmutability of `[String; 2]` is not yet supported.
111111
|
112112
note: required by a bound in `is_maybe_transmutable`
113113
--> $DIR/should_require_well_defined_layout.rs:12:14

0 commit comments

Comments
 (0)