-
Notifications
You must be signed in to change notification settings - Fork 19
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
fix: add #[must_use]
to volatile types, read
, and as_raw_ptr
#58
Conversation
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
@@ -82,6 +82,7 @@ where | |||
/// }; | |||
/// assert_eq!(pointer.read(), 42); | |||
/// ``` | |||
#[must_use] |
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.
A user might be calling this function to cause side-effects and not necessarily because they're interested in the value.
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.
Ah, that's true.
For those cases, it might still be beneficial to be explicit about wanting side effects by discarding the value:
let _side_effect = pointer.read();
I can remove it, if you want me to, though. I would prefer #[must_use]
and be explicit about side effects, but I have no strong opinion on this.
I'm not sure about this PR. I think the I guess it comes down to personal preference. In theory, we could add As one data point, the standard library didn't make array index or pointer read operations unsafe. The following example compiles without any warnings: use std::ops::Index;
fn main() {
let x = [1, 2, 3];
x[1];
x.index(1);
unsafe { std::ptr::read(&x[0]) };
} Clippy throws a warning for the array access, though:
I don't have a strong opinion about this and I'm happy to dicuss this further. |
"The I'd argue that this is the case for volatile pointers and references, though maybe not Regarding the types: Personally, I'd like the hint from the compiler that if I have a volatile pointer, no matter if created via |
I fully agree with you that compiler warnings are useful in these cases! I'm just trying to decide for some policy that we can follow for this crate. After thinking about this more, I agree that it's a good idea to add the
For
I don't know if read operations only for their side-effects are "common", so it's difficult to estimate whether a bare |
Yeah, that's what I am unsure of, too. I would not expect them to be common, but I don't have a lot of experience in this area yet. |
Let's merge this as-is and see how common such false-positive warnings are. We can still remove the warning later if it needs to be silenced too often. |
No description provided.