Skip to content

run-make-support: use a CommandWrapper trait instead of impl_helper_methods macro #125747

Closed as not planned
@jieyouxu

Description

@jieyouxu

impl_helper_methods worked reasonably well while prototyping, but now I realized a trait with default provided methods is a better fit for making it easier and less verbose to implement command wrappers. This is because command_output can be a required method checked by rustc, while we can provide helper methods but still allow individual command wrapper instances to override as desired.

pub trait CommandWrapper {
    // required method
    fn command_output(self) -> std::command::Output;

    // provided helper methods
    fn run(self) -> std::command::Output { ... }
    fn run_fail(self, expected_exit_code: i32) -> std::command::Output { ... }
}

then implementors can write

pub struct Rustc { cmd: Command }

impl CommandWrapper for Rustc {
    fn command_output(self) -> Output { ... }
}

impl Rustc {
    // ... other helper methods
}

Unresolved questions

  • If these helper methods are moved on to a trait, then test writers will have to bring the trait in scope in order to use the helper methods. Is it worth the extra typing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-run-makeArea: port run-make Makefiles to rmake.rsA-testsuiteArea: The testsuite used to check the correctness of rustcC-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions