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

Merged
merged 1 commit into from Oct 28, 2019

Conversation

@matthewjasper
Copy link
Contributor

matthewjasper 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 added the T-lang label Oct 7, 2019
@jonas-schievink jonas-schievink added this to the 1.40 milestone Oct 7, 2019
@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

Centril 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

rfcbot 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

pnkfelix 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

pnkfelix commented Oct 17, 2019

@rfcbot reviewed

@rfcbot

This comment has been minimized.

Copy link

rfcbot 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
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 25, 2019

☔️ The latest upstream changes (presumably #65804) made this pull request unmergeable. Please resolve the merge conflicts.

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Oct 27, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@matthewjasper matthewjasper force-pushed the matthewjasper:stabilize-const-constructor branch from 701b9b2 to 170718c Oct 27, 2019
@matthewjasper

This comment has been minimized.

Copy link
Contributor Author

matthewjasper commented Oct 27, 2019

@bors r=Centril

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 27, 2019

📌 Commit 170718c has been approved by Centril

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 27, 2019

⌛️ Testing commit 170718c with merge 077619e...

bors added a commit that referenced this pull request Oct 27, 2019
…entril

Stabilize `const_constructor`

# 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:

```rust
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

* [ui/consts/const_constructor/const-construct-call.rs](https://github.com/rust-lang/rust/blob/0d75ab2293a106eb674ac01860910cfc1580837e/src/test/ui/consts/const_constructor/const-construct-call.rs) - Tests various syntactic forms, use in both `const fn` and `const` items, and constructors in both the current and extern crates.
* [ui/consts/const_constructor/const_constructor_qpath.rs](https://github.com/rust-lang/rust/blob/1850dfcdabf8258a1f023f26c2c59e96b869dd95/src/test/ui/consts/const_constructor/const_constructor_qpath.rs) - Tests that type qualified paths to enum variants are also considered to be `const fn`.(#64247)

r? @oli-obk

Closes #61456
Closes  #64247
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 28, 2019

💥 Test timed out

@Centril

This comment has been minimized.

Copy link
Member

Centril commented Oct 28, 2019

@bors retry

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 28, 2019

⌛️ Testing commit 170718c with merge 03a50ae...

bors added a commit that referenced this pull request Oct 28, 2019
…entril

Stabilize `const_constructor`

# 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:

```rust
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

* [ui/consts/const_constructor/const-construct-call.rs](https://github.com/rust-lang/rust/blob/0d75ab2293a106eb674ac01860910cfc1580837e/src/test/ui/consts/const_constructor/const-construct-call.rs) - Tests various syntactic forms, use in both `const fn` and `const` items, and constructors in both the current and extern crates.
* [ui/consts/const_constructor/const_constructor_qpath.rs](https://github.com/rust-lang/rust/blob/1850dfcdabf8258a1f023f26c2c59e96b869dd95/src/test/ui/consts/const_constructor/const_constructor_qpath.rs) - Tests that type qualified paths to enum variants are also considered to be `const fn`.(#64247)

r? @oli-obk

Closes #61456
Closes  #64247
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 28, 2019

☀️ Test successful - checks-azure
Approved by: Centril
Pushing 03a50ae to master...

@bors bors added the merged-by-bors label Oct 28, 2019
@bors bors merged commit 170718c into rust-lang:master Oct 28, 2019
5 checks passed
5 checks passed
homu Test successful
Details
pr Build #20191027.52 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (LinuxTools) LinuxTools succeeded
Details
@matthewjasper matthewjasper deleted the matthewjasper:stabilize-const-constructor branch Oct 28, 2019
@jadbox

This comment has been minimized.

Copy link

jadbox commented Nov 7, 2019

Does this improve performance at all when calling these constructors or no?

@matthewjasper

This comment has been minimized.

Copy link
Contributor Author

matthewjasper commented Nov 8, 2019

No, this is just fixing inconsistent behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.