Skip to content

Tuple should probably be unsizable by last argument #32702

Closed

Description

@VFLashM

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.

struct S;
trait T {}
impl T for S {}

struct Wrapper<TT: ?Sized>(i32, TT);

fn main() {
    let sw: Wrapper<S> = Wrapper(0, S);
    let tw: &Wrapper<T> = &sw; // unsizes just fine

    let 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 now
type Why = (T, i32);

Activity

  1. added a commit that references this issue on Jun 29, 2017
    686ec28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DSTsArea: Dynamically-sized types (DSTs)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions