Skip to content

Forbid generic parameters in the type of const generic parameters #74152

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
lcnr opened this issue Jul 8, 2020 · 3 comments · Fixed by #74159
Closed

Forbid generic parameters in the type of const generic parameters #74152

lcnr opened this issue Jul 8, 2020 · 3 comments · Fixed by #74159
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

@lcnr
Copy link
Contributor

lcnr commented Jul 8, 2020

e.g. do not allow fn foo<T, const N: T>() and foo<const N: usize, const M: [u8; N]>().

While we may want to support this in the future, this should not be part of the MVP and causes a lot of problems
with our current approach. It causes both ICE ICE baby and breaks foo<const N: [u8; { 1+ 4 }]>() because { 1 + 4 } contains N itself in its substitutions.

What probably has to done here:

  • change name resolution to forbid mentions of parameters.
  • stop using the parent generics in generics_of.

cc @eddyb @varkor @yodaldevoid

@lcnr lcnr added A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Jul 8, 2020
@lcnr lcnr self-assigned this Jul 8, 2020
@lcnr
Copy link
Contributor Author

lcnr commented Jul 8, 2020

note: please ping me on zulip if you want to work on this.

@JohnTitor JohnTitor added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 9, 2020
@varkor
Copy link
Member

varkor commented Jul 10, 2020

I believe we already forbade generic type parameters in const generic types, but may have forgotten about other const generics. I'll review the PR soon.

@lcnr
Copy link
Contributor Author

lcnr commented Jul 10, 2020

Afaict we removed that ban for some reason. E0671 is currently unused.

Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
forbid generic params in the type of const params

implements and closes rust-lang#74152

fixes rust-lang#74101, closes rust-lang#71169, fixes rust-lang#73491, closes rust-lang#62878

@eddyb and I talked [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203405696) about this and we probably want to also forbid generic consts in the default
type of a parameter, e.g. `struct Foo<T, U = [u8; std::mem::size_of::<T>()]>`, this is currently still allowed
and I will probably fix that in a followup PR.

r? @varkor @eddyb
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
forbid generic params in the type of const params

implements and closes rust-lang#74152

fixes rust-lang#74101, closes rust-lang#71169, fixes rust-lang#73491, closes rust-lang#62878

@eddyb and I talked [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203405696) about this and we probably want to also forbid generic consts in the default
type of a parameter, e.g. `struct Foo<T, U = [u8; std::mem::size_of::<T>()]>`, this is currently still allowed
and I will probably fix that in a followup PR.

r? @varkor @eddyb
@bors bors closed this as completed in 6ef0dfa Jul 16, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-enhancement Category: An issue proposing an enhancement or a PR with one. 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.

3 participants