`for x in children.iter()` works in `html!` but `for x in &children` does not
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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