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

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

Closed
jplatte opened this issue Jan 28, 2020 · 2 comments · Fixed by #71018
Closed

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

jplatte opened this issue Jan 28, 2020 · 2 comments · Fixed by #71018
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jplatte
Copy link
Contributor

jplatte commented Jan 28, 2020

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.

@Centril Centril added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 28, 2020
@jplatte
Copy link
Contributor Author

jplatte commented Jan 30, 2020

Also happens with some built-in types, e.g. arrays:

#![feature(const_generics)]

struct Const<const V: [usize; 0]> {}
type MyConst = Const<{ [] }>;

fn main() {
    let _x = Const::<{ [] }> {}; // ERROR
    let _y = MyConst {}; // ERROR
}

@lcnr
Copy link
Contributor

lcnr commented Apr 11, 2020

@rustbot claim

@rustbot rustbot self-assigned this Apr 11, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 1, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 1, 2020
@bors bors closed this as completed in 14c3ee9 May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants