A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rust-lang/rust/issues/51545 below:

Conditional control flow returning from functions no longer works · Issue #51545 · rust-lang/rust · GitHub

If a match expression has one arm that returns a borrowed matched value from its pattern, and another arm that doesn't borrow directly from a matched value but instead borrows the variable the matched value borrows and returns it, compilation fails if the match statement is returning from a function, but not if it's assigning to a variable. This used to work (and iirc one of the goals of NLLs was to make this pattern work), but it broke between nightly-2018-05-17 and nightly-2018-05-19. A nightly for May 18th doesn't appear to exist.

Examples:

This doesn't work now:

// Doesn't compile on nightly-2018-05-19 and later, but does on nightly-2018-05-17.
fn borrow(o: &mut Option<i32>) -> Option<&mut i32> {
    match o.as_mut() {
        Some(i) => Some(i),
        None => o.as_mut()
    }
}

This is similar to the other code, but does work both before and after nightly-2018-05-19

fn main() {
    let mut o: Option<i32> = Some(1i32);

    // Compiles everywhere!
    let x = match o.as_mut() {
        Some(i) => Some(i),
        None => o.as_mut()
    };
}

schneiderfelipe, tuguzT, emadpres, Millione, SimonMaracine and 1 more


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4