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

Permit unused generic const parameters in type definitions #60047

Closed
varkor opened this issue Apr 17, 2019 · 6 comments · Fixed by #60058
Closed

Permit unused generic const parameters in type definitions #60047

varkor opened this issue Apr 17, 2019 · 6 comments · Fixed by #60058
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@varkor
Copy link
Member

varkor commented Apr 17, 2019

#![feature(const_generics)]

struct A<const N: usize>;

should compile, as there are no variance issues with respect to const parameters. (See #44580 (comment).)

@varkor varkor added the A-const-generics Area: const generics (parameters and arguments) label Apr 17, 2019
@varkor varkor self-assigned this Apr 17, 2019
@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-type-system Area: Type system labels Apr 17, 2019
@cramertj
Copy link
Member

Technically we could do this with 'static types as well, right? struct A<T: 'static>; also doesn't have any variance issues that I can think of.

@jonas-schievink
Copy link
Contributor

Related: #59875

@Centril
Copy link
Contributor

Centril commented Apr 17, 2019

@cramertj We can do it sensibly for all type parameters by assuming that PhantomData<T> is there for all unused type parameters T (which gives rise to covariance & owned dropck behavior & ...). But that's a larger discussion.

@cramertj
Copy link
Member

@Centril sorry, that's a different thing-- that's assuming a variance. I'm talking about allowing it where we don't have to assume a variance because variance can't matter.

@hanna-kruppe
Copy link
Contributor

But variance is not the only thing determined by how the type parameter is used, it also affects dropck, auto traits, and possibly more that I'm forgetting right now. So T: 'static doesn't remove the need to "assume" things when T is unused.

@cramertj
Copy link
Member

Good point! :)

bors added a commit that referenced this issue Apr 18, 2019
Make const parameters enforce no variance constraints

Fixes #60047. Also includes some minor const refactoring for convenience.
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) A-type-system Area: Type system C-bug Category: This is a bug. 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.

5 participants