Skip to content

Allow the use of const parameters from outer definitions #61414

Closed
@varkor

Description

@varkor
Member

We would like this to pass:

fn foo<const X: u32>() -> u32 {
    fn bar() -> u32 {
        X
    }
    bar() * 2
}

fn main() {
    assert_eq!(foo::<6>(), 12);
}

See this IRLO post for motivation.

Activity

added
A-const-genericsArea: const generics (parameters and arguments)
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
T-langRelevant to the language team
on May 31, 2019
Centril

Centril commented on May 31, 2019

@Centril
Contributor

This would be an implementation of {-# LANGUAGE ScopedTypeVariables #-} as in the Glasgow Haskell Compiler but specifically for const generic parameters.

I do think we should generalize this to type parameters at least and make this work for non-impl items (possibly not for others) in general. Lifetimes are also something to consider... and likely tricky and it should also impact const generics and type parameters implicitly.

removed
requires-nightlyThis issue requires a nightly compiler in some way.
on Jun 24, 2022
lcnr

lcnr commented on Jun 24, 2022

@lcnr
Contributor

implementing this would require a lang MCP or an RFC. As such I am closing this issue.

I generally don't think we should have a special case for const parameters here. I don't think there's a meaningful difference between const and type parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Centril@jonas-schievink@varkor@BoxyUwU@lcnr

        Issue actions

          Allow the use of const parameters from outer definitions · Issue #61414 · rust-lang/rust