Skip to content

Commit ae4b792

Browse files
Remove MyFnOnce
1 parent 0bb6e14 commit ae4b792

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub fn prepare_target<'a, 'cfg>(
299299
// here. See documentation on `build_script_local_fingerprints`
300300
// below for more information. Despite this just try to proceed and
301301
// hobble along if it happens to return `Some`.
302-
if let Some(new_local) = gen_local.call_box(&deps, None)? {
302+
if let Some(new_local) = (gen_local)(&deps, None)? {
303303
*fingerprint.local.lock().unwrap() = new_local;
304304
*fingerprint.memoized_hash.lock().unwrap() = None;
305305
}
@@ -1121,9 +1121,7 @@ fn calculate_run_custom_build<'a, 'cfg>(
11211121
// the whole crate.
11221122
let (gen_local, overridden) = build_script_local_fingerprints(cx, unit);
11231123
let deps = &cx.build_explicit_deps[unit];
1124-
let local = gen_local
1125-
.call_box(deps, Some(&|| pkg_fingerprint(cx.bcx, unit.pkg)))?
1126-
.unwrap();
1124+
let local = (gen_local)(deps, Some(&|| pkg_fingerprint(cx.bcx, unit.pkg)))?.unwrap();
11271125
let output = deps.build_script_output.clone();
11281126

11291127
// Include any dependencies of our execution, which is typically just the
@@ -1167,11 +1165,10 @@ fn calculate_run_custom_build<'a, 'cfg>(
11671165
/// scripts). That deduplication is the rationale for the closure at least.
11681166
///
11691167
/// The arguments to the closure are a bit weirder, though, and I'll apologize
1170-
/// in advance for the weirdness too. The first argument to the closure (see
1171-
/// `MyFnOnce` below) is a `&BuildDeps`. This is the parsed version of a build
1172-
/// script, and when Cargo starts up this is cached from previous runs of a
1173-
/// build script. After a build script executes the output file is reparsed and
1174-
/// passed in here.
1168+
/// in advance for the weirdness too. The first argument to the closure is a
1169+
/// `&BuildDeps`. This is the parsed version of a build script, and when Cargo
1170+
/// starts up this is cached from previous runs of a build script. After a
1171+
/// build script executes the output file is reparsed and passed in here.
11751172
///
11761173
/// The second argument is the weirdest, it's *optionally* a closure to
11771174
/// call `pkg_fingerprint` below. The `pkg_fingerprint` below requires access
@@ -1191,7 +1188,16 @@ fn calculate_run_custom_build<'a, 'cfg>(
11911188
fn build_script_local_fingerprints<'a, 'cfg>(
11921189
cx: &mut Context<'a, 'cfg>,
11931190
unit: &Unit<'a>,
1194-
) -> (Box<dyn MyFnOnce + Send>, bool) {
1191+
) -> (
1192+
Box<
1193+
dyn FnOnce(
1194+
&BuildDeps,
1195+
Option<&dyn Fn() -> CargoResult<String>>,
1196+
) -> CargoResult<Option<Vec<LocalFingerprint>>>
1197+
+ Send,
1198+
>,
1199+
bool,
1200+
) {
11951201
// First up, if this build script is entirely overridden, then we just
11961202
// return the hash of what we overrode it with. This is the easy case!
11971203
if let Some(fingerprint) = build_script_override_fingerprint(cx, unit) {
@@ -1603,30 +1609,3 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<Vec<(String, V
16031609
})
16041610
.collect()
16051611
}
1606-
1607-
// This trait solely exists for the `build_script_local_fingerprints` function
1608-
// above, see documentation there for more information. If we had `Box<dyn
1609-
// FnOnce>` we wouldn't need this.
1610-
trait MyFnOnce {
1611-
fn call_box(
1612-
self: Box<Self>,
1613-
f: &BuildDeps,
1614-
pkg_fingerprint: Option<&dyn Fn() -> CargoResult<String>>,
1615-
) -> CargoResult<Option<Vec<LocalFingerprint>>>;
1616-
}
1617-
1618-
impl<F> MyFnOnce for F
1619-
where
1620-
F: FnOnce(
1621-
&BuildDeps,
1622-
Option<&dyn Fn() -> CargoResult<String>>,
1623-
) -> CargoResult<Option<Vec<LocalFingerprint>>>,
1624-
{
1625-
fn call_box(
1626-
self: Box<Self>,
1627-
f: &BuildDeps,
1628-
pkg_fingerprint: Option<&dyn Fn() -> CargoResult<String>>,
1629-
) -> CargoResult<Option<Vec<LocalFingerprint>>> {
1630-
(*self)(f, pkg_fingerprint)
1631-
}
1632-
}

0 commit comments

Comments
 (0)