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

Make some methods of Pin unstable const #76655

Merged
merged 2 commits into from
Sep 22, 2020
Merged

Conversation

CDirkx
Copy link
Contributor

@CDirkx CDirkx commented Sep 12, 2020

Make the following methods unstable const under the const_pin feature:

  • new
  • new_unchecked
  • into_inner
  • into_inner_unchecked
  • get_ref
  • into_ref
  • get_mut
  • get_unchecked_mut

Of these, into_inner and into_inner_unchecked require the unstable const_precise_live_drops.

Also adds tests for these methods in a const context.

Tracking issue: #76654

r? @ecstatic-morse

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 12, 2020
@CDirkx
Copy link
Contributor Author

CDirkx commented Sep 13, 2020

I remember checking if Pin methods could be made const before, however at that time I got an error that const fns could only be inside impl blocks that have Sized or no bounds on generic parameters. I couldn't find what enabled this?

@CDirkx
Copy link
Contributor Author

CDirkx commented Sep 13, 2020

I excluded into_ref (implemented on on Pin<&mut T>), which could technically also be made const, as &mut in consts is still being figured out I believe.

@jyn514 jyn514 added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 13, 2020
@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Sep 13, 2020

I remember checking if Pin methods could be made const before, however at that time I got an error that const fns could only be inside impl blocks that have Sized or no bounds on generic parameters. I couldn't find what enabled this?

This is currently part of the "min const fn" checks, which are disabled for const-unstable functions. Presumably you used rustc_const_unstable rustc_const_stable the last time you tried this.

I excluded into_ref (implemented on on Pin<&mut T>), which could technically also be made const, as &mut in consts is still being figured out I believe.

I don't really see a reason to exclude this if it compiles. As long as these functions are all const-unstable, there's not really any risk.

cc @rust-lang/wg-const-eval Unlike Option and Result, I doubt Pin is useful in a const-context. However, making these unstably const might allow people to test things like const-qualification more thoroughly, and I don't see any downsides.

@CDirkx
Copy link
Contributor Author

CDirkx commented Sep 13, 2020

I added the methods into_ref, get_mut, get_unchecked_mut from Pin<&mut T>, the tests for these are a bit different.

Comment on lines 23 to 24
// test that the methods of `Pin<&mut T>` are usable in a const context
// should be written as the other tests once `&mut` is usable in constants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two sentences? I think they are. If yes, please add capitalization and .. I had to read this 5 times to successfully parse it.

@ecstatic-morse
Copy link
Contributor

r=me with Ralf's change.

@bors delegate+

@bors
Copy link
Contributor

bors commented Sep 15, 2020

✌️ @CDirkx can now approve this pull request

Make the following methods unstable const under the `const_pin` feature:
- `into_ref`
- `get_mut`
- `get_unchecked_mut`
@CDirkx
Copy link
Contributor Author

CDirkx commented Sep 18, 2020

r=@ecstatic-morse

@RalfJung
Copy link
Member

Almost, the right command is

@bors r=ecstatic-morse

@bors
Copy link
Contributor

bors commented Sep 18, 2020

📌 Commit e3c6e46 has been approved by ecstatic-morse

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 18, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 19, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 19, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 19, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 20, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 21, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 21, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 22, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
ecstatic-morse added a commit to ecstatic-morse/rust that referenced this pull request Sep 22, 2020
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: rust-lang#76654

r? @ecstatic-morse
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 22, 2020
…atic-morse

Rollup of 13 pull requests

Successful merges:

 - rust-lang#72734 (Reduce duplicate in liballoc reserve error handling)
 - rust-lang#76131 (Don't use `zip` to compare iterators during pretty-print hack)
 - rust-lang#76150 (Don't recommend ManuallyDrop to customize drop order)
 - rust-lang#76275 (Implementation of Write for some immutable ref structs)
 - rust-lang#76489 (Add explanation for E0756)
 - rust-lang#76581 (do not ICE on bound variables, return `TooGeneric` instead)
 - rust-lang#76655 (Make some methods of `Pin` unstable const)
 - rust-lang#76783 (Only get ImplKind::Impl once)
 - rust-lang#76807 (Use const-checking to forbid use of unstable features in const-stable functions)
 - rust-lang#76888 (use if let instead of single match arm expressions)
 - rust-lang#76914 (extend `Ty` and `TyCtxt` lints to self types)
 - rust-lang#77022 (Reduce boilerplate for BytePos and CharPos)
 - rust-lang#77032 (lint missing docs for extern items)

Failed merges:

r? `@ghost`
@bors bors merged commit 537ede4 into rust-lang:master Sep 22, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 22, 2020
@CDirkx CDirkx deleted the const-pin branch September 23, 2020 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants