-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 some clippy lints for library/std/src/sys/windows #118154
Changes from all commits
ad12be3
533de2b
6c22e57
bfbeb3e
fe25569
4273459
2454263
9e42456
b962ae1
220217a
8c85c5b
4c084c5
d7e1f1c
c15adf6
852c038
6c8ebf1
b9fe367
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ impl<'a> IoSlice<'a> { | |
|
||
#[inline] | ||
pub fn as_slice(&self) -> &[u8] { | ||
unsafe { slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this is Since it's not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true. Though we're a bit at the mercy of the win32metadata project here (which is what our bindings are ultimately generated from) which might not necessarily follow what we think a |
||
unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) } | ||
} | ||
} | ||
|
||
|
@@ -70,12 +70,12 @@ impl<'a> IoSliceMut<'a> { | |
|
||
#[inline] | ||
pub fn as_slice(&self) -> &[u8] { | ||
unsafe { slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) } | ||
unsafe { slice::from_raw_parts(self.vec.buf, self.vec.len as usize) } | ||
} | ||
|
||
#[inline] | ||
pub fn as_mut_slice(&mut self) -> &mut [u8] { | ||
unsafe { slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.len as usize) } | ||
unsafe { slice::from_raw_parts_mut(self.vec.buf, self.vec.len as usize) } | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,7 +195,7 @@ fn write_valid_utf8_to_console(handle: c::HANDLE, utf8: &str) -> io::Result<usiz | |
MaybeUninit::slice_assume_init_ref(&utf16[..result as usize]) | ||
}; | ||
|
||
let mut written = write_u16s(handle, &utf16)?; | ||
let mut written = write_u16s(handle, utf16)?; | ||
|
||
// Figure out how many bytes of as UTF-8 were written away as UTF-16. | ||
if written == utf16.len() { | ||
|
@@ -207,7 +207,7 @@ fn write_valid_utf8_to_console(handle: c::HANDLE, utf8: &str) -> io::Result<usiz | |
// write the missing surrogate out now. | ||
// Buffering it would mean we have to lie about the number of bytes written. | ||
let first_code_unit_remaining = utf16[written]; | ||
if first_code_unit_remaining >= 0xDCEE && first_code_unit_remaining <= 0xDFFF { | ||
if matches!(first_code_unit_remaining, 0xDCEE..=0xDFFF) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirmed that using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, so long as there's only a single range in the (If there's multiple then things get complicated, see #103024 (comment) if you're curious.) |
||
// low surrogate | ||
// We just hope this works, and give up otherwise | ||
let _ = write_u16s(handle, &utf16[written..written + 1]); | ||
|
@@ -266,7 +266,7 @@ impl io::Read for Stdin { | |
let mut bytes_copied = self.incomplete_utf8.read(buf); | ||
|
||
if bytes_copied == buf.len() { | ||
return Ok(bytes_copied); | ||
Ok(bytes_copied) | ||
} else if buf.len() - bytes_copied < 4 { | ||
// Not enough space to get a UTF-8 byte. We will use the incomplete UTF8. | ||
let mut utf16_buf = [MaybeUninit::new(0); 1]; | ||
|
@@ -332,7 +332,7 @@ fn read_u16s_fixup_surrogates( | |
// and it is not 0, so we know that `buf[amount - 1]` have been | ||
// initialized. | ||
let last_char = unsafe { buf[amount - 1].assume_init() }; | ||
if last_char >= 0xD800 && last_char <= 0xDBFF { | ||
if matches!(last_char, 0xD800..=0xDBFF) { | ||
// high surrogate | ||
*surrogate = last_char; | ||
amount -= 1; | ||
|
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.
Can we uplift this clippy lint? 🙂
(Not in this PR, obviously)
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.
That's
needless_borrows_for_generic_args
. There's also the relatedneedless_borrow
which found a lot too!