Undocumented if-let behavior with or-patterns
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 70/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust
调研方向
该 issue 给出一个分两部分的 Rust 示例:一个带有或模式和 && 守卫的 if let,以及一个带有相同或模式和守卫的 match。运行两者以确认差异,然后在 Reference 中查找关于或模式、match 守卫、if let 和 let 链的章节。完成标准是 Reference 明确指出:当后续条件失败时,let 链不会重试或模式的各个分支,而 match 守卫会。
由索引模型根据 Issue 内容生成。
描述
Or-patterns in a match can cause a match guard to run multiple times, as each of the or'ed patterns gets tried after the previous one fails in the guard. However, with let-chains, there is no such "backtracking" behavior. This is not documented in the reference.
fn main() {
if let (x, _) | (_, x) = (1, 2)
&& x == 2
{
println!("This is NOT printed.");
}
match (1, 2) {
(x, _) | (_, x) if x == 2 => {
println!("This is printed.");
}
_ => {}
}
}
Relevant discussion: https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Merging.20destructuring.20assignment.20and.20patterns/near/576565919
- 主要语言
- Rust
- 星标
- 1.6k
- 派生
- 618
- 平均合并
- 5 小时 48 分钟
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/reference 的其他 Issue
-
A-const-eval A-undefined-behavior
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
rust-lang/reference#2266 · 1 条评论 ·
维护者通常 1 天内回复
-
A-resolve
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
A-coercions
难度 2/5 1-3 小时 新手友好度 65/100
rust-lang/reference#2094 · 1 条评论 ·
维护者通常 1 天内回复
查看 rust-lang/reference 的全部 Issue
相似的 Issue
-
good first issue help wanted program
难度 2/5 1-3 小时 新手友好度 83/100
hffgzktbcc-blip/ounce-core#297 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
nautechsystems/nautilus_trader#5631 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 69/100
bytecodealliance/rustix#1736 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
longbridge/gpui-kit#3871 ·
维护者通常 1 天内回复
-
area:models enhancement
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复