`Option::map` with `NonZero::min` turns `None` into `Some`

オープン
#166,505 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
12/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
compilers

調査の方向性

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 の本文から書いたものです。

説明

A-LLVM C-bug I-miscompile regression-from-stable-to-stable T-compiler
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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rust のほかの issue

rust-lang/rust の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。