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

Various fixes for const_trait_impl #89359

Merged
merged 4 commits into from
Nov 25, 2021
Merged

Conversation

fee1-dead
Copy link
Member

A few problems I found while making Iterator easier to const-implement.

  1. More generous ~const Drop check.

We check for nested fields with caller bounds.

For example, an ADT type with fields of types A, B, C, check if all of them are either:

  • Bounded (A: ~const Drop, B: Copy)
  • Known to be able to destruct at compile time (C = i32, struct C(i32), C = some_fn)
  1. Don't treat trait functions marked with #[default_method_body_is_const] as stable const fns when checking const_for and const_try feature gates.

I think anyone can review this, so no r? this time.

@fee1-dead fee1-dead added the F-const_trait_impl `#![feature(const_trait_impl)]` label Sep 29, 2021
@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 29, 2021
@fee1-dead fee1-dead changed the title Various bugfixes for const_trait_impl Various fixes for const_trait_impl Sep 29, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
@jackh726
Copy link
Member

r? @oli-obk

@bors
Copy link
Contributor

bors commented Oct 23, 2021

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


pub struct Foo<T>(T);

const fn baz<T: ~const Drop, E: ~const Drop>(res: Result<Foo<T>, Foo<E>>) -> Option<Foo<T>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

So ~const Drop bounds already are unlike Drop bounds in that the type does not have to actually implement the Drop trait. Is this noted anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. That makes sense now, seeing as there isn't really any other way to easily do it.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 18, 2021

makes sense

r=me after a rebase

@rust-log-analyzer

This comment has been minimized.

@fee1-dead
Copy link
Member Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Nov 24, 2021

📌 Commit 4f29f3c has been approved by oli-obk

@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 Nov 24, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Nov 24, 2021
Various fixes for const_trait_impl

A few problems I found while making `Iterator` easier to const-implement.

1. More generous `~const Drop` check.

We check for nested fields with caller bounds.

For example, an ADT type with fields of types `A`, `B`, `C`, check if all of them are either:
 - Bounded (`A: ~const Drop`, `B: Copy`)
 - Known to be able to destruct at compile time (`C = i32`, `struct C(i32)`, `C = some_fn`)

2. Don't treat trait functions marked with `#[default_method_body_is_const]` as stable const fns when checking `const_for` and `const_try` feature gates.

I think anyone can review this, so no r? this time.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 25, 2021
Various fixes for const_trait_impl

A few problems I found while making `Iterator` easier to const-implement.

1. More generous `~const Drop` check.

We check for nested fields with caller bounds.

For example, an ADT type with fields of types `A`, `B`, `C`, check if all of them are either:
 - Bounded (`A: ~const Drop`, `B: Copy`)
 - Known to be able to destruct at compile time (`C = i32`, `struct C(i32)`, `C = some_fn`)

2. Don't treat trait functions marked with `#[default_method_body_is_const]` as stable const fns when checking `const_for` and `const_try` feature gates.

I think anyone can review this, so no r? this time.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 25, 2021
Various fixes for const_trait_impl

A few problems I found while making `Iterator` easier to const-implement.

1. More generous `~const Drop` check.

We check for nested fields with caller bounds.

For example, an ADT type with fields of types `A`, `B`, `C`, check if all of them are either:
 - Bounded (`A: ~const Drop`, `B: Copy`)
 - Known to be able to destruct at compile time (`C = i32`, `struct C(i32)`, `C = some_fn`)

2. Don't treat trait functions marked with `#[default_method_body_is_const]` as stable const fns when checking `const_for` and `const_try` feature gates.

I think anyone can review this, so no r? this time.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 25, 2021
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#89359 (Various fixes for const_trait_impl)
 - rust-lang#90499 (Link with default MACOSX_DEPLOYMENT_TARGET if not otherwise specified.)
 - rust-lang#91096 (Print associated types on opaque `impl Trait` types)
 - rust-lang#91111 (Do not visit attributes in `ItemLowerer`.)
 - rust-lang#91162 (explain why CTFE/Miri perform truncation on shift offset)
 - rust-lang#91185 (Remove `-Z force-overflow-checks`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 90dd7c0 into rust-lang:master Nov 25, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_trait_impl `#![feature(const_trait_impl)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants