-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
use std::num::NonZero;
fn main() {
let x: NonZero<u8> = NonZero::MAX;
}
I expected to see this happen: NonZero::MAX
is inferred to be NonZero::<u8>::MAX
Instead, this happened: compilation error
Meta
rustc --version --verbose
:
cargo 1.88.0 (873a06493 2025-05-10)
release: 1.88.0
commit-hash: 873a0649350c486caf67be772828a4f36bb4734c
commit-date: 2025-05-10
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.1-DEV (sys:0.4.80+curl-8.12.1 vendored ssl:OpenSSL/3.4.1)
ssl: OpenSSL 3.4.1 11 Feb 2025
os: NixOS 25.11.0 [64-bit]
(also tested on latest beta and nightly, using Playground)
Backtrace
error[E0034]: multiple applicable items in scope
--> src/lib.rs:4:35
|
4 | let x: NonZero<u8> = NonZero::MAX;
| ^^^ multiple `MAX` found
|
= note: candidate #1 is defined in an impl for the type `NonZero<i128>`
= note: candidate #2 is defined in an impl for the type `NonZero<i16>`
= note: candidate #3 is defined in an impl for the type `NonZero<i32>`
= note: candidate #4 is defined in an impl for the type `NonZero<i64>`
= note: and 8 others
For more information about this error, try `rustc --explain E0034`.
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.