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

Coherence should allow fundamental types to impl traits when they are local #65738

Conversation

ohadravid
Copy link
Contributor

@ohadravid ohadravid commented Oct 23, 2019

After #64414, impl<T> Remote for Box<T> { } is disallowed, but it is also disallowed in liballoc, where Box is a local type!

Enabling #![feature(re_rebalance_coherence)] in liballoc results in:

error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
    --> src\liballoc\boxed.rs:1098:1
     |
1098 | impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `F` must be used as the type parameter for some local type

This PR relaxes uncover_fundamental_ty to skip local fundamental types.
I didn't add a test since liballoc already fails to compile, but I can add one if needed.

r? @nikomatsakis

cc #63599

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 23, 2019
@ohadravid ohadravid force-pushed the re-rebalance-coherence-allow-fundamental-local branch from f36742a to 67953fd Compare October 23, 2019 21:40
@Centril Centril added the F-re_rebalance_coherence `#![feature(re_rebalance_coherence)]` label Oct 24, 2019
@nikomatsakis
Copy link
Contributor

Heh, good catch @ohadravid -- I'm torn about the test. You're right that we don't need one in some sense but I think if you don't mind adding one it would help us to prevent similar oversights in the future.

@ohadravid ohadravid force-pushed the re-rebalance-coherence-allow-fundamental-local branch from 67953fd to 8f988bd Compare October 26, 2019 11:09
@ohadravid
Copy link
Contributor Author

ohadravid commented Oct 26, 2019

@nikomatsakis I added two tests which should prevent a regression.

BTW I can also open the stabilization PR for re_rebalance_coherence, I just wasn't sure if it was taken or not.

Original failures are:

LL | impl Remote for Local {}
   | ^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate

and

LL | impl<T> Remote for MyBox<T> {}                                                                             
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type      

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 26, 2019

📌 Commit 8f988bd 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 Oct 26, 2019
@nikomatsakis
Copy link
Contributor

@ohadravid thanks! And yes, a stabilization PR would be great! Please explicitly add r? @nikomatsakis on the PR, too.

Centril added a commit to Centril/rust that referenced this pull request Oct 26, 2019
…low-fundamental-local, r=nikomatsakis

Coherence should allow fundamental types to impl traits when they are local

After rust-lang#64414, `impl<T> Remote for Box<T> { }` is disallowed, but it is also disallowed in liballoc, where `Box` is a local type!

Enabling `#![feature(re_rebalance_coherence)]` in `liballoc` results in:
```
error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
    --> src\liballoc\boxed.rs:1098:1
     |
1098 | impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `F` must be used as the type parameter for some local type
```

This PR relaxes `uncover_fundamental_ty` to skip local fundamental types.
I didn't add a test since `liballoc` already fails to compile, but I can add one if needed.

r? @nikomatsakis

cc rust-lang#63599
Centril added a commit to Centril/rust that referenced this pull request Oct 26, 2019
…low-fundamental-local, r=nikomatsakis

Coherence should allow fundamental types to impl traits when they are local

After rust-lang#64414, `impl<T> Remote for Box<T> { }` is disallowed, but it is also disallowed in liballoc, where `Box` is a local type!

Enabling `#![feature(re_rebalance_coherence)]` in `liballoc` results in:
```
error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
    --> src\liballoc\boxed.rs:1098:1
     |
1098 | impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `F` must be used as the type parameter for some local type
```

This PR relaxes `uncover_fundamental_ty` to skip local fundamental types.
I didn't add a test since `liballoc` already fails to compile, but I can add one if needed.

r? @nikomatsakis

cc rust-lang#63599
Centril added a commit to Centril/rust that referenced this pull request Oct 27, 2019
…low-fundamental-local, r=nikomatsakis

Coherence should allow fundamental types to impl traits when they are local

After rust-lang#64414, `impl<T> Remote for Box<T> { }` is disallowed, but it is also disallowed in liballoc, where `Box` is a local type!

Enabling `#![feature(re_rebalance_coherence)]` in `liballoc` results in:
```
error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct<F>`)
    --> src\liballoc\boxed.rs:1098:1
     |
1098 | impl<F: ?Sized + Future + Unpin> Future for Box<F> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `F` must be used as the type parameter for some local type
```

This PR relaxes `uncover_fundamental_ty` to skip local fundamental types.
I didn't add a test since `liballoc` already fails to compile, but I can add one if needed.

r? @nikomatsakis

cc rust-lang#63599
bors added a commit that referenced this pull request Oct 27, 2019
Rollup of 6 pull requests

Successful merges:

 - #65566 (Use heuristics to suggest assignment)
 - #65738 (Coherence should allow fundamental types to impl traits when they are local)
 - #65777 (Don't ICE for completely unexpandable `impl Trait` types)
 - #65834 (Remove lint callback from driver)
 - #65839 (Clean up `check_consts` now that new promotion pass is implemented)
 - #65855 (Add long error explaination for E0666)

Failed merges:

r? @ghost
@bors bors merged commit 8f988bd into rust-lang:master Oct 27, 2019
@bors
Copy link
Contributor

bors commented Oct 27, 2019

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

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 27, 2019
@ohadravid ohadravid deleted the re-rebalance-coherence-allow-fundamental-local branch December 2, 2019 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-re_rebalance_coherence `#![feature(re_rebalance_coherence)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants