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

Stabilize `const_constructor` #65188

Open
wants to merge 1 commit into
base: master
from

Conversation

@matthewjasper
Copy link
Contributor

commented Oct 7, 2019

Stabilization proposal

I propose that we stabilize #![feature(const_constructor)].

Tracking issue: #61456
Version target: 1.40 (2019-11-05 => beta, 2019-12-19 => stable).

What is stabilized

User guide

Tuple struct and tuple variant constructors are now considered to be constant functions. As such a call expression where the callee has a tuple struct or variant constructor "function item" type can be called:

const fn make_options() {
    // These already work because they are special cased:
    Some(0);
    (Option::Some)(1);
    // These also work now:
    let f = Option::Some;
    f(2);
    {Option::Some}(3);
    <Option>::Some(5);
}

Motivation

Consistency with other const fn. Consistency between syntactic path forms.

This should also ensure that constructors implement const Fn traits and can be coerced to const fn function pointers, if they are introduced.

Tests

r? @oli-obk

Closes #61456
Closes #64247

@matthewjasper matthewjasper force-pushed the matthewjasper:stabilize-const-constructor branch from 1850dfc to 701b9b2 Oct 7, 2019
@Centril

This comment has been minimized.

Copy link
Member

commented Oct 8, 2019

Thanks for the report!
I also propose that we do indeed stabilize const_constructor.

@rfcbot merge


r? @Centril r=me once FCP completes.

@rust-highfive rust-highfive assigned Centril and unassigned oli-obk Oct 8, 2019
@rfcbot

This comment has been minimized.

Copy link

commented Oct 8, 2019

Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@pnkfelix

This comment has been minimized.

Copy link
Member

commented Oct 17, 2019

as described, this seems fine to me.

I would like to note that another case where const constructors arise is in the context of patterns, e.g.:

#[derive(PartialEq, Eq)]
struct Hi(i32);

const fn hi() -> Hi { Hi(10) }
const C: Hi = hi();

fn main() {
    match Hi(10) {
        self::C => println!("matched"),
        _ => println!("other"),
    }
}

But as far as I can tell, the change being suggested here does not introduce any interesting changes to our behavior for such cases.

@pnkfelix

This comment has been minimized.

Copy link
Member

commented Oct 17, 2019

@rfcbot reviewed

@rfcbot

This comment has been minimized.

Copy link

commented Oct 17, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@Centril Centril removed the I-nominated label Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.