Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuple should probably be unsizable by last argument #32702

Closed
VFLashM opened this issue Apr 3, 2016 · 0 comments
Closed

Tuple should probably be unsizable by last argument #32702

VFLashM opened this issue Apr 3, 2016 · 0 comments
Labels
A-DSTs Area: Dynamically-sized types (DSTs)

Comments

@VFLashM
Copy link
Contributor

VFLashM commented Apr 3, 2016

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);
@Mark-Simulacrum Mark-Simulacrum added the A-DSTs Area: Dynamically-sized types (DSTs) label May 2, 2017
bors added a commit that referenced this issue Jun 29, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs)
Projects
None yet
Development

No branches or pull requests

2 participants