Skip to content

Commit

Permalink
Auto merge of #9183 - weihanglo:refactor/straighforward-deref, r=alex…
Browse files Browse the repository at this point in the history
…crichton

refactor: make deref intentions more straightforward

Just some little tweaks to make intentions of deref more straightforward.
  • Loading branch information
bors committed Feb 18, 2021
2 parents 1ca930b + dfe4e67 commit adb3580
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl ser::Serialize for Target {
edition: &self.edition().to_string(),
required_features: self
.required_features()
.map(|rf| rf.iter().map(|s| &**s).collect()),
.map(|rf| rf.iter().map(|s| s.as_str()).collect()),
doc: self.documented(),
doctest: self.doctested() && self.doctestable(),
test: self.tested(),
Expand Down
12 changes: 2 additions & 10 deletions src/cargo/core/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,12 @@ impl<'src> SourceMap<'src> {

/// Like `HashMap::get`.
pub fn get(&self, id: SourceId) -> Option<&(dyn Source + 'src)> {
let source = self.map.get(&id);

source.map(|s| {
let s: &(dyn Source + 'src) = &**s;
s
})
self.map.get(&id).map(|s| s.as_ref())
}

/// Like `HashMap::get_mut`.
pub fn get_mut(&mut self, id: SourceId) -> Option<&mut (dyn Source + 'src)> {
self.map.get_mut(&id).map(|s| {
let s: &mut (dyn Source + 'src) = &mut **s;
s
})
self.map.get_mut(&id).map(|s| s.as_mut())
}

/// Like `HashMap::get`, but first calculates the `SourceId` from a `PackageId`.
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn resolve_to_string_orig(
f.read_to_string(&mut s)?;
Ok(s)
});
let out = serialize_resolve(resolve, orig.as_ref().ok().map(|s| &**s));
let out = serialize_resolve(resolve, orig.as_deref().ok());
(orig.ok(), out, ws_root)
}

Expand Down
5 changes: 1 addition & 4 deletions src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ fn sync(
opts: &VendorOptions<'_>,
) -> CargoResult<VendorConfig> {
let canonical_destination = opts.destination.canonicalize();
let canonical_destination = canonical_destination
.as_ref()
.map(|p| &**p)
.unwrap_or(opts.destination);
let canonical_destination = canonical_destination.as_deref().unwrap_or(opts.destination);

paths::create_dir_all(&canonical_destination)?;
let mut to_remove = HashSet::new();
Expand Down

0 comments on commit adb3580

Please sign in to comment.