-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Open
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-adt_const_params`#![feature(adt_const_params)]``#![feature(adt_const_params)]`F-min_generic_const_args`#![feature(min_generic_const_args)]``#![feature(min_generic_const_args)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Follow up of #150618 and #150699. We currently support directly represented literals as a hir::ConstArgKind::Literal but we don't support negated literals as such a representation:
#![feature(adt_const_params, min_generic_const_args)]
use std::marker::ConstParamTy;
#[derive(Eq, PartialEq, ConstParamTy)]
struct Foo {
field: isize
}
fn foo<const F: Foo>() {}
fn main() {
// works
foo::<{ Foo { field: 1} }>();
// needs an anon const
foo::<{ Foo { field: -1 } }>();
// works
foo::<{ Foo { field: const { -1 } } }>();
}error: complex const arguments must be placed inside of a `const` block
--> src/main.rs:16:26
|
16 | foo::<{ Foo { field: -1 } }>();
| ^^
Not certain of the right way of implementing this, maybe extending ConstArgKind::Literal with a flag for whether it was negated or not 🤔 Then it should just be a matter of updating lower_anon_const_to_const_arg_direct with a case for -1 as well as threading the bool into the input of lit_to_const in lower_const_arg_literal
Once this and #152001 have been done we should remove the special casing in parsing under mGCA for literals being parsed as anon consts instead of direct const args.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-adt_const_params`#![feature(adt_const_params)]``#![feature(adt_const_params)]`F-min_generic_const_args`#![feature(min_generic_const_args)]``#![feature(min_generic_const_args)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.