Skip to content

Fix warnings when using custom_trace macro from Rust 2024 Edition#188

Merged
Manishearth merged 1 commit into
Manishearth:masterfrom
todesking:fix/rust2024_warnings
May 20, 2025
Merged

Fix warnings when using custom_trace macro from Rust 2024 Edition#188
Manishearth merged 1 commit into
Manishearth:masterfrom
todesking:fix/rust2024_warnings

Conversation

@todesking
Copy link
Copy Markdown
Contributor

When using custom_trace! in the Rust 2024 Edition, calling mark directly can trigger an unsafe_op_in_unsafe_fn warning. However, wrapping mark in an unsafe block causes an unused_unsafe warning instead. This PR modifies the macro so that no warnings are emitted when mark is called inside an unsafe block.

#[derive(gc_derive::Finalize)]
pub struct Foo;

unsafe impl gc::Trace for Foo {
    gc::custom_trace!(this, {
        // warning[E0133]: call to unsafe function `<runtime::Foo as gc::Trace>::unroot::mark` is unsafe and requires unsafe block
        mark(this);
    });
}
#[derive(gc_derive::Finalize)]
pub struct Foo;

unsafe impl gc::Trace for Foo {
    gc::custom_trace!(this,  {
        // warning: unnecessary `unsafe` block
        unsafe { mark(this); }
    });
}

@Manishearth Manishearth merged commit f2224c1 into Manishearth:master May 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants