Skip to content

for x in children.iter() works in html! but for x in &children does not #4073

@Madoshakalaka

Description

@Madoshakalaka

Problem

The for loop syntax in html! requires children.iter() to compile, but does not accept &children, which is the idiomatic Rust form and what clippy's explicit_iter_loop lint likes.

Minimal Reproduction

This compiles:

#[derive(Clone, PartialEq, Properties)]
pub struct WrapperProps {
    pub children: Children,
}

#[component]
fn Wrapper(props: &WrapperProps) -> Html {
    html! {
        <ul>
            for child in props.children.iter() {
                <li>{child}</li>
            }
        </ul>
    }
}

This does not:

#[component]
fn Wrapper(props: &WrapperProps) -> Html {
    html! {
        <ul>
            for child in &props.children {
                <li>{child}</li>
            }
        </ul>
    }
}

Expected behavior
both should compile

Environment:

  • Yew version: [0.23.0]

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions