Skip to content

Commit

Permalink
Fixed non_local_definitions warning
Browse files Browse the repository at this point in the history
```text
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
   --> main/utility/macros.rs:148:13
    |
147 |           const $const_name : () = {
    |           ---------------------- move the `impl` block outside of this associated constant `_syscall_logger_waitid`
148 |               impl crate::utility::macros::SyscallLogger {
    |               ^^^^^-------------------------------------
    |                    |
    |                    `SyscallLogger` is not local
    |
   ::: main/host/syscall/handler/wait.rs:232:5
    |
232 | /     log_syscall!(
233 | |         waitid,
234 | |         /* rv */ kernel_pid_t,
235 | |         /* which */ c_int,
...   |
239 | |         /* uru */ *const std::ffi::c_void,
240 | |     );
    | |_____- in this macro invocation
    |
    = note: the macro `log_syscall` defines the non-local `impl`, and may need to be changed
    = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <rust-lang/rust#120363>
    = note: this warning originates in the macro `log_syscall` (in Nightly builds, run with -Z macro-backtrace for more info)
```
  • Loading branch information
stevenengler committed Oct 8, 2024
1 parent d84b563 commit 922bd39
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/utility/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ macro_rules! log_syscall {
paste::paste! { log_syscall!([< _syscall_logger_ $name >]; $name, $rv, $($args),*); }
};
($const_name:ident; $name:ident, $rv:ty, $($args:ty),*) => {
// we use a constant as a hack so that we can do "impl SyscallLogger { ... }" while
// already inside a "impl SyscallHandler { ... }" block
// We use a constant as a hack so that we can do "impl SyscallLogger { ... }" while already
// inside a "impl SyscallHandler { ... }" block. Apparently they may make this a hard error
// (with no way to opt-out with an `allow`) in the future:
// https://github.com/rust-lang/rust/issues/120363
#[doc(hidden)]
#[allow(non_upper_case_globals)]
#[allow(non_local_definitions)]
const $const_name : () = {
impl crate::utility::macros::SyscallLogger {
pub fn $name(
Expand Down

0 comments on commit 922bd39

Please sign in to comment.