Skip to content

Instantiating a type that's const-generic over a custom type doesn't work #68615

Closed
@jplatte

Description

@jplatte

Code (Playground):

#![feature(const_generics)]

#[derive(PartialEq, Eq)]
struct MyType;
struct Const<const V: MyType> {}
type MyConst = Const<{ MyType }>;

fn main() {
    let _x = Const::<{ MyType }> {};
    let _y = MyConst {};
}

Error message:

error[E0308]: mismatched types
 --> src/main.rs:9:14
  |
9 |     let _x = Const::<{ MyType }> {};
  |              ^^^^^^^^^^^^^^^^^^^^^^ expected `ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: MyType`, found `ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: MyType`
  |
  = note: expected type `_`
           found struct `Const<ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: MyType>`

error[E0308]: mismatched types
  --> src/main.rs:10:14
   |
10 |     let _y = MyConst {};
   |              ^^^^^^^^^^ expected `ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: MyType`, found `ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: MyType`
   |
   = note: expected type `_`
            found struct `Const<ByRef { alloc: Allocation { bytes: [], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [], len: Size { raw: 0 } }, size: Size { raw: 0 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }: MyType>`

This issue has been assigned to @lcnr via this comment.

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions