yewstack / yewstack/yew

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

Open
#4,073 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
32.8k
Forks
1.5k
Avg merge
5h 34m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the html! macro handles for-loop expressions, using the two minimal reproductions in the issue to compare children.iter() with &props.children. Verify the change against both forms and add or run regression coverage showing that both compile and render the child items.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.