Skip to content

Commit c666ee4

Browse files
Fix some clippy warnings
1 parent 87d0fa1 commit c666ee4

File tree

14 files changed

+30
-35
lines changed

14 files changed

+30
-35
lines changed

src/checker.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,21 @@ impl Checker {
356356
Problem::UsesBuildScript(pkg_id.clone()).into()
357357
}
358358

359-
pub(crate) fn pkg_ids_from_source_path(
360-
&self,
359+
pub(crate) fn pkg_ids_from_source_path<'checker>(
360+
&'checker self,
361361
source_path: &Path,
362-
) -> Result<Cow<Vec<PackageId>>> {
362+
) -> Result<Cow<'checker, [PackageId]>> {
363363
self.opt_pkg_ids_from_source_path(source_path)
364364
.ok_or_else(|| anyhow!("Couldn't find crate name for {}", source_path.display(),))
365365
}
366366

367-
pub(crate) fn opt_pkg_ids_from_source_path(
368-
&self,
367+
pub(crate) fn opt_pkg_ids_from_source_path<'checker>(
368+
&'checker self,
369369
source_path: &Path,
370-
) -> Option<Cow<Vec<PackageId>>> {
370+
) -> Option<Cow<'checker, [PackageId]>> {
371371
self.path_to_pkg_ids
372372
.get(source_path)
373-
.map(Cow::Borrowed)
373+
.map(|ids| Cow::Borrowed(ids.as_slice()))
374374
.or_else(|| {
375375
// If the source path is from the rust standard library, or from one of the
376376
// precompiled crates that comes with the standard library, then report no crates.

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ mod tests {
479479
fn check_unknown_field(context: &str) {
480480
// Make sure that without the unknown field, it parses OK.
481481
parse(context).unwrap();
482-
assert!(parse(&format!("{}\n no_such_field = 1\n", context)).is_err());
482+
assert!(parse(&format!("{context}\n no_such_field = 1\n")).is_err());
483483
}
484484

485485
#[test]

src/crate_index.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,7 @@ impl PackageId {
248248
let name = get_env("CARGO_PKG_NAME")?;
249249
let version_string = get_env("CARGO_PKG_VERSION")?;
250250
let version = Version::parse(&version_string).with_context(|| {
251-
format!(
252-
"Package `{}` has invalid version string `{}`",
253-
name, version_string
254-
)
251+
format!("Package `{name}` has invalid version string `{version_string}`")
255252
})?;
256253
let non_unique_pkg_names = get_env(MULTIPLE_VERSION_PKG_NAMES_ENV)?;
257254
let name_is_unique = non_unique_pkg_names.split(',').all(|p| p != name);
@@ -267,7 +264,7 @@ impl PackageId {
267264
&self.version
268265
}
269266

270-
pub(crate) fn crate_name(&self) -> Cow<str> {
267+
pub(crate) fn crate_name<'id>(&'id self) -> Cow<'id, str> {
271268
if self.name.contains('-') {
272269
self.name.replace('-', "_").into()
273270
} else {

src/crate_index/lib_tree.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ impl LibTreeBuilder<'_> {
7979
.context("Failed to parse package version from `cargo tree`")?;
8080
let packages_with_name = self.pkg_name_to_ids.get(pkg_name).with_context(|| {
8181
format!(
82-
"`cargo tree` output contained package `{}` not in `cargo metadata` output",
83-
pkg_name
82+
"`cargo tree` output contained package `{pkg_name}` not in `cargo metadata` output"
8483
)
8584
})?;
8685
let package_id = packages_with_name

src/location.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Display for SourceLocation {
5050
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5151
write!(f, "{} [{}", self.filename.display(), self.line)?;
5252
if let Some(column) = self.column {
53-
write!(f, ":{}", column)?;
53+
write!(f, ":{column}")?;
5454
}
5555
write!(f, "]")
5656
}

src/names.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ impl Namespace {
8181
}
8282
}
8383

84-
impl DebugName<'_> {
85-
pub(crate) fn names_iterator(&self) -> NamesIterator<NonMangledIterator> {
84+
impl<'input> DebugName<'input> {
85+
pub(crate) fn names_iterator<'a>(&'a self) -> NamesIterator<'a, NonMangledIterator<'a>> {
8686
NamesIterator::new(NonMangledIterator::new(
8787
&self.namespace.parts,
8888
self.name.as_ref(),
@@ -254,7 +254,7 @@ impl<'data, I: Clone + Iterator<Item = DemangleToken<'data>>> Iterator
254254
if self.as_final == Some(text)
255255
&& self
256256
.as_final
257-
.is_some_and(|t| t.as_ptr() as usize == text.as_ptr() as usize)
257+
.is_some_and(|t| std::ptr::eq(t.as_ptr(), text.as_ptr()))
258258
{
259259
// This text was already output as the final part of an as-name. Ignore it.
260260
continue;
@@ -343,15 +343,15 @@ impl<'data, I: Clone + Iterator<Item = DemangleToken<'data>>> Iterator
343343
}
344344
}
345345

346-
impl DebugName<'_> {
346+
impl<'input> DebugName<'input> {
347347
pub(crate) fn to_heap(&self) -> DebugName<'static> {
348348
DebugName {
349349
namespace: self.namespace.clone(),
350350
name: self.name.to_heap(),
351351
}
352352
}
353353

354-
pub(crate) fn new(namespace: Namespace, name: &str) -> DebugName {
354+
pub(crate) fn new(namespace: Namespace, name: &'input str) -> DebugName<'input> {
355355
DebugName {
356356
namespace,
357357
name: Utf8Bytes::Borrowed(name),
@@ -449,7 +449,7 @@ impl Display for SymbolOrDebugName {
449449

450450
impl Debug for Name {
451451
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
452-
write!(f, "Name({})", self)
452+
write!(f, "Name({self})")
453453
}
454454
}
455455

src/problem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn display_usages(
427427
for u in local_usages {
428428
write!(f, " -> {} [{}", u.to_source, u.source_location.line(),)?;
429429
if let Some(column) = u.source_location.column() {
430-
write!(f, ":{}", column)?;
430+
write!(f, ":{column}")?;
431431
}
432432
writeln!(f, "]")?;
433433
}

src/problem_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl ProblemStoreRef {
4848
outcome.recv().unwrap_or(Outcome::GiveUp)
4949
}
5050

51-
pub(crate) fn lock(&self) -> MutexGuard<ProblemStore> {
51+
pub(crate) fn lock<'a>(&'a self) -> MutexGuard<'a, ProblemStore> {
5252
self.inner.lock().unwrap()
5353
}
5454
}

src/sandbox/bubblewrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Display for CommandDisplay {
115115
let arg = arg.to_string_lossy();
116116
if arg.contains(' ') || arg.contains('"') || arg.is_empty() {
117117
// Use debug print, since that gives us quotes.
118-
write!(f, " {:?}", arg)?;
118+
write!(f, " {arg:?}")?;
119119
} else {
120120
// Print without quotes, since it probably isn't necessary.
121121
write!(f, " {arg}")?

src/symbol.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub(crate) struct Symbol<'data> {
1515
bytes: Bytes<'data>,
1616
}
1717

18-
impl Symbol<'_> {
19-
pub(crate) fn borrowed(data: &[u8]) -> Symbol {
18+
impl<'data> Symbol<'data> {
19+
pub(crate) fn borrowed(data: &'data [u8]) -> Symbol<'data> {
2020
Symbol {
2121
bytes: Bytes::Borrowed(data),
2222
}
@@ -40,7 +40,7 @@ impl Symbol<'_> {
4040
}
4141

4242
/// Splits the name of this symbol into names. See `crate::names::split_names` for details.
43-
pub(crate) fn names(&self) -> Result<NamesIterator<DemangleIterator>> {
43+
pub(crate) fn names<'a>(&'a self) -> Result<NamesIterator<'a, DemangleIterator<'a>>> {
4444
Ok(NamesIterator::new(DemangleIterator::new(self.to_str()?)))
4545
}
4646

src/symbol_graph/dwarf.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,9 @@ impl<'input> SymbolDebugInfoScanner<'input> {
494494
}
495495
}
496496

497-
fn path_from_opt_slice(slice: Option<gimli::EndianSlice<gimli::LittleEndian>>) -> &Path {
497+
fn path_from_opt_slice<'input>(
498+
slice: Option<gimli::EndianSlice<'input, gimli::LittleEndian>>,
499+
) -> &'input Path {
498500
slice
499501
.map(|dir| Path::new(OsStr::from_bytes(dir.slice())))
500502
.unwrap_or_else(|| Path::new(""))

src/ui/full_term/problems_ui.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,7 @@ fn usage_source_lines(
770770
} else {
771771
" "
772772
};
773-
let mut spans = vec![Span::from(format!(
774-
"{marker}{:gutter_width$}: ",
775-
line_number
776-
))];
773+
let mut spans = vec![Span::from(format!("{marker}{line_number:gutter_width$}: "))];
777774
let column = (line_number == target_line)
778775
.then(|| source_location.column())
779776
.flatten();

test_crates/crab-1/src/impl1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[inline(never)]
22
pub fn crab_1(v: u32) -> u32 {
3-
#[allow(clippy::transmute_num_to_bytes)]
3+
#[allow(unnecessary_transmutes)]
44
unsafe {
55
let mut v2: [u8; 4] = core::mem::transmute(v);
66
v2.reverse();

test_crates/crab-2/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub mod stuff {
3333
println!("CRAB_2_EXT_ENV: {:?}", option_env!("CRAB_2_EXT_ENV"));
3434

3535
let total: u32 = crate::DATA.iter().cloned().map(|byte| byte as u32).sum();
36-
println!("{}", total);
36+
println!("{total}");
3737
}
3838
}
3939

0 commit comments

Comments
 (0)