Skip to content

Inline const expressions and patterns#2920

Merged
nikomatsakis merged 19 commits intorust-lang:masterfrom
ecstatic-morse:inline-const
Aug 27, 2020
Merged

Inline const expressions and patterns#2920
nikomatsakis merged 19 commits intorust-lang:masterfrom
ecstatic-morse:inline-const

Conversation

@ecstatic-morse
Copy link
Copy Markdown
Contributor

@ecstatic-morse ecstatic-morse commented May 4, 2020

Rendered

TL; DR: Allows users to request compile-time evaluation without requiring promotion or a named const.

fn foo() -> &'static i32 {
    &const { 
        let x = 4i32;
        x.pow(5)
    }
}

fn main() {
    match *x {
        0 ..= const { u32::MAX / 2 } => println!("low"),
        const { u32::MAX / 2 + 1 } ..= u32::MAX => println!("high"),
    }
}

This idea has been in the ether for a while now as a way to reduce dependence on promotion for evaluating simple expressions at compile-time. It was discussed most recently on Zulip.

Credit to @scottmcm, who discussed this with me on Zulip and was one of the people who discovered this idea. I believe both @RalfJung and @oli-obk have considered this as well.

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

Labels

A-const Proposals relating to const items A-const-eval Proposals relating to compile time evaluation (CTFE). disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. T-lang Relevant to the language team, which will review and decide on the RFC.

Projects

None yet

Development

Successfully merging this pull request may close these issues.