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

Option::and is not as polymorphic as it can be #9773

Closed
wants to merge 2 commits into from

Conversation

micahrj
Copy link
Contributor

@micahrj micahrj commented Oct 8, 2013

Option::and currently requires optb to contain the same type as self. Option::and_then demonstrates that this is unnecessary, since the function will either return None or optb.

@@ -132,7 +132,7 @@ impl<T> Option<T> {

/// Returns `None` if the option is `None`, otherwise returns `optb`.
#[inline]
pub fn and(self, optb: Option<T>) -> Option<T> {
pub fn and(self, optb: Option<U>) -> Option<U> {
Copy link
Member

Choose a reason for hiding this comment

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

I think this will fail to compile because of the undeclared U type parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, you're right. It needs to be and<U>.

@alexcrichton
Copy link
Member

ping @micahjohnston, any progress on this?

@alexcrichton
Copy link
Member

This was subsumed as part of #10119

flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2022
Fix ICE in `redundant_allocation`

changelog: Fix ICE in `redundant_allocation`

Closes rust-lang#9746, the original issue was fixed already, this gets the one in rust-lang/rust-clippy#9746 (comment)
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2023
…r=Veykril

fix: check tail expressions more precisely in `extract_function`

Fixes rust-lang#13620

When extracting expressions with control flows into a function, we can avoid wrapping tail expressions in `Option` or `Result` when they are also tail expressions of the container we're extracting from (see rust-lang#7840, rust-lang#9773). This is controlled by `ContainerInfo::is_in_tail`, but we've been computing it by checking if the tail expression of the range to extract is contained in the container's syntactically last expression, which may be a block that contains both tail and non-tail expressions (e.g. in rust-lang#13620, the range to be extracted is not a tail expression but we set the flag to true).

This PR tries to compute the flag as precise as possible by utilizing `for_each_tail_expr()` (and also moves the flag to `Function` struct as it's more of a property of the function to be extracted than of the container).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants