Skip to content

Allow first-class struct and tuple constants #23260

@aochagavia

Description

@aochagavia

The following code should compile, but does not:

struct MyStruct { field: usize }
struct Nested { nested: MyStruct }
struct Mix2 { nested: ((usize,),) }

const STRUCT: MyStruct = MyStruct { field: 42 };
const TUP: (usize,) = (43,);
const NESTED_S: Nested = Nested { nested: MyStruct { field: 5 } };
const NESTED_T: ((usize,),) = ((4,),);
const MIX_1: ((Nested,),) = ((Nested { nested: MyStruct { field: 3 } },),);
const MIX_2: Mix2 = Mix2 { nested: ((2,),) };
const INSTANT_1: usize = (MyStruct { field: 1 }).field;
const INSTANT_2: usize = (0,).0;

fn main() {
    let a = [0; STRUCT.field];
    let b = [0; TUP.0];
    let c = [0; NESTED_S.nested.field];
    let d = [0; (NESTED_T.0).0];
    let e = [0; (MIX_1.0).0.nested.field];
    let f = [0; (MIX_2.nested.0).0];
    let g = [0; INSTANT_1];
    let h = [0; INSTANT_2];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions