`Option::map` with `NonZero::min` turns `None` into `Some`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start by reproducing the snippet with rustc -C opt-level=1 and -C opt-level=0 to confirm the optimization-dependent result. The report links an upstream LLVM issue (llvm-project#245656), which is where the root cause most likely lives, so read that thread first. Done would mean the assertion passes at every opt level, probably via a fix or workaround in the upstream LLVM change or in how the Rust side lowers this pattern.
索引モデルが issue の本文から書いたものです。
説明
Code
I tried this code:
use std::num::NonZeroU64;
#[inline(never)]
fn f(a: Option<NonZeroU64>, b: NonZeroU64) -> bool {
a.map(|a| a.min(b)).is_some()
}
fn main() {
let none = std::hint::black_box(None);
assert!(!f(none, NonZeroU64::MIN));
}
I expected to see this happen: This assertion should pass because the None value should not be turned into a NonZeroU64.
Instead, this happened: The assertion fails because of LLVM optimizations. Opt levels 0, 2, and 3 work while 1, s, and z are wrong.
You can see the different outcomes on 1.94, 1.95, and nightly here: https://godbolt.org/z/17nKG3bev
This is due to https://github.com/llvm/llvm-project/issues/245656
Version it worked on
It most recently worked on: 1.94.1
Version with regression
rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: aarch64-apple-darwin
release: 1.95.0
LLVM version: 22.1.2
This is still wrong on 1.100 and nightly 2026-11-23.
Backtrace
Backtrace
thread 'main' (21403425) panicked at repro.rs:10:5:
assertion failed: !f(none, NonZeroU64::MIN)
stack backtrace:
0: __rustc::rust_begin_unwind
at /rustc/0ef1bc386059596dada8fb65b50425aab2ea637a/library/std/src/panicking.rs:676:5
1: core::panicking::panic_fmt
at /rustc/0ef1bc386059596dada8fb65b50425aab2ea637a/library/core/src/panicking.rs:80:14
2: core::panicking::panic
at /rustc/0ef1bc386059596dada8fb65b50425aab2ea637a/library/core/src/panicking.rs:150:5
3: repro::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
- 主要言語
- Rust
- スター
- 123k
- フォーク
- 16.6k
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 532
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rust のほかの issue
-
C-bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
rust-lang/rust#166722 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
A-attributes relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-lang
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
A-run-make C-bug T-bootstrap
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Tracking issue for release notes of #161531: Remove `T: Send + Sync` bound from `Arc::downcast`オープンrelnotes relnotes-tracking-issue T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
A-str A-Unicode relnotes relnotes-tracking-issue T-libs
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
bug core-lang
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Windows microphone listing treats words in a device name as DirectShow labels対応中かも @Sujal-chaudhary が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
clipy-recorder/clipy#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
nightly-cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
max-sixty/worktrunk#4939 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信