refactor: make deref intentions more clear

This commit is contained in:
Weihang Lo 2021-02-18 12:16:23 +08:00
parent 1ca930b6c9
commit dfe4e670b1
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
4 changed files with 5 additions and 16 deletions

View File

@ -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(),

View File

@ -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`.

View File

@ -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)
}

View File

@ -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();