Skip to content

Temporary does not live long enough in let chains #103476

Closed
@Alexendoo

Description

@Alexendoo

I tried this code, playground:

#![feature(let_chains)]

use syn::{Attribute, Meta};

fn f(attr: &Attribute) -> bool {
    if let Meta::NameValue(name_value) = attr.parse_meta().ok().unwrap()
        && let path_idents = name_value.path.segments.iter()
        /* other stuff */
    {
        
    }
    
    true
}

I expected to see this happen: code compiles

Instead, this happened: errors due to name_value.path.segments does not live long enough

It compiles when expressed as nested ifs, playground:

#![feature(let_chains)]

use syn::{Attribute, Meta};

fn f(attr: &Attribute) -> bool {
    if let Meta::NameValue(name_value) = attr.parse_meta().ok().unwrap() {
        if let path_idents = name_value.path.segments.iter() {}
    }

    true
}

The code compiled previously, but no longer does after #103034 (confirmed with a cargo bisect-rustc)

cc @nathanwhit

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-let_chains`#![feature(let_chains)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions