Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce duplication in Task::run #542

Merged
merged 1 commit into from
Sep 7, 2020
Merged

Reduce duplication in Task::run #542

merged 1 commit into from
Sep 7, 2020

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Sep 5, 2020

Previously, this would create a new TaskCtx for every task that needed
to run. Now it only constructs it once.

This also had the most confusing error message I've ever had the
misfortune to see in Rust:

error[E0308]: mismatched types
   --> src/runner/tasks.rs:255:38
    |
255 |         test::run_test(action, &ctx, test)?;
    |                                      ^^^^ one type is more general than the other
    |
    = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2> fn(&'r runner::tasks::TaskCtx<'s, DB>, &'t0 rustwide::Build<'t1>, &'t2 std::collections::HashSet<cargo_metadata::PackageId>) -> std::result::Result<_, _>`
               found fn pointer `fn(&runner::tasks::TaskCtx<'_, DB>, &rustwide::Build<'_>, &std::collections::HashSet<cargo_metadata::PackageId>) -> std::result::Result<_, _>`

The fix was to change

        let (action, test, toolchain, quiet): (_, fn(_, _, _) -> _, _, _) = match self.step {

to

        let (action, test, toolchain, quiet): (_, fn(&TaskCtx<_>, &Build, &_) -> _, _, _) = match self.step {

I have no idea why.

Previously, this would create a new `TaskCtx` for every task that needed
to run. Now it only constructs it once.

This also had the most confusing error message I've ever had the
misfortune to see in Rust:

```rust
error[E0308]: mismatched types
   --> src/runner/tasks.rs:255:38
    |
255 |         test::run_test(action, &ctx, test)?;
    |                                      ^^^^ one type is more general than the other
    |
    = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2> fn(&'r runner::tasks::TaskCtx<'s, DB>, &'t0 rustwide::Build<'t1>, &'t2 std::collections::HashSet<cargo_metadata::PackageId>) -> std::result::Result<_, _>`
               found fn pointer `fn(&runner::tasks::TaskCtx<'_, DB>, &rustwide::Build<'_>, &std::collections::HashSet<cargo_metadata::PackageId>) -> std::result::Result<_, _>`
```

The fix was to change

```
        let (action, test, toolchain, quiet): (_, fn(_, _, _) -> _, _, _) = match self.step {
```

to

```
        let (action, test, toolchain, quiet): (_, fn(&TaskCtx<_>, &Build, &_) -> _, _, _) = match self.step {
```

I have no idea why.
@pietroalbini
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Sep 7, 2020

📌 Commit 8efe38a has been approved by pietroalbini

@bors
Copy link
Contributor

bors commented Sep 7, 2020

⌛ Testing commit 8efe38a with merge dcc5456...

@bors
Copy link
Contributor

bors commented Sep 7, 2020

☀️ Test successful - checks-actions
Approved by: pietroalbini
Pushing dcc5456 to master...

@bors bors merged commit dcc5456 into rust-lang:master Sep 7, 2020
@jyn514 jyn514 deleted the refactor branch September 7, 2020 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants