-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[swap
] lints now check if there is no_std
or no_core
attribute
#7877
Conversation
r? @camsteffen (rust-highfive has picked a reviewer for you, use r? to override) |
clippy_lints/src/swap.rs
Outdated
"" | ||
} else { | ||
"core" | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use one more util std_or_core() -> Option<&'static str>
. Shouldn't use empty strings as "none"`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was going for a direct return there on the last else statement, but I did this as a workaround since if_not_else
is warning this
let sugg = if !is_no_std_crate(cx) {
"std"
} else if !is_no_core_crate(cx) {
"core"
} else {
return;
};
Now that #7895 is merged, I think we can go for the above, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think std_or_core
would be good to have in clippy_utils
. You could sneak in a let-else.
let Some(sugg) = std_or_core(cx) else { return };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let-else
sounds amazing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh whoops, semicolon-if-nothing-returned
FP on this?
let Some(sugg) = std_or_core(cx) else { return };
produces
--> src/swap.rs:116:5
|
116 | let Some(sugg) = std_or_core(cx) else { return };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `let Some(sugg) = std_or_core(cx) else { return };;`
|
= note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
I will open an issue for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but we need to do something about the false positive in the CI build. Would you be interested in fixing that in another PR?
Moved out reusable pieces from `is_automatically_derived` and `any_parent_is_automatically_derived`.
FP in CI build should be fixed by #7955 🙂 |
Nice. Can you squash some commits? |
This commit adds a `no_std` and `no_core` check on `swap` lint and additionally suggest `core::mem::swap` whenever possible. Remove warning if both `std` and `core` is not present.
Adds additional test to check for `swap` suggestion when `no_std` is present
Done |
@bors r+ thanks! |
📌 Commit dcd1a16 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Closes #7858
changelog: [
swap
] lints now check if there isno_std
orno_core
attribute