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

Add auto traits and clone trait migrations for RFC2229 #84730

Merged
merged 4 commits into from
May 12, 2021

Conversation

roxelo
Copy link
Member

@roxelo roxelo commented Apr 30, 2021

This PR

  • renames the existent RFC2229 migration disjoint_capture_drop_reorder to disjoint_capture_migration
  • add additional migrations for auto traits and clone trait

Closes rust-lang/project-rfc-2229#29
Closes rust-lang/project-rfc-2229#28

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 30, 2021
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@arora-aman arora-aman left a comment

Choose a reason for hiding this comment

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

mostly nits

compiler/rustc_typeck/src/check/upvar.rs Outdated Show resolved Hide resolved

let cause = ObligationCause::misc(self.tcx.hir().span(var_hir_id), self.body_id);

let clone_obligation_should_hold = tcx
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe its better to do this with a helper like (just to reduce some degree of duplication):

  • Check need_2229_migrations_for_trait(var_hir_id, trait)
    • Checks for the specific var_hir meets trait bound
    • Loops over all captures and see if that trait bound is met

and then this function can just do

if need_2229_migrations..(var_hir_id, tcx.lang_items().clone_trait()) {
       auto_trait_reasons.insert("`Clone`");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

A helper function does seem like it would be good here.

compiler/rustc_typeck/src/check/upvar.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/upvar.rs Show resolved Hide resolved
compiler/rustc_typeck/src/check/upvar.rs Outdated Show resolved Hide resolved
drop_reorder_reason = true;
}

if need_some_migrations {
Copy link
Member

Choose a reason for hiding this comment

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

this can just be need need_auto_trait_migrations || need_drop_migrations

Copy link
Member Author

Choose a reason for hiding this comment

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

I still think it's simple to just use need_migrations. Since we do need to handle drop and auto_trait migration differently

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Do we have a test that causes some variable to be captured for multiple reasons -- e.g., because of Send but also because of destructors?

compiler/rustc_typeck/src/check/upvar.rs Outdated Show resolved Hide resolved
@roxelo roxelo force-pushed the rox-auto-trait branch from 25f3d74 to ad5e18d Compare May 6, 2021 18:58
@roxelo
Copy link
Member Author

roxelo commented May 6, 2021

Yes, there are a few tests that check that a variable is being captured for multiple reasons. For instance here and here

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

This looks about ready to land! One nit.


let cause = ObligationCause::misc(self.tcx.hir().span(var_hir_id), self.body_id);

let clone_obligation_should_hold = tcx
Copy link
Contributor

Choose a reason for hiding this comment

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

A helper function does seem like it would be good here.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 12, 2021

📌 Commit 564b4de has been approved by nikomatsakis

@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 May 12, 2021
@bors
Copy link
Contributor

bors commented May 12, 2021

⌛ Testing commit 564b4de with merge 28e2b29...

@bors
Copy link
Contributor

bors commented May 12, 2021

☀️ Test successful - checks-actions
Approved by: nikomatsakis
Pushing 28e2b29 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 12, 2021
@bors bors merged commit 28e2b29 into rust-lang:master May 12, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 12, 2021
@pnkfelix
Copy link
Member

Performance triage indicates that this PR introduced a 1.4% regression when fully compiling coercions-debug.

I don't think any performance hit was expected. However, it also seems like this may be just noise.

@@ -343,4 +343,7 @@ language_item_table! {
Range, sym::Range, range_struct, Target::Struct;
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct;
RangeTo, sym::RangeTo, range_to_struct, Target::Struct;
Send, sym::send, send_trait, Target::Trait;
UnwindSafe, sym::unwind_safe, unwind_safe_trait, Target::Trait;
RefUnwindSafe, sym::ref_unwind_safe, ref_unwind_safe_trait, Target::Trait;
Copy link
Contributor

Choose a reason for hiding this comment

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

I've just seen in #86603 that Send is made a lang item again.

I don't see why this PR needs to add new lang items, all of these could be diagnostic items instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's true, I forgot that diagnostic items were a thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

@petrochenkov Thanks for pointing this out, I'll try to have a fix done in the next few days.

Copy link
Member Author

Choose a reason for hiding this comment

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

@petrochenkov The fix is up for review #86726

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 8, 2021
…-rfc2229-migration, r=nikomatsakis

Use diagnostic items instead of lang items for rfc2229 migrations

This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in rust-lang#84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations.

r? `@nikomatsakis`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 8, 2021
…-rfc2229-migration, r=nikomatsakis

Use diagnostic items instead of lang items for rfc2229 migrations

This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in rust-lang#84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations.

r? ``@nikomatsakis``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 8, 2021
…-rfc2229-migration, r=nikomatsakis

Use diagnostic items instead of lang items for rfc2229 migrations

This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in rust-lang#84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations.

r? ```@nikomatsakis```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto traits with closures Possible closure not being Clone anymore
9 participants