Skip to content

Commit

Permalink
Avoid naming variables str
Browse files Browse the repository at this point in the history
This renames variables named `str` to other names, to make sure `str`
always refers to a type.

It's confusing to read code where `str` (or another standard type name)
is used as an identifier. It also produces misleading syntax
highlighting.
  • Loading branch information
joshtriplett authored and gitbot committed Feb 20, 2025
1 parent 42c746f commit 01acc35
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,13 +1283,13 @@ impl fmt::Debug for Output {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let stdout_utf8 = str::from_utf8(&self.stdout);
let stdout_debug: &dyn fmt::Debug = match stdout_utf8 {
Ok(ref str) => str,
Ok(ref s) => s,
Err(_) => &self.stdout,
};

let stderr_utf8 = str::from_utf8(&self.stderr);
let stderr_debug: &dyn fmt::Debug = match stderr_utf8 {
Ok(ref str) => str,
Ok(ref s) => s,
Err(_) => &self.stderr,
};

Expand Down
6 changes: 3 additions & 3 deletions std/src/sys/pal/windows/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ impl AsRef<OsStr> for EnvKey {
}
}

pub(crate) fn ensure_no_nuls<T: AsRef<OsStr>>(str: T) -> io::Result<T> {
if str.as_ref().encode_wide().any(|b| b == 0) {
pub(crate) fn ensure_no_nuls<T: AsRef<OsStr>>(s: T) -> io::Result<T> {
if s.as_ref().encode_wide().any(|b| b == 0) {
Err(io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
} else {
Ok(str)
Ok(s)
}
}

Expand Down
4 changes: 2 additions & 2 deletions std/src/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ impl Wtf8Buf {
///
/// Since WTF-8 is a superset of UTF-8, this always succeeds.
#[inline]
pub fn from_str(str: &str) -> Wtf8Buf {
Wtf8Buf { bytes: <[_]>::to_vec(str.as_bytes()), is_known_utf8: true }
pub fn from_str(s: &str) -> Wtf8Buf {
Wtf8Buf { bytes: <[_]>::to_vec(s.as_bytes()), is_known_utf8: true }
}

pub fn clear(&mut self) {
Expand Down

0 comments on commit 01acc35

Please sign in to comment.