Description
This is the summary issue for the UNSIZED_IN_TUPLE
future-compatibility warning and other related errors. The goal of
this page is describe why this change was made and how you can fix
code that is affected by it. It also provides a place to ask questions
or register a complaint if you feel the change should not be made. For
more information on the policy around future-compatibility warnings,
see our breaking change policy guidelines.
What is the warning for?
Among other things, Rust's WF rules guarantee that every type in a legal program is representable. For ADTs, this means that the offsets to every field in the ADT must be known, which requires for every field but the last to be Sized
.
Because tuples are just anonymous ADTs, this requirement also holds for them. However, that requirement was missing from RFC 1214 and the original implementation. This error was found during the work for PR #33138, and this deficiency is to be fixed in rustc 1.10.
As these ill-formed tuples result in an ICE when used, this affects user code mostly in trait declarations. An example from the standard library is the (unstable) trait core::num::bignum::FullOps
:
/// Arithmetic operations required by bignums.
pub trait FullOps {
/// Returns `(carry', v')` such that `carry' * 2^W + v' = self + other + carry`,
/// where `W` is the number of bits in `Self`.
fn full_add(self, other: Self, carry: bool) -> (bool /*carry*/, Self);
/// Returns `(carry', v')` such that `carry' * 2^W + v' = self * other + carry`,
/// where `W` is the number of bits in `Self`.
fn full_mul(self, other: Self, carry: Self) -> (Self /*carry*/, Self);
/// Returns `(carry', v')` such that `carry' * 2^W + v' = self * other + other2 + carry`,
/// where `W` is the number of bits in `Self`.
fn full_mul_add(self, other: Self, other2: Self, carry: Self) -> (Self /*carry*/, Self);
/// Returns `(quo, rem)` such that `borrow * 2^W + self = quo * other + rem`
/// and `0 <= rem < other`, where `W` is the number of bits in `Self`.
fn full_div_rem(self, other: Self, borrow: Self) -> (Self /*quotient*/, Self /*remainder*/);
}
Here the function full_mul
returns a (Self, Self)
tuple, which is only well-formed when the Self
-type is Sized
- for that and other reasons, the trait only makes sense when Self
is Sized
. The solution in this case and most others is to add the missing Sized
supertrait.
Note: at this moment, due to issue #33241, the old trans
code crashes when translating code that uses unsized tuples even if only the last field is unsized. This should be fixed for MIR trans and should not imply in any way that these tuples are ill-formed.
When will this warning become a hard error?
At the beginning of each 6-week release cycle, the Rust compiler team
will review the set of outstanding future compatibility warnings and
nominate some of them for Final Comment Period. Toward the end of
the cycle, we will review any comments and make a final determination
whether to convert the warning into a hard error or remove it
entirely.