You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently tuples can contain unsized types, but cannot be coerced.
It contrasts with behavior of tuple structs and probably should be changed.
I can see two options here:
a) Forbid tuples with unsized types completely.
b) Forbid tuples with unsized types on any but last position and allow DST coercions.
structS;traitT{}implTforS{}structWrapper<TT: ?Sized>(i32,TT);fnmain(){let sw:Wrapper<S> = Wrapper(0,S);let tw:&Wrapper<T> = &sw;// unsizes just finelet st:(i32,S) = (0,S);let tt:&(i32,T) = &st;// fails to unsize, even though it could}// on a side note, why is it a legal type?// as far as I can tell there is no way to get // an instance of this type right nowtypeWhy = (T,i32);
The text was updated successfully, but these errors were encountered:
Unsized tuple coercions
Part of #18469. Fixes#32702.
#37685 and #34451 might also be related.
This PR does the following:
- Introduce explicit `Sized` constraints on tuple initializers, similar to that of record-struct initializers. Not much relevant to the main contribution but I noticed this when making tests for unsized tuple coercions.
- Implement `(.., T): Unsize<(.., U)>` where `T: Unsize<U>`.
- Assume `(.., T)` is MaybeUnsizedUnivariant.
- Modify `src/librustc/ty/util.rs` and `src/librustc_trans/glue.rs` so that tuples and structs are uniformly traversed when translating.
Currently tuples can contain unsized types, but cannot be coerced.
It contrasts with behavior of tuple structs and probably should be changed.
I can see two options here:
a) Forbid tuples with unsized types completely.
b) Forbid tuples with unsized types on any but last position and allow DST coercions.
The text was updated successfully, but these errors were encountered: