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

Add a mean to mutably access the members of a workspace #9547

Merged
merged 2 commits into from
Jun 9, 2021

Conversation

lu-zero
Copy link
Contributor

@lu-zero lu-zero commented Jun 6, 2021

It is used by cargo-c to patch all the lib crates in a workspace.

@rust-highfive
Copy link

r? @alexcrichton

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 6, 2021
@lu-zero lu-zero mentioned this pull request Jun 7, 2021
2 tasks
@alexcrichton
Copy link
Member

Thanks! I would naively expect the non-mut versions to look basically the same, and I think that they're morally the same, right? It looks like they may predate impl Trait return values, so could this update the non-mut versions to look the same? (make it easier to maintain if they look the same because otherwise it may appears like they're different for a reason).

@lu-zero
Copy link
Contributor Author

lu-zero commented Jun 7, 2021

They are morally the same, but I cannot implement the mutable version using the same approach since get_mut() has different constraints compared to get().

The non-mutable version iterates over a Vec and do the hashmap lookup, the mutable iterates over the HashMap and does a linear search over the Vec since it does not have other way to ensure that the mutable references do not overlap.

I can remove the custom struct and return the impl Iterator to make the code a bit more compact thought. Patch coming in few hours :)

@lu-zero
Copy link
Contributor Author

lu-zero commented Jun 7, 2021

Now the code is similar enough, hopefully.

.collect();

packages.iter_mut().filter_map(move |(path, package)| {
if members.contains(path) {
Copy link
Member

Choose a reason for hiding this comment

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

Could this use package.get_mut like above uses packages.get?

(same for default_members_mut below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, the get_mut lifetime gets (rightfully) in the way.

@alexcrichton
Copy link
Member

@bors: r+

Ah yes, indeed!

@bors
Copy link
Collaborator

bors commented Jun 9, 2021

📌 Commit b26ceda has been approved by alexcrichton

@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 9, 2021
@bors
Copy link
Collaborator

bors commented Jun 9, 2021

⌛ Testing commit b26ceda with merge 2b3af39...

@bors
Copy link
Collaborator

bors commented Jun 9, 2021

☀️ Test successful - checks-actions
Approved by: alexcrichton
Pushing 2b3af39 to master...

@bors bors merged commit 2b3af39 into rust-lang:master Jun 9, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Jun 11, 2021
Update cargo

10 commits in aa8b09297bb3156b849e73db48af4cd050492fe6..81537ee3f7bd97ff7821b6c86c148764d40d26cd
2021-06-09 00:28:53 +0000 to 2021-06-11 00:00:14 +0000
- Change how the fix_deny_warnings_but_not_others test works (rust-lang/cargo#9571)
- Add mising documentation regarding `cargo doc` (rust-lang/cargo#9565)
- Implement warning for ignored trailing arguments (rust-lang/cargo#9561)
- Make clippy happy (rust-lang/cargo#9569)
- Fix rustc/rustdoc config values to be config-relative. (rust-lang/cargo#9566)
- Update rustfix. (rust-lang/cargo#9567)
- Warn if an "all" target is specified, but we don't match anything (rust-lang/cargo#9549)
- add default_run to SerializedPackage (rust-lang/cargo#9550)
- respect user choice of lib/bin over heuristics (rust-lang/cargo#9522)
- Add a mean to mutably access the members of a workspace (rust-lang/cargo#9547)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 11, 2021
Update cargo

10 commits in aa8b09297bb3156b849e73db48af4cd050492fe6..81537ee3f7bd97ff7821b6c86c148764d40d26cd
2021-06-09 00:28:53 +0000 to 2021-06-11 00:00:14 +0000
- Change how the fix_deny_warnings_but_not_others test works (rust-lang/cargo#9571)
- Add mising documentation regarding `cargo doc` (rust-lang/cargo#9565)
- Implement warning for ignored trailing arguments (rust-lang/cargo#9561)
- Make clippy happy (rust-lang/cargo#9569)
- Fix rustc/rustdoc config values to be config-relative. (rust-lang/cargo#9566)
- Update rustfix. (rust-lang/cargo#9567)
- Warn if an "all" target is specified, but we don't match anything (rust-lang/cargo#9549)
- add default_run to SerializedPackage (rust-lang/cargo#9550)
- respect user choice of lib/bin over heuristics (rust-lang/cargo#9522)
- Add a mean to mutably access the members of a workspace (rust-lang/cargo#9547)
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 12, 2021
Update cargo

11 commits in aa8b09297bb3156b849e73db48af4cd050492fe6..44456677b5d1d82fe981c955dc5c67734b31f340
2021-06-09 00:28:53 +0000 to 2021-06-12 18:00:01 +0000
- Fix package_default_run test. (rust-lang/cargo#9577)
- Change how the fix_deny_warnings_but_not_others test works (rust-lang/cargo#9571)
- Add mising documentation regarding `cargo doc` (rust-lang/cargo#9565)
- Implement warning for ignored trailing arguments (rust-lang/cargo#9561)
- Make clippy happy (rust-lang/cargo#9569)
- Fix rustc/rustdoc config values to be config-relative. (rust-lang/cargo#9566)
- Update rustfix. (rust-lang/cargo#9567)
- Warn if an "all" target is specified, but we don't match anything (rust-lang/cargo#9549)
- add default_run to SerializedPackage (rust-lang/cargo#9550)
- respect user choice of lib/bin over heuristics (rust-lang/cargo#9522)
- Add a mean to mutably access the members of a workspace (rust-lang/cargo#9547)
@ehuss ehuss added this to the 1.55.0 milestone Feb 6, 2022
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