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

Simplify checking feature syntax #14106

Merged
merged 2 commits into from
Jun 20, 2024
Merged

Conversation

Eh2406
Copy link
Contributor

@Eh2406 Eh2406 commented Jun 19, 2024

What does this PR try to resolve?

Similar to #14089, in my PubGrub work I had to try to understand the build_feature_map code that determines if the name refers to a feature or an optional dependency. There were a couple of little things I wanted to clean up while I was staring at the code. Specifically:

  • there was a lot of vertical space taken up with arguments to bail that could be in line at the format string.
  • some match statements were used where a named helper method would be clearer.
  • split_once could replace a find ... split_at dance.
  • in dep_map we were constructing a full Vec<Dependency>, when we only cared about whether there was any dependency and whether any of the dependencies were optional.

How should we test and review this PR?

It's an internal re-factor, and the tests still pass.

Additional information

If you're having questions about this code while you're reviewing, this would be a perfect opportunity for better naming and comments. Please ask questions.

@epage: After this PR I am likely to copy this code into my pubgrub tester. Are there other users who might be interested in looking at a cargo.toml or an index entry and determining what feature names are available and what dependencies they enable? If so maybe this function should be moved to one of the new stable-ish reusable libraries.

@rustbot
Copy link
Collaborator

rustbot commented Jun 19, 2024

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2024
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some bikeshedding on the name.

}
}

fn dep_name(&self) -> InternedString {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a confusing name, since FeatureValue::Feature is not necessarily a dependency name. For example:

[features]
foo = ["bar"]
bar = []

Here the FeatureValue::Feature("bar") is not a dependency name.

I realize this is refactoring code that was already using dep_name, but the original was somewhat abusing the nomenclature.

I would go with feature_or_dep_name to make it clearer it can be either. What do you think?

/// Returns `true` if this feature explicitly used `dep:` syntax.
pub fn has_dep_prefix(&self) -> bool {
matches!(self, FeatureValue::Dep { .. })
fn explicitly_name(&self) -> Option<InternedString> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here name seems ambiguous to me. It could be a "feature name" or a "dependency name". I might go with something like explicit_dep_name or something like that.

Also, can you add a docstring to say exactly what it does?

@epage
Copy link
Contributor

epage commented Jun 19, 2024

cargo add and `cargo-information do their own feature activation work.

@Eh2406
Copy link
Contributor Author

Eh2406 commented Jun 19, 2024

@ehuss tweak names as requested.

@epage are you saying that other projects would or would not find making this method public useful?

@epage
Copy link
Contributor

epage commented Jun 19, 2024

I've not checked the function logic to see if it would work (mostly out for the next couple weeks) so I was just noting potential applications, one being in Cargo.

@ehuss
Copy link
Contributor

ehuss commented Jun 20, 2024

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 20, 2024

📌 Commit 85f6d2d has been approved by ehuss

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2024
@bors
Copy link
Collaborator

bors commented Jun 20, 2024

⌛ Testing commit 85f6d2d with merge fb05646...

@bors
Copy link
Collaborator

bors commented Jun 20, 2024

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing fb05646 to master...

1 similar comment
@bors
Copy link
Collaborator

bors commented Jun 20, 2024

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing fb05646 to master...

@bors bors merged commit fb05646 into rust-lang:master Jun 20, 2024
22 checks passed
@bors
Copy link
Collaborator

bors commented Jun 20, 2024

👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 22, 2024
Update cargo

17 commits in 3ed207e416fb2f678a40cc79c02dcf4f936a21ce..bc89bffa5987d4af8f71011c7557119b39e44a65
2024-06-18 19:18:22 +0000 to 2024-06-22 00:36:36 +0000
- test: migrate weak_dep_features, workspaces and yank to snapbox (rust-lang/cargo#14111)
- test: migrate features and features(2|_namespaced) to snapbox (rust-lang/cargo#14100)
- test: Add auto-redaction for not found error (rust-lang/cargo#14124)
- test: migrate build to snapbox (rust-lang/cargo#14068)
- test: migrate unit_graph, update and vendor to snapbox (rust-lang/cargo#14119)
- fix(test): Un-redact Packaged files (rust-lang/cargo#14123)
- test: Auto-redact file number (rust-lang/cargo#14121)
- test: migrate lints_table and lints/(mod|unknown_lints) to snapbox (rust-lang/cargo#14104)
- Simplify checking feature syntax (rust-lang/cargo#14106)
- test: migrate testsuites to snapbox (rust-lang/cargo#14091)
- Make `-Cmetadata` consistent across platforms (rust-lang/cargo#14107)
- fix(toml): Warn when edition is unuset, even when MSRV is unset (rust-lang/cargo#14110)
- Add `CodeFix::apply_solution` and impl `Clone` (rust-lang/cargo#14092)
- test: migrate `cargo_alias_config&cargo_config/mod` to snapbox (rust-lang/cargo#14093)
- Simplify checking for dependency cycles (rust-lang/cargo#14089)
- test: Migrate `pub_priv.rs` to snapshot (rust-lang/cargo#14103)
- test: migrate rustdoc and rustdocflags to snapbox (rust-lang/cargo#14098)

<!--
r? ghost
-->
@rustbot rustbot added this to the 1.81.0 milestone Jun 22, 2024
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jun 23, 2024
Update cargo

17 commits in 3ed207e416fb2f678a40cc79c02dcf4f936a21ce..bc89bffa5987d4af8f71011c7557119b39e44a65
2024-06-18 19:18:22 +0000 to 2024-06-22 00:36:36 +0000
- test: migrate weak_dep_features, workspaces and yank to snapbox (rust-lang/cargo#14111)
- test: migrate features and features(2|_namespaced) to snapbox (rust-lang/cargo#14100)
- test: Add auto-redaction for not found error (rust-lang/cargo#14124)
- test: migrate build to snapbox (rust-lang/cargo#14068)
- test: migrate unit_graph, update and vendor to snapbox (rust-lang/cargo#14119)
- fix(test): Un-redact Packaged files (rust-lang/cargo#14123)
- test: Auto-redact file number (rust-lang/cargo#14121)
- test: migrate lints_table and lints/(mod|unknown_lints) to snapbox (rust-lang/cargo#14104)
- Simplify checking feature syntax (rust-lang/cargo#14106)
- test: migrate testsuites to snapbox (rust-lang/cargo#14091)
- Make `-Cmetadata` consistent across platforms (rust-lang/cargo#14107)
- fix(toml): Warn when edition is unuset, even when MSRV is unset (rust-lang/cargo#14110)
- Add `CodeFix::apply_solution` and impl `Clone` (rust-lang/cargo#14092)
- test: migrate `cargo_alias_config&cargo_config/mod` to snapbox (rust-lang/cargo#14093)
- Simplify checking for dependency cycles (rust-lang/cargo#14089)
- test: Migrate `pub_priv.rs` to snapshot (rust-lang/cargo#14103)
- test: migrate rustdoc and rustdocflags to snapbox (rust-lang/cargo#14098)

<!--
r? ghost
-->
@Eh2406 Eh2406 deleted the build_feature_map branch June 25, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants