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

clippy fixes: make some lifetimes anonymous and add send/sync to types::BoundRef #260

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
types: implement Send/Sync for BoundRef
Added a block comment inline explaining the safety.
apoelstra committed Jan 11, 2025
commit 5696096d4c011eaa8dae178ec5a002961c1ceeed
13 changes: 13 additions & 0 deletions src/types/context.rs
Original file line number Diff line number Diff line change
@@ -245,6 +245,19 @@ pub struct BoundRef {
index: usize,
}

// SAFETY: The pointer inside `BoundRef` is always (eventually) constructed from Arc::as_ptr
// from the slab of a type-inference context.
//
// Arc will prevent the pointer from ever changing, except to be deallocated when the last
// Arc goes away. But this occurs only when the context itself goes away, which in turn
// happens only when every type bound referring to the context goes away.
//
// If this were untrue, our use of `BoundRef` would lead to dereferences of a dangling
// pointer, and `Send`/`Sync` would be the least of our concerns!
unsafe impl Send for BoundRef {}
// SAFETY: see comment on `Send`
unsafe impl Sync for BoundRef {}

impl BoundRef {
pub fn assert_matches_context(&self, ctx: &Context) {
assert_eq!(