Skip to content

Commit adb3580

Browse files
committed
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.
2 parents 1ca930b + dfe4e67 commit adb3580

File tree

4 files changed

+5
-16
lines changed

4 files changed

+5
-16
lines changed

src/cargo/core/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl ser::Serialize for Target {
285285
edition: &self.edition().to_string(),
286286
required_features: self
287287
.required_features()
288-
.map(|rf| rf.iter().map(|s| &**s).collect()),
288+
.map(|rf| rf.iter().map(|s| s.as_str()).collect()),
289289
doc: self.documented(),
290290
doctest: self.doctested() && self.doctestable(),
291291
test: self.tested(),

src/cargo/core/source/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,12 @@ impl<'src> SourceMap<'src> {
271271

272272
/// Like `HashMap::get`.
273273
pub fn get(&self, id: SourceId) -> Option<&(dyn Source + 'src)> {
274-
let source = self.map.get(&id);
275-
276-
source.map(|s| {
277-
let s: &(dyn Source + 'src) = &**s;
278-
s
279-
})
274+
self.map.get(&id).map(|s| s.as_ref())
280275
}
281276

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

290282
/// Like `HashMap::get`, but first calculates the `SourceId` from a `PackageId`.

src/cargo/ops/lockfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn resolve_to_string_orig(
9696
f.read_to_string(&mut s)?;
9797
Ok(s)
9898
});
99-
let out = serialize_resolve(resolve, orig.as_ref().ok().map(|s| &**s));
99+
let out = serialize_resolve(resolve, orig.as_deref().ok());
100100
(orig.ok(), out, ws_root)
101101
}
102102

src/cargo/ops/vendor.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ fn sync(
7474
opts: &VendorOptions<'_>,
7575
) -> CargoResult<VendorConfig> {
7676
let canonical_destination = opts.destination.canonicalize();
77-
let canonical_destination = canonical_destination
78-
.as_ref()
79-
.map(|p| &**p)
80-
.unwrap_or(opts.destination);
77+
let canonical_destination = canonical_destination.as_deref().unwrap_or(opts.destination);
8178

8279
paths::create_dir_all(&canonical_destination)?;
8380
let mut to_remove = HashSet::new();

0 commit comments

Comments
 (0)