Skip to content

Regeneralize the "-1 for None" change - #160376

Draft
scottmcm wants to merge 1 commit into
rust-lang:mainfrom
scottmcm:more-minus-one-again
Draft

Regeneralize the "-1 for None" change#160376
scottmcm wants to merge 1 commit into
rust-lang:mainfrom
scottmcm:more-minus-one-again

Conversation

@scottmcm

@scottmcm scottmcm commented Aug 2, 2026

Copy link
Copy Markdown
Member

Not planning on un-drafting this until after #158734 lands.

The "prefer the smaller magnitude" change (#155473) had been applied pretty narrowly: just to option-like niches and just to non-bool-like values. But now that llvm/llvm-project#208611 has been fixed, let's apply it more generally.

In doing so I ended up pretty substantially restructuring the function. I also greatly expanded the comments and added unit tests for it so it's easier to exercise all the paths (and much quicker than rebuilding all of rustc). I made sure to keep the previous "try to keep zero available for None" cleverness, however.


Or, if you prefer, this is contradicting the old comment in the code that

If niche zero is already reserved, the selection of bounds are of little interest.

🙂

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 2, 2026
@rust-log-analyzer

This comment has been minimized.

@scottmcm
scottmcm force-pushed the more-minus-one-again branch from 71d4b14 to c568872 Compare August 2, 2026 09:04
@rust-log-analyzer

This comment has been minimized.

@scottmcm

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 2, 2026
Regeneralize the "-1 for None" change


try-job: aarch64*llvm-21*
@rust-bors

This comment was marked as outdated.

@scottmcm
scottmcm force-pushed the more-minus-one-again branch from c568872 to 7ca10fc Compare August 2, 2026 16:20
@rust-log-analyzer

This comment has been minimized.

@scottmcm

scottmcm commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

:/

sccache: error: Timed out waiting for server startup. Maybe the remote service is unreachable?

@scottmcm scottmcm closed this Aug 2, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 2, 2026
@scottmcm scottmcm reopened this Aug 2, 2026
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 2, 2026
@rust-log-analyzer

This comment has been minimized.

@scottmcm
scottmcm force-pushed the more-minus-one-again branch from 7ca10fc to 0e8bca9 Compare August 2, 2026 16:34
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-gcc-core-tests failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
running 2793 tests
error: test failed, to rerun pass `-p coretests --test coretests`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/dist/build/coretests/a8d1c5450ff3af52/out/coretests-a8d1c5450ff3af52 -Z unstable-options --format json` (signal: 11, SIGSEGV: invalid memory reference)
Bootstrap failed while executing `--stage 1 test library/coretests`
Currently active steps:
test::Crate { build_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, mode: Std, crates: ["coretests"] } at src/bootstrap/src/core/build_steps/test.rs:3390
Build completed unsuccessfully in 0:14:46
  local time: Sun Aug  2 16:53:38 UTC 2026

Important

For more information how to resolve CI failures of this job, visit this link.

@scottmcm

scottmcm commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@bors try jobs=aarch64llvm-21

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 2, 2026
Regeneralize the "-1 for None" change


try-job: aarch64*llvm-21*
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

error: comptime fns can only be called at compile time
##[error]  --> example/example.rs:14:12
   |
14 |     if b { a * 2 } else { a * 3 }
   |            ^^^^^

error: comptime fns can only be called at compile time
##[error]  --> example/example.rs:14:27
   |
14 |     if b { a * 2 } else { a * 3 }
   |                           ^^^^^

error: comptime fns can only be called at compile time
##[error]  --> example/example.rs:47:6
   |
---

error: comptime fns can only be called at compile time
##[error]  --> example/example.rs:81:9
   |
81 |         intrinsics::copy::<u8>(src, dst, 1);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: comptime fns can only be called at compile time
##[error]  --> example/example.rs:88:9
   |
88 |         copy2(src, dst, 1);
   |         ^^^^^^^^^^^^^^^^^^

error: comptime fns can only be called at compile time
##[error]  --> example/example.rs:99:5
   |
99 |     (|_, _, _| {})(0u8, 42u16, 0u8)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: comptime fns can only be called at compile time
##[error]   --> example/example.rs:103:5
    |
103 |     (|_, _| {})(0u8, 42u16)
    |     ^^^^^^^^^^^^^^^^^^^^^^^

error: comptime fns can only be called at compile time
##[error]   --> example/example.rs:113:9
    |
113 |         self.call_mut(arg)
    |         ^^^^^^^^^^^^^^^^^^

error: comptime fns can only be called at compile time
##[error]   --> example/example.rs:125:5
    |
125 |     IsNotEmpty.call_once((&(&[0u16] as &[_]),));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: comptime fns can only be called at compile time
##[error]   --> example/example.rs:129:5
    |
---
    |     ^^^^

error: aborting due to 16 previous errors

"/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustc-clif" "-Zannotate-moves" "-Zrandomize-layout" "-Zunstable-options" "--check-cfg=cfg(bootstrap)" "-Zmacro-backtrace" "-Csplit-debuginfo=off" "-Clink-arg=-L/usr/lib/llvm-21/lib" "-Cllvm-args=-import-instr-limit=10" "-Clink-args=-Wl,-z,origin" "-Clink-args=-Wl,-rpath,$ORIGIN/../lib" "-Alinker-messages" "-L" "crate=/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/example" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/example" "-Cdebuginfo=2" "--target" "aarch64-unknown-linux-gnu" "-Cpanic=abort" "--check-cfg=cfg(jit)" "--edition=2024" "example/example.rs" "--crate-type" "lib" exited with status ExitStatus(unix_wait_status(256))
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=release --manifest-path /checkout/compiler/rustc_codegen_cranelift/build_system/Cargo.toml -- test --download-dir /checkout/obj/build/cg_clif_download --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif --no-unstable-features --use-backend cranelift --sysroot llvm --skip-test testsuite.extended_sysroot [workdir=/checkout/compiler/rustc_codegen_cranelift]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/test.rs:4270:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:4315:26

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `--stage 2 test --skip intrinsic-test --skip src/tools/rust-analyzer --skip tests --skip library --skip tidyselftest`
Currently active steps:
test::CodegenCranelift { compilers: RustcPrivateCompilers { build_compiler: Compiler { stage: 1, host: aarch64-unknown-linux-gnu, forced_compiler: false }, target_compiler: Compiler { stage: 2, host: aarch64-unknown-linux-gnu, forced_compiler: false } }, target: aarch64-unknown-linux-gnu } at src/bootstrap/src/core/build_steps/test.rs:4256
Build completed unsuccessfully in 0:24:33
  local time: Sun Aug  2 17:28:45 UTC 2026

@rust-bors

rust-bors Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 84c2f57 failed: CI. Failed jobs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants