Skip to content

Commit b8253a7

Browse files
committed
Makes Clippy happier
1 parent 0ed518c commit b8253a7

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/fs.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn make_io_utf8_error() -> std::io::Error {
5050
}
5151

5252
fn io_bytes_to_str(vec: &[u8]) -> Result<&str, std::io::Error> {
53-
std::str::from_utf8(&vec)
53+
std::str::from_utf8(vec)
5454
.map_err(|_| make_io_utf8_error())
5555
}
5656

@@ -215,7 +215,7 @@ pub fn split_zip(p_bytes: &[u8]) -> (&[u8], Option<&[u8]>) {
215215
let mut search_offset = 0;
216216

217217
while search_offset < p_bytes.len() {
218-
if let Some(m) = ZIP_RE.find_at(&p_bytes, search_offset) {
218+
if let Some(m) = ZIP_RE.find_at(p_bytes, search_offset) {
219219
let idx = m.start();
220220
let next_char_idx = m.end();
221221

@@ -241,9 +241,9 @@ pub fn split_virtual(p_bytes: &[u8]) -> std::io::Result<(usize, Option<(usize, u
241241
static ref VIRTUAL_RE: Regex = Regex::new("(?:^|/)((?:\\$\\$virtual|__virtual__)/[a-f0-9]+/([0-9]+)/)").unwrap();
242242
}
243243

244-
if let Some(m) = VIRTUAL_RE.captures(&p_bytes) {
244+
if let Some(m) = VIRTUAL_RE.captures(p_bytes) {
245245
if let (Some(main), Some(depth)) = (m.get(1), m.get(2)) {
246-
if let Ok(depth_n) = str::parse(io_bytes_to_str(&depth.as_bytes())?) {
246+
if let Ok(depth_n) = str::parse(io_bytes_to_str(depth.as_bytes())?) {
247247
return Ok((main.start(), Some((main.end() - main.start(), depth_n))));
248248
}
249249
}
@@ -254,9 +254,8 @@ pub fn split_virtual(p_bytes: &[u8]) -> std::io::Result<(usize, Option<(usize, u
254254

255255
pub fn vpath(p: &Path) -> std::io::Result<VPath> {
256256
let p_str = arca::path::normalize_path(
257-
p.as_os_str()
257+
&p.as_os_str()
258258
.to_string_lossy()
259-
.to_string()
260259
);
261260

262261
let p_bytes = p_str
@@ -299,7 +298,7 @@ pub fn vpath(p: &Path) -> std::io::Result<VPath> {
299298
io_bytes_to_str(&archive_path_u8[base_path_len..archive_path_u8.len()])?.to_string(),
300299
io_bytes_to_str(&archive_path_u8[base_path_len + virtual_len..archive_path_u8.len()])?.to_string(),
301300
));
302-
} else if let None = zip_path_u8 {
301+
} else if zip_path_u8.is_none() {
303302
return Ok(VPath::Native(PathBuf::from(p_str)));
304303
}
305304

src/lib.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,10 @@ pub fn find_closest_pnp_manifest_path<P: AsRef<Path>>(p: P) -> Option<PathBuf> {
149149

150150
if pnp_path.exists() {
151151
Some(pnp_path)
152+
} else if let Some(directory_path) = p.as_ref().parent() {
153+
find_closest_pnp_manifest_path(directory_path)
152154
} else {
153-
if let Some(directory_path) = p.as_ref().parent() {
154-
find_closest_pnp_manifest_path(directory_path)
155-
} else {
156-
None
157-
}
155+
None
158156
}
159157
}
160158

@@ -233,7 +231,7 @@ pub fn init_pnp_manifest<P: AsRef<Path>>(manifest: &mut Manifest, p: P) {
233231
}
234232

235233
pub fn find_pnp_manifest(parent: &Path) -> Result<Option<Manifest>, Error> {
236-
find_closest_pnp_manifest_path(parent).map_or(Ok(None), |p| Ok(Some(load_pnp_manifest(&p)?)))
234+
find_closest_pnp_manifest_path(parent).map_or(Ok(None), |p| Ok(Some(load_pnp_manifest(p)?)))
237235
}
238236

239237
pub fn find_locator<'a, P: AsRef<Path>>(manifest: &'a Manifest, path: &P) -> Option<&'a PackageLocator> {
@@ -270,8 +268,8 @@ pub fn is_excluded_from_fallback(manifest: &Manifest, locator: &PackageLocator)
270268
pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(manifest: &Manifest, specifier: &str, parent: P) -> Result<Resolution, Error> {
271269
let (ident, module_path) = parse_bare_identifier(specifier)?;
272270

273-
if let Some(parent_locator) = find_locator(&manifest, &parent) {
274-
let parent_pkg = get_package(&manifest, parent_locator)?;
271+
if let Some(parent_locator) = find_locator(manifest, &parent) {
272+
let parent_pkg = get_package(manifest, parent_locator)?;
275273

276274
let mut reference_or_alias: Option<PackageDependency> = None;
277275
let mut is_set = false;
@@ -283,7 +281,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(manifest: &Manifest,
283281
}
284282
}
285283

286-
if !is_set && manifest.enable_top_level_fallback && !is_excluded_from_fallback(&manifest, parent_locator) {
284+
if !is_set && manifest.enable_top_level_fallback && !is_excluded_from_fallback(manifest, parent_locator) {
287285
if let Some(fallback_resolution) = manifest.fallback_pool.get(&ident) {
288286
reference_or_alias = fallback_resolution.clone();
289287
is_set = true;
@@ -296,13 +294,13 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(manifest: &Manifest,
296294

297295
if let Some(resolution) = reference_or_alias {
298296
let dependency_pkg = match resolution {
299-
PackageDependency::Reference(reference) => get_package(&manifest, &PackageLocator { name: ident, reference }),
300-
PackageDependency::Alias(name, reference) => get_package(&manifest, &PackageLocator { name, reference }),
297+
PackageDependency::Reference(reference) => get_package(manifest, &PackageLocator { name: ident, reference }),
298+
PackageDependency::Alias(name, reference) => get_package(manifest, &PackageLocator { name, reference }),
301299
}?;
302300

303-
Ok(Resolution::Package(dependency_pkg.package_location.clone(), module_path.clone()))
301+
Ok(Resolution::Package(dependency_pkg.package_location.clone(), module_path))
304302
} else {
305-
return Err(Error::FailedResolution);
303+
Err(Error::FailedResolution)
306304
}
307305
} else {
308306
Ok(Resolution::Specifier(specifier.to_string()))
@@ -311,7 +309,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(manifest: &Manifest,
311309

312310
pub fn resolve_to_unqualified<P: AsRef<Path>>(specifier: &str, parent: P, config: &ResolutionConfig) -> Result<Resolution, Error> {
313311
if let Some(manifest) = (config.host.find_pnp_manifest)(parent.as_ref())? {
314-
resolve_to_unqualified_via_manifest(&manifest, &specifier, &parent)
312+
resolve_to_unqualified_via_manifest(&manifest, specifier, &parent)
315313
} else {
316314
Ok(Resolution::Specifier(specifier.to_string()))
317315
}

0 commit comments

Comments
 (0)