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

Fix warnings in str.rs and binding_generated.rs #343

Merged
merged 2 commits into from
Jun 4, 2021

Conversation

nbdd0121
Copy link
Member

@nbdd0121 nbdd0121 commented Jun 3, 2021

No description provided.

@ksquirrel

This comment has been minimized.

@nbdd0121
Copy link
Member Author

nbdd0121 commented Jun 3, 2021

Related #340

@ojeda
Copy link
Member

ojeda commented Jun 3, 2021

Thanks a ton for these! For bindgen, let's open an issue with them...

@ojeda
Copy link
Member

ojeda commented Jun 3, 2021

Done: rust-lang/rust-bindgen#2063

@@ -89,8 +89,13 @@ impl CStr {
/// must not be mutated.
#[inline]
pub unsafe fn from_char_ptr<'a>(ptr: *const c_types::c_char) -> &'a Self {
let len = bindings::strlen(ptr) + 1;
Self::from_bytes_with_nul_unchecked(core::slice::from_raw_parts(ptr as _, len as _))
// SAFETY: `ptr` is a valid pointer to a `NUL`-terminated C string.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to mention that this property (and the ones just below) is guaranteed by the /// # Safety function prerequisite? Not sure how to formulate.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, // SAFETY comments should not just say "what", but "why" too, i.e. something like:

Suggested change
// SAFETY: `ptr` is a valid pointer to a `NUL`-terminated C string.
// SAFETY: The safety precondition guarantees `ptr` is a valid pointer to a `NUL`-terminated C string.

@@ -144,7 +149,8 @@ impl CStr {
// requires `ptr_metadata`).
// While none of them are current stable, it is very likely that one of
// them will eventually be.
&*(bytes as *const [u8] as *const Self)
// SAFETY: property of `bytes` guaranteed by the caller.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this follow from /// # Safety prerequisite above?

fn index(&self, index: ops::RangeFrom<usize>) -> &Self::Output {
// Delegate bounds checking to slice.
&self.as_bytes()[index.start..];
// Assign to _ to mute clippy's unnecessary operation warning.
let _ = &self.as_bytes()[index.start..];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this fix an unsafe warning?

Copy link
Member

Choose a reason for hiding this comment

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

If it is for an unused variable warning, yeah, it should be in a separate commit and ideally a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Split into a separate commit. Little reluctant to split into a separate PR since I always feel such a simple change don't warrant its own merge commit ;)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, in the future we will not have merge commits -- i.e. patches will be applied on top of each other in a linear fashion (when I add the sentient module to @ksquirrel :-)

@ojeda
Copy link
Member

ojeda commented Jun 4, 2021

Can be rebased now that #348 is in.

@ksquirrel

This comment has been minimized.

@ksquirrel

This comment has been minimized.

@nbdd0121
Copy link
Member Author

nbdd0121 commented Jun 4, 2021

E: Failed to fetch http://apt.llvm.org/focal/dists/llvm-toolchain-focal-12/main/binary-amd64/Packages  File has unexpected size (9429 != 9436). Mirror sync in progress? [IP: 151.101.250.49 443]

sigh

@ojeda
Copy link
Member

ojeda commented Jun 4, 2021

That is GitHub LLVM for you :D

Copy link
Member

@ojeda ojeda left a comment

Choose a reason for hiding this comment

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

Nits since you have to push again thanks to LLVM ;)

rust/kernel/str.rs Outdated Show resolved Hide resolved
rust/kernel/str.rs Outdated Show resolved Hide resolved
rust/kernel/str.rs Outdated Show resolved Hide resolved
@ksquirrel
Copy link
Member

Review of 14f1c7ca98cc:

  • ⚠️ The PR body message looks too short.
  • ✔️ Commit edfd6af: Looks fine!
  • ✔️ Commit 14f1c7c: Looks fine!

@ojeda ojeda merged commit c82b757 into Rust-for-Linux:rust Jun 4, 2021
@nbdd0121 nbdd0121 deleted the warnings branch June 10, 2021 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants