Skip to content

Keyword/modifier generics #164

Closed
Closed
@oli-obk

Description

@oli-obk

Summary

We want to allow users to be generic over at least the following keywords:

  • mut
  • const
  • async
  • extern
  • unsafe

We already support a limited version for const (only a sugared version, not explictly being generic over it), because const fn foo<T: ~const Trait>(t: T) { t.method() } is usable outside a const context with types that don't impl const Trait, and inside const contexts the types must have an impl const Trait.

As a first step we want to actually change the implementation of this feature inside rustc to re-use the generics and substitution infrastructure.

As a next step we want to play with async to allow the same kind of async if async bounds as well as async trait declarations and impl async Trait for Type declarations for those bounds to be useful.

Most of this will initially happen with attributes instead of syntax changes, but we want to start exploring possible syntax (hopefully without the ~ placeholder modifier) for the sugar.

I've talked about sugar, but what we'll likely want in the farther future is to allow writing the desugared version directly in the surface language. Basically I envision something like the following (modulo syntax bikeshed, but mostly in the right places)

const fn foo<T: ~const Trait>(t: T)

// the above desugars to

for<effect K> const<K> fn foo<T: const<K> Trait>(t: T)

The details of how we think this should work are in a doc that'll be ready for consumption in time for this meeting.

Background reading

About this issue

This issue corresponds to a lang-team design meeting proposal. It corresponds
to a possible topic of discussion that may be scheduled for deeper discussion
during one of our design meetings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions