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

Minor changes to IndexVec::ensure_contains_elem & related methods #110451

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

WaffleLapkin
Copy link
Member

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 17, 2023
@rust-log-analyzer

This comment has been minimized.

}

#[inline]
pub fn remove(&mut self, index: I) -> Option<T> {
self.ensure_contains_elem(index, || None);
self[index].take()
self.get_mut(index).map(Option::take).unwrap_or(None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.get_mut(index).map(Option::take).unwrap_or(None)
self.get_mut(index)?.take()

Copy link
Member

@scottmcm scottmcm Apr 17, 2023

Choose a reason for hiding this comment

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

Agreed, ? looks much nicer than two combinators here.

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

r=me, preferably with kadiwa's suggestion.

let min_new_len = elem.index() + 1;
if self.len() < min_new_len {
self.raw.resize_with(min_new_len, fill_value);
}

&mut self[elem]
Copy link
Member

Choose a reason for hiding this comment

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

Very nice change!

}

#[inline]
pub fn remove(&mut self, index: I) -> Option<T> {
self.ensure_contains_elem(index, || None);
self[index].take()
self.get_mut(index).map(Option::take).unwrap_or(None)
Copy link
Member

@scottmcm scottmcm Apr 17, 2023

Choose a reason for hiding this comment

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

Agreed, ? looks much nicer than two combinators here.

@WaffleLapkin
Copy link
Member Author

@bors r=scottmcm rollup

@WaffleLapkin
Copy link
Member Author

@bors ping

@bors
Copy link
Contributor

bors commented Apr 18, 2023

📌 Commit bd1dfce has been approved by scottmcm

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 Apr 18, 2023
@bors
Copy link
Contributor

bors commented Apr 18, 2023

😪 I'm awake I'm awake

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#110432 (Report more detailed reason why `Index` impl is not satisfied)
 - rust-lang#110451 (Minor changes to `IndexVec::ensure_contains_elem` & related methods)
 - rust-lang#110476 (Delay a good path bug on drop for `TypeErrCtxt` (instead of a regular delayed bug))
 - rust-lang#110498 (Switch to `EarlyBinder` for `collect_return_position_impl_trait_in_trait_tys`)
 - rust-lang#110507 (boostrap: print output during building tools)
 - rust-lang#110510 (Fix ICE for transmutability in candidate assembly)
 - rust-lang#110513 (make `non_upper_case_globals` lint not report trait impls)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a184557 into rust-lang:master Apr 19, 2023
@rustbot rustbot added this to the 1.71.0 milestone Apr 19, 2023
@WaffleLapkin WaffleLapkin deleted the ensure_return_elem branch April 21, 2023 17:41
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 13, 2024
…, r=scottmcm

Small style improvement in `gvn.rs`

Allowed by rust-lang#110451 (comment). :P

r? `@scottmcm`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 13, 2024
…, r=scottmcm

Small style improvement in `gvn.rs`

Allowed by rust-lang#110451 (comment). :P

r? ``@scottmcm``
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 13, 2024
…, r=scottmcm

Small style improvement in `gvn.rs`

Allowed by rust-lang#110451 (comment). :P

r? ```@scottmcm```
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 14, 2024
Rollup merge of rust-lang#126392 - WaffleLapkin:gvn-style-ish-changes, r=scottmcm

Small style improvement in `gvn.rs`

Allowed by rust-lang#110451 (comment). :P

r? ``@scottmcm``
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Jun 28, 2024
Small style improvement in `gvn.rs`

Allowed by rust-lang/rust#110451 (comment). :P

r? ``@scottmcm``
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants