Avoid naming variables str
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.
This commit is contained in:
parent
fb546ee09b
commit
bb6bbfa13f
10 changed files with 34 additions and 34 deletions
|
@ -544,12 +544,12 @@ fn pretty_print_region_elements(elements: impl IntoIterator<Item = RegionElement
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
fn push_location_range(str: &mut String, location1: Location, location2: Location) {
|
fn push_location_range(s: &mut String, location1: Location, location2: Location) {
|
||||||
if location1 == location2 {
|
if location1 == location2 {
|
||||||
str.push_str(&format!("{location1:?}"));
|
s.push_str(&format!("{location1:?}"));
|
||||||
} else {
|
} else {
|
||||||
assert_eq!(location1.block, location2.block);
|
assert_eq!(location1.block, location2.block);
|
||||||
str.push_str(&format!(
|
s.push_str(&format!(
|
||||||
"{:?}[{}..={}]",
|
"{:?}[{}..={}]",
|
||||||
location1.block, location1.statement_index, location2.statement_index
|
location1.block, location1.statement_index, location2.statement_index
|
||||||
));
|
));
|
||||||
|
|
|
@ -704,8 +704,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
pub fn read_str(&self, mplace: &MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, &str> {
|
pub fn read_str(&self, mplace: &MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, &str> {
|
||||||
let len = mplace.len(self)?;
|
let len = mplace.len(self)?;
|
||||||
let bytes = self.read_bytes_ptr_strip_provenance(mplace.ptr(), Size::from_bytes(len))?;
|
let bytes = self.read_bytes_ptr_strip_provenance(mplace.ptr(), Size::from_bytes(len))?;
|
||||||
let str = std::str::from_utf8(bytes).map_err(|err| err_ub!(InvalidStr(err)))?;
|
let s = std::str::from_utf8(bytes).map_err(|err| err_ub!(InvalidStr(err)))?;
|
||||||
interp_ok(str)
|
interp_ok(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read from a local of the current frame. Convenience method for [`InterpCx::local_at_frame_to_op`].
|
/// Read from a local of the current frame. Convenience method for [`InterpCx::local_at_frame_to_op`].
|
||||||
|
|
|
@ -1017,9 +1017,9 @@ where
|
||||||
/// This is allocated in immutable global memory and deduplicated.
|
/// This is allocated in immutable global memory and deduplicated.
|
||||||
pub fn allocate_str_dedup(
|
pub fn allocate_str_dedup(
|
||||||
&mut self,
|
&mut self,
|
||||||
str: &str,
|
s: &str,
|
||||||
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
|
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
|
||||||
let bytes = str.as_bytes();
|
let bytes = s.as_bytes();
|
||||||
let ptr = self.allocate_bytes_dedup(bytes)?;
|
let ptr = self.allocate_bytes_dedup(bytes)?;
|
||||||
|
|
||||||
// Create length metadata for the string.
|
// Create length metadata for the string.
|
||||||
|
|
|
@ -234,10 +234,10 @@ declare_lint! {
|
||||||
declare_lint_pass!(NonSnakeCase => [NON_SNAKE_CASE]);
|
declare_lint_pass!(NonSnakeCase => [NON_SNAKE_CASE]);
|
||||||
|
|
||||||
impl NonSnakeCase {
|
impl NonSnakeCase {
|
||||||
fn to_snake_case(mut str: &str) -> String {
|
fn to_snake_case(mut name: &str) -> String {
|
||||||
let mut words = vec![];
|
let mut words = vec![];
|
||||||
// Preserve leading underscores
|
// Preserve leading underscores
|
||||||
str = str.trim_start_matches(|c: char| {
|
name = name.trim_start_matches(|c: char| {
|
||||||
if c == '_' {
|
if c == '_' {
|
||||||
words.push(String::new());
|
words.push(String::new());
|
||||||
true
|
true
|
||||||
|
@ -245,7 +245,7 @@ impl NonSnakeCase {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for s in str.split('_') {
|
for s in name.split('_') {
|
||||||
let mut last_upper = false;
|
let mut last_upper = false;
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if s.is_empty() {
|
if s.is_empty() {
|
||||||
|
|
|
@ -130,11 +130,11 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
|
||||||
|
|
||||||
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
|
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
|
||||||
match cfg.backtrace {
|
match cfg.backtrace {
|
||||||
Ok(str) => {
|
Ok(backtrace_target) => {
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer()
|
let fmt_layer = tracing_subscriber::fmt::layer()
|
||||||
.with_writer(io::stderr)
|
.with_writer(io::stderr)
|
||||||
.without_time()
|
.without_time()
|
||||||
.event_format(BacktraceFormatter { backtrace_target: str });
|
.event_format(BacktraceFormatter { backtrace_target });
|
||||||
let subscriber = subscriber.with(fmt_layer);
|
let subscriber = subscriber.with(fmt_layer);
|
||||||
tracing::subscriber::set_global_default(subscriber).unwrap();
|
tracing::subscriber::set_global_default(subscriber).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,14 +156,14 @@ impl Entries {
|
||||||
Entries { map: HashMap::with_capacity(capacity) }
|
Entries { map: HashMap::with_capacity(capacity) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert(&mut self, span: Span, str: &str, errors: &mut Errors) -> u32 {
|
fn insert(&mut self, span: Span, s: &str, errors: &mut Errors) -> u32 {
|
||||||
if let Some(prev) = self.map.get(str) {
|
if let Some(prev) = self.map.get(s) {
|
||||||
errors.error(span, format!("Symbol `{str}` is duplicated"));
|
errors.error(span, format!("Symbol `{s}` is duplicated"));
|
||||||
errors.error(prev.span_of_name, "location of previous definition".to_string());
|
errors.error(prev.span_of_name, "location of previous definition".to_string());
|
||||||
prev.idx
|
prev.idx
|
||||||
} else {
|
} else {
|
||||||
let idx = self.len();
|
let idx = self.len();
|
||||||
self.map.insert(str.to_string(), Preinterned { idx, span_of_name: span });
|
self.map.insert(s.to_string(), Preinterned { idx, span_of_name: span });
|
||||||
idx
|
idx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,14 +192,14 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
|
||||||
let mut entries = Entries::with_capacity(input.keywords.len() + input.symbols.len() + 10);
|
let mut entries = Entries::with_capacity(input.keywords.len() + input.symbols.len() + 10);
|
||||||
let mut prev_key: Option<(Span, String)> = None;
|
let mut prev_key: Option<(Span, String)> = None;
|
||||||
|
|
||||||
let mut check_order = |span: Span, str: &str, errors: &mut Errors| {
|
let mut check_order = |span: Span, s: &str, errors: &mut Errors| {
|
||||||
if let Some((prev_span, ref prev_str)) = prev_key {
|
if let Some((prev_span, ref prev_str)) = prev_key {
|
||||||
if str < prev_str {
|
if s < prev_str {
|
||||||
errors.error(span, format!("Symbol `{str}` must precede `{prev_str}`"));
|
errors.error(span, format!("Symbol `{s}` must precede `{prev_str}`"));
|
||||||
errors.error(prev_span, format!("location of previous symbol `{prev_str}`"));
|
errors.error(prev_span, format!("location of previous symbol `{prev_str}`"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prev_key = Some((span, str.to_string()));
|
prev_key = Some((span, s.to_string()));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate the listed keywords.
|
// Generate the listed keywords.
|
||||||
|
|
|
@ -1283,13 +1283,13 @@ impl fmt::Debug for Output {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let stdout_utf8 = str::from_utf8(&self.stdout);
|
let stdout_utf8 = str::from_utf8(&self.stdout);
|
||||||
let stdout_debug: &dyn fmt::Debug = match stdout_utf8 {
|
let stdout_debug: &dyn fmt::Debug = match stdout_utf8 {
|
||||||
Ok(ref str) => str,
|
Ok(ref s) => s,
|
||||||
Err(_) => &self.stdout,
|
Err(_) => &self.stdout,
|
||||||
};
|
};
|
||||||
|
|
||||||
let stderr_utf8 = str::from_utf8(&self.stderr);
|
let stderr_utf8 = str::from_utf8(&self.stderr);
|
||||||
let stderr_debug: &dyn fmt::Debug = match stderr_utf8 {
|
let stderr_debug: &dyn fmt::Debug = match stderr_utf8 {
|
||||||
Ok(ref str) => str,
|
Ok(ref s) => s,
|
||||||
Err(_) => &self.stderr,
|
Err(_) => &self.stderr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -142,11 +142,11 @@ impl AsRef<OsStr> for EnvKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ensure_no_nuls<T: AsRef<OsStr>>(str: T) -> io::Result<T> {
|
pub(crate) fn ensure_no_nuls<T: AsRef<OsStr>>(s: T) -> io::Result<T> {
|
||||||
if str.as_ref().encode_wide().any(|b| b == 0) {
|
if s.as_ref().encode_wide().any(|b| b == 0) {
|
||||||
Err(io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
|
Err(io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
|
||||||
} else {
|
} else {
|
||||||
Ok(str)
|
Ok(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,8 +204,8 @@ impl Wtf8Buf {
|
||||||
///
|
///
|
||||||
/// Since WTF-8 is a superset of UTF-8, this always succeeds.
|
/// Since WTF-8 is a superset of UTF-8, this always succeeds.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_str(str: &str) -> Wtf8Buf {
|
pub fn from_str(s: &str) -> Wtf8Buf {
|
||||||
Wtf8Buf { bytes: <[_]>::to_vec(str.as_bytes()), is_known_utf8: true }
|
Wtf8Buf { bytes: <[_]>::to_vec(s.as_bytes()), is_known_utf8: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
|
||||||
|
|
||||||
for result in diff::lines(expected, actual) {
|
for result in diff::lines(expected, actual) {
|
||||||
match result {
|
match result {
|
||||||
diff::Result::Left(str) => {
|
diff::Result::Left(s) => {
|
||||||
if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
|
if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
|
||||||
results.push(mismatch);
|
results.push(mismatch);
|
||||||
mismatch = Mismatch::new(line_number - context_queue.len() as u32);
|
mismatch = Mismatch::new(line_number - context_queue.len() as u32);
|
||||||
|
@ -41,11 +41,11 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
|
||||||
mismatch.lines.push(DiffLine::Context(line.to_owned()));
|
mismatch.lines.push(DiffLine::Context(line.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
mismatch.lines.push(DiffLine::Expected(str.to_owned()));
|
mismatch.lines.push(DiffLine::Expected(s.to_owned()));
|
||||||
line_number += 1;
|
line_number += 1;
|
||||||
lines_since_mismatch = 0;
|
lines_since_mismatch = 0;
|
||||||
}
|
}
|
||||||
diff::Result::Right(str) => {
|
diff::Result::Right(s) => {
|
||||||
if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
|
if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
|
||||||
results.push(mismatch);
|
results.push(mismatch);
|
||||||
mismatch = Mismatch::new(line_number - context_queue.len() as u32);
|
mismatch = Mismatch::new(line_number - context_queue.len() as u32);
|
||||||
|
@ -55,18 +55,18 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
|
||||||
mismatch.lines.push(DiffLine::Context(line.to_owned()));
|
mismatch.lines.push(DiffLine::Context(line.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
mismatch.lines.push(DiffLine::Resulting(str.to_owned()));
|
mismatch.lines.push(DiffLine::Resulting(s.to_owned()));
|
||||||
lines_since_mismatch = 0;
|
lines_since_mismatch = 0;
|
||||||
}
|
}
|
||||||
diff::Result::Both(str, _) => {
|
diff::Result::Both(s, _) => {
|
||||||
if context_queue.len() >= context_size {
|
if context_queue.len() >= context_size {
|
||||||
let _ = context_queue.pop_front();
|
let _ = context_queue.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
if lines_since_mismatch < context_size {
|
if lines_since_mismatch < context_size {
|
||||||
mismatch.lines.push(DiffLine::Context(str.to_owned()));
|
mismatch.lines.push(DiffLine::Context(s.to_owned()));
|
||||||
} else if context_size > 0 {
|
} else if context_size > 0 {
|
||||||
context_queue.push_back(str);
|
context_queue.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
line_number += 1;
|
line_number += 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue