Skip to content

Commit f6e737b

Browse files
committed
Auto merge of #11445 - willcrichton:refactor-target-generator, r=weihanglo
Refactor generate_targets into separate module ### What does this PR try to resolve? The `generate_targets` function is fairly complicated with an absurd number of parameters. This PR refactors the function into a `TargetGenerator` struct that represents the state of the generator, and reduces the amount of parameter-passing between the relevant functions. Additionally, the `generate_targets` function has been refactored into two smaller functions `create_proposals` and `proposals_to_units`. The docscrape-specific functionality from #11430 has been pulled out into a separate function, as promised. ### How should we test and review this PR? This PR does not change any functionality, so no new tests are added. It should be reviewed for code style. r? `@weihanglo`
2 parents 324a935 + ad201bc commit f6e737b

File tree

5 files changed

+739
-722
lines changed

5 files changed

+739
-722
lines changed

src/cargo/ops/cargo_compile/compile_filter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ pub enum FilterRule {
2828
/// Filter to apply to the root package to select which Cargo targets will be built.
2929
/// (examples, bins, benches, tests, ...)
3030
///
31-
/// The actual filter process happens inside [`generate_targets`].
31+
/// The actual filter process happens inside [`generate_units`].
3232
///
3333
/// Not to be confused with [`Packages`], which opts in packages to be built.
3434
///
35-
/// [`generate_targets`]: super::generate_targets
35+
/// [`generate_units`]: super::UnitGenerator::generate_units
3636
/// [`Packages`]: crate::ops::Packages
3737
#[derive(Debug)]
3838
pub enum CompileFilter {
@@ -176,7 +176,7 @@ impl CompileFilter {
176176
/// may include additional example targets to ensure they can be compiled.
177177
///
178178
/// Note that the actual behavior is subject to `filter_default_targets`
179-
/// and `generate_targets` though.
179+
/// and `generate_units` though.
180180
pub fn all_test_targets() -> Self {
181181
Self::Only {
182182
all_targets: false,
@@ -234,7 +234,7 @@ impl CompileFilter {
234234
}
235235

236236
/// Selects targets for "cargo run". for logic to select targets for other
237-
/// subcommands, see `generate_targets` and `filter_default_targets`.
237+
/// subcommands, see `generate_units` and `filter_default_targets`.
238238
pub fn target_run(&self, target: &Target) -> bool {
239239
match *self {
240240
CompileFilter::Default { .. } => true,

0 commit comments

Comments
 (0)