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

Refactor impl_lcm_array macro to avoid using non-existing cfg option #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tvsfx
Copy link
Contributor

@tvsfx tvsfx commented Nov 8, 2024

To avoid having overlapping trait instances, the impl_lcm_array macro makes use of a skip identifier that expands to something akin to the following:

impl<T> SplitArray<[T; 32]> for [T; 32] {
    type Output = [[T; 32]; 32 / 32];
    fn split_mut_internal(&mut self) -> &mut Self::Output {
        unsafe { &mut *(self as *mut _ as *mut _) }
    }
}

However, in sufficiently modern versions of rustc this results in warnings, because skip is not a valid option for cfg:

warning: unexpected `cfg` condition name: `skip`
  --> src/encode/mod.rs:71:25
   |
71 |         $(#[cfg(all(not($nm), $nm))])*
   |                         ^^^
...
82 | impl_lcm_array!(32, skip / 32, 32);
   | ---------------------------------- in this macro invocation
   |
   = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
   = help: consider using a Cargo feature instead
   = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
            [lints.rust]
            unexpected_cfgs = { level = "warn", check-cfg = ['cfg(skip)'] }
   = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(skip)");` to the top of the `build.rs`
   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
   = note: `#[warn(unexpected_cfgs)]` on by default
   = note: this warning originates in the macro `impl_lcm_array` (in Nightly builds, run with -Z macro-backtrace for more info)

This PR fixxes the issue and updates the macro to use the more modern and accurate ? notation in the process

To avoid having overlapping trait instances, the `impl_lcm_array` macro makes use of a `skip` identifier that expands
to something akin to the following:

```rust
impl<T> SplitArray<[T; 32]> for [T; 32] {
    type Output = [[T; 32]; 32 / 32];
    fn split_mut_internal(&mut self) -> &mut Self::Output {
        unsafe { &mut *(self as *mut _ as *mut _) }
    }
}
```

However, in sufficiently modern versions of `rustc` this results in
warnings, because `skip` is not a valid option for `cfg`:

```sh
warning: unexpected `cfg` condition name: `skip`
  --> src/encode/mod.rs:71:25
   |
71 |         $(#[cfg(all(not($nm), $nm))])*
   |                         ^^^
...
82 | impl_lcm_array!(32, skip / 32, 32);
   | ---------------------------------- in this macro invocation
   |
   = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
   = help: consider using a Cargo feature instead
   = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
            [lints.rust]
            unexpected_cfgs = { level = "warn", check-cfg = ['cfg(skip)'] }
   = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(skip)");` to the top of the `build.rs`
   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
   = note: `#[warn(unexpected_cfgs)]` on by default
   = note: this warning originates in the macro `impl_lcm_array` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This commit fixxes the issue and updates the macro to use the more
modern and accurate `?` notation in the process
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.

1 participant