Auto merge of #9183 - weihanglo:refactor/straighforward-deref, r=alexcrichton

refactor: make deref intentions more straightforward

Just some little tweaks to make intentions of deref more straightforward.
This commit is contained in:
bors 2021-02-18 15:11:16 +00:00
commit adb35807a3
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(), edition: &self.edition().to_string(),
required_features: self required_features: self
.required_features() .required_features()
.map(|rf| rf.iter().map(|s| &**s).collect()), .map(|rf| rf.iter().map(|s| s.as_str()).collect()),
doc: self.documented(), doc: self.documented(),
doctest: self.doctested() && self.doctestable(), doctest: self.doctested() && self.doctestable(),
test: self.tested(), test: self.tested(),

View File

@ -271,20 +271,12 @@ impl<'src> SourceMap<'src> {
/// Like `HashMap::get`. /// Like `HashMap::get`.
pub fn get(&self, id: SourceId) -> Option<&(dyn Source + 'src)> { pub fn get(&self, id: SourceId) -> Option<&(dyn Source + 'src)> {
let source = self.map.get(&id); self.map.get(&id).map(|s| s.as_ref())
source.map(|s| {
let s: &(dyn Source + 'src) = &**s;
s
})
} }
/// Like `HashMap::get_mut`. /// Like `HashMap::get_mut`.
pub fn get_mut(&mut self, id: SourceId) -> Option<&mut (dyn Source + 'src)> { pub fn get_mut(&mut self, id: SourceId) -> Option<&mut (dyn Source + 'src)> {
self.map.get_mut(&id).map(|s| { self.map.get_mut(&id).map(|s| s.as_mut())
let s: &mut (dyn Source + 'src) = &mut **s;
s
})
} }
/// Like `HashMap::get`, but first calculates the `SourceId` from a `PackageId`. /// 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)?; f.read_to_string(&mut s)?;
Ok(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) (orig.ok(), out, ws_root)
} }

View File

@ -74,10 +74,7 @@ fn sync(
opts: &VendorOptions<'_>, opts: &VendorOptions<'_>,
) -> CargoResult<VendorConfig> { ) -> CargoResult<VendorConfig> {
let canonical_destination = opts.destination.canonicalize(); let canonical_destination = opts.destination.canonicalize();
let canonical_destination = canonical_destination let canonical_destination = canonical_destination.as_deref().unwrap_or(opts.destination);
.as_ref()
.map(|p| &**p)
.unwrap_or(opts.destination);
paths::create_dir_all(&canonical_destination)?; paths::create_dir_all(&canonical_destination)?;
let mut to_remove = HashSet::new(); let mut to_remove = HashSet::new();