-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-generic_arg_inferUsing `_` as a const argument: #![feature(generic_arg_infer)]`Using `_` as a const argument: #![feature(generic_arg_infer)]`
Description
#![feature(generic_arg_infer)]
struct NotCopy;
fn with_len<T, const N: usize>(_: [T; N]) {}
fn main() {
let x = [NotCopy; _];
with_len::<NotCopy, 0>(x)
}
results in the following error:
error[[E0277]](https://doc.rust-lang.org/nightly/error_codes/E0277.html): the trait bound `NotCopy: Copy` is not satisfied
--> src/main.rs:7:14
|
7 | let x = [NotCopy; _];
| ^^^^^^^ the trait `Copy` is not implemented for `NotCopy`
|
= note: the `Copy` trait is required because this value will be copied for each element of the array
help: consider annotating `NotCopy` with `#[derive(Copy)]`
|
2 + #[derive(Copy)]
3 | struct NotCopy;
|
we should be able to solve that by using marker traits (potentially waiting until they're stable)
#[marker]
trait RepeatExprMayCopyValue {}
impl<T: Copy, const N: usize> RepeatExprMayCopyValue for [T; N] {}
impl<T> RepeatExprMayCopyValue for [T; 0] {}
impl<T> RepeatExprMayCopyValue for [T; 1] {}
and then change hir typeck to require RepeatExprMayCopyValue
for the array instead of optionally requiring Copy
for the value.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-generic_arg_inferUsing `_` as a const argument: #![feature(generic_arg_infer)]`Using `_` as a const argument: #![feature(generic_arg_infer)]`