Skip to content

Parametrise modules #424

Open
Open
@nrc

Description

@nrc

I would like to be able to parametrise modules by types and lifetimes. Type parameters are useful where many items in a module should use the same concrete type. E.g., taking some implementation as a parameter we want to ensure that all functions and data types in a module use the same implementor without annotating every item with the same type parameters. Likewise, parameterising by lifetimes is useful if we are to assume that many objects in a module have the same lifetime. This is especially useful in conjunction with arena allocation.

Details

Module declarations may have formal type and lifetime parameters and where clauses, e.g, mod foo<X, 'a> where X: Bar { ... }.

Module uses, including in use expressions which include an alias, can have actual type and lifetime parameters. E.g, let x: foo<int>::Baz = ...; or use foo<int, 'static> as int_foo.

The usual rules around well-formedness wrt bounds, and inference would apply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceType inference related proposals & ideasA-modulesProposals relating to modules.A-resolveProposals relating to name resolution.A-syntaxSyntax related proposals & ideasA-typesystemType system related proposals & ideasT-langRelevant to the language team, which will review and decide on the RFC.postponedRFCs that have been postponed and may be revisited at a later time.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions