FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix workaround false positive clippy lint `reversed_empty_ranges` by ModProg · Pull Request #1279 · rust-ndarray/ndarray · GitHub

fix workaround false positive clippy lint reversed_empty_ranges - #1279

Closed
ModProg wants to merge 1 commit into
rust-ndarray:masterfrom
ModProg:add_clippy_allow_to_s
Closed

fix workaround false positive clippy lint reversed_empty_ranges#1279
ModProg wants to merge 1 commit into
rust-ndarray:masterfrom
ModProg:add_clippy_allow_to_s

Conversation

ModProg commented Apr 23, 2023

Copy link
Copy Markdown

As the rust-clippy issue rust-lang/rust-clippy#5808 doesn't seam to make much progress I propose to just allow the lint for s![] macro invocations for now.

The let = ... is necessary, because attributes are not allowed on expressions
currently (rust-lang/rust#15701).

ModProg commented Apr 30, 2023

Copy link
Copy Markdown
Author

@bluss removed the depricated zip

bluss commented Apr 30, 2023
edited
Loading

Copy link
Copy Markdown
Member

Can we hold off on removing the deprecated zip until it can be replaced by std::iter::zip? That's after all the whole point of it, to use the function version :slightly_smiling_face:

(Function zip is the best 🙂 )

ModProg commented Apr 30, 2023

Copy link
Copy Markdown
Author

Yeah no problem, only did so because the ci was failing because of it.

ModProg force-pushed the add_clippy_allow_to_s branch from 57b0486 to d855c70 Compare April 30, 2023 22:12
Comment thread src/slice.rs Outdated
]
{
#[allow(clippy::reversed_empty_ranges)]
let slice = $crate::s![@parse

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Did you try using #![allow(clippy::reversed_empty_ranges)] to allow this for the block and thereby avoiding the temporary binding? (Tail expressions do influence lifetime extension of temporaries and hence I would like to avoid changing this if it can be avoided.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

attributes on expressions are experimental

Wouldn't work, as it needs a statement to apply the attribute

adamreichold May 23, 2023
edited
Loading

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Note the exclamation mark. This is similar to the form used at the beginning of a module to apply a directive to the whole module. So this would apply to everything inside the block, which in this case is just a single expression.

ModProg May 23, 2023
edited
Loading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
($($t:tt)*) => {
    {
        #![allow(clippy::reversed_empty_ranges)]
        $crate::s![@parse
            ::core::marker::PhantomData::<$crate::Ix0>,
            ::core::marker::PhantomData::<$crate::Ix0>,
            []
            $($t)*
        ]
    }
};
error[E0658]: attributes on expressions are experimental
   --> /mnt/data-ssd/modprog/Development/Rust/ndarray/src/slice.rs:871:13
    |
775 | macro_rules! s(
    | -------------- in this expansion of `s!`
...
871 |             #![allow(clippy::reversed_empty_ranges)]
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
   ::: tests/array.rs:202:16
    |
202 |     let info = s![1.., 1, NewAxis, ..;2];
    |                ------------------------- in this macro invocation
    |
    = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
    = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok, so this did work. Sorry for that.

Could you give the diff

diff --git a/src/slice.rs b/src/slice.rs
index 0146d6db..53763ae2 100644
--- a/src/slice.rs
+++ b/src/slice.rs
@@ -779,7 +779,7 @@ macro_rules! s(
             r => {
                 let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim);
                 let out_dim = $crate::SliceNextDim::next_out_dim(&r, $out_dim);
-                #[allow(unsafe_code)]
+                #[allow(unsafe_code, clippy::reversed_empty_ranges)]
                 unsafe {
                     $crate::SliceInfo::new_unchecked(
                         [$($stack)* $crate::s!(@convert r, $s)],
@@ -796,7 +796,7 @@ macro_rules! s(
             r => {
                 let in_dim = $crate::SliceNextDim::next_in_dim(&r, $in_dim);
                 let out_dim = $crate::SliceNextDim::next_out_dim(&r, $out_dim);
-                #[allow(unsafe_code)]
+                #[allow(unsafe_code, clippy::reversed_empty_ranges)]
                 unsafe {
                     $crate::SliceInfo::new_unchecked(
                         [$($stack)* $crate::s!(@convert r)],

a try? It does work for me without forcing the slice info into a local binding.

If it does, could use this approach and rebase this on the current master branch?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That didn't work, but I found a different solution, using two blocks to convince rust to allow an attribute on an expression.

ModProg force-pushed the add_clippy_allow_to_s branch from d855c70 to aff63a6 Compare May 24, 2023 18:27

akern40 commented May 19, 2025

Copy link
Copy Markdown
Collaborator

This lint is no longer triggered after #1196 was merged.

akern40 closed this May 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL