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

BTree: evaluate static type-related check at compile time #95005

Merged
merged 1 commit into from
Aug 26, 2022

Conversation

ssomers
Copy link
Contributor

@ssomers ssomers commented Mar 16, 2022

asserts like the ones replaced here would only go off when you run the right test cases, if the code were ever incorrectly changed such that rhey would trigger. But inspired on a nice forum question, they can be checked at compile time.

@rust-highfive
Copy link
Collaborator

r? @yaahc

(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 Mar 16, 2022
@yaahc yaahc added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Mar 18, 2022
Comment on lines 1645 to 1651
impl BorrowType for Owned {
// Traversal isn't needed, it happens using the result of `borrow_mut`.
// Reject evaluation, because traversal isn't needed. Instead traversal
// happens using the result of `borrow_mut`.
// By disabling traversal, and only creating new references to roots,
// we know that every reference of the `Owned` type is to a root node.
const PERMITS_TRAVERSAL: bool = false;
const TRAVERSAL_PERMIT: () = panic!();
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some UI tests to show the cases where this does and doesn't panic and to let us review the panic output?

Copy link
Contributor Author

@ssomers ssomers Apr 15, 2022

Choose a reason for hiding this comment

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

I don't think I can. These static asserts guard the private internals of node.rs. We have unit test of those internals, we can do positive compile tests, but a negative compile test of internals, I doubt the test framework caters for that. And surely we don't want to make this stuff public.

The way I tested this is to try to address the remaining FIXME on reborrow_mutin node.rs: disable the permit for Mut<'+> like it is disabled for Owned, and build errors point out the first place where a Mut handle is traversed. While without this PR, you have to run tests to see it, and you have to assume tests offer complete coverage. I've edited the PR description a bit.

@yaahc
Copy link
Member

yaahc commented Apr 29, 2022

r? rust-lang/libs

@rust-highfive rust-highfive assigned kennytm and unassigned yaahc Apr 29, 2022
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2022
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2022
@thomcc
Copy link
Member

thomcc commented Aug 25, 2022

r? @thomcc

@rust-highfive rust-highfive assigned thomcc and unassigned kennytm Aug 25, 2022
@thomcc
Copy link
Member

thomcc commented Aug 25, 2022

This looks fine to me. Sorry for the delay.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 25, 2022

📌 Commit ea4e5c2 has been approved by thomcc

It is now in the queue for this repository.

@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 Aug 25, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 26, 2022
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#95005 (BTree: evaluate static type-related check at compile time)
 - rust-lang#99742 (Add comments about stdout locking)
 - rust-lang#100128 (Document that `RawWakerVTable` functions must be thread-safe.)
 - rust-lang#100956 (Reduce right-side DOM size)
 - rust-lang#101006 (Fix doc cfg on reexports)
 - rust-lang#101012 (rustdoc: remove unused CSS for `.variants_table`)
 - rust-lang#101023 (rustdoc: remove `type="text/css"` from stylesheet links)
 - rust-lang#101031 (Remove unused build dependency)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e3148dc into rust-lang:master Aug 26, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 26, 2022
@ssomers ssomers deleted the btree_static_assert branch August 26, 2022 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants