Repository navigation
rustc suggest adding an import of compiler_builtins #142676
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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
Code
fn f() {
u8::cast_from_lossy(9);
}Current output
Compiling playground v0.0.1 (/playground)
error[E0599]: no function or associated item named `cast_from_lossy` found for type `u8` in the current scope
--> src/lib.rs:2:9
|
2 | u8::cast_from_lossy(9);
| ^^^^^^^^^^^^^^^ function or associated item not found in `u8`
|
= help: items from traits can only be used if the trait is in scope
help: trait `CastFrom` which provides `cast_from_lossy` is implemented but not in scope; perhaps you want to import it
|
1 + use compiler_builtins::math::libm::support::int_traits::CastFrom;
|
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` (lib) due to 1 previous errorDesired output
Compiling playground v0.0.1 (/playground)
error[E0599]: no function or associated item named `cast_from_lossy` found for type `u8` in the current scope
--> src/lib.rs:2:9
|
2 | u8::cast_from_lossy(9);
| ^^^^^^^^^^^^^^^ function or associated item not found in `u8`
|
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` (lib) due to 1 previous errorRationale and extra context
The suggested import does not work. Additionally, the import will be suggested even if it's already there.
Other cases
A previously reported issue #71090 was supposed to be fixed, but maybe it regressed?Rust Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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.
Activity
ChrisDenton commentedon Jun 19, 2025
This regressed in version 1.86.
As noted in the OP, this error was previously seen in #71090 but had been fixed years ago.
workingjubilee commentedon Jun 19, 2025
cc @tgross35
ChrisDenton commentedon Jun 19, 2025
Bisection:
searched nightlies: from nightly-2025-01-27 to nightly-2025-06-19
regressed nightly: nightly-2025-02-26
searched commit range: 617aad8...85abb27
regressed commit: 4ecd70d
Most obvious candidate is #137515 which leads to rust-lang/compiler-builtins#766
tgross35 commentedon Jun 19, 2025
You're kidding me, still? This was supposed to be gone forever with #135501 🙃. Either compiler_builtins is getting marked public somehow, or diagnostics are suggesting from private crates when they shouldn't be.
tgross35 commentedon Jun 19, 2025
With
RUSTC_LOG=rustc_metadata=infohttps://rust.godbolt.org/z/qcG85vvr3 I see:So it is still private at the end of resolution, meaning that the diagnostic is making suggestions from crates it shouldn't. At least resolution doesn't seem borked.
estebank commentedon Jun 20, 2025
This has happened in the past...
tgross35 commentedon Jun 24, 2025
I probably won't be able to look at this for a while and this isn't the highest priority, so I'll label for someone to pick it up if they get the chance. The steps are most likely:
rust/compiler/rustc_hir_typeck/src/method/suggest.rs
Lines 3476 to 3508 in 3129d37
info!statements andRUSTC_LOGhttps://rustc-dev-guide.rust-lang.org/tracing.html)valid_out_of_scope_traitscomes from and why it's including private dependencies. Or maybe just filter it within suggest_valid_traits.Medium-hard?
cyrgani commentedon Jun 25, 2025
A very similar issue with
objectinstead ofcompiler_builtinsis #138191.Qelxiros commentedon Jun 25, 2025
@rustbot claim
1 remaining item
tgross35 commentedon Jun 25, 2025
Looking at the issue @cyrgani linked, the diagnostic has been an issue back to 1.56 https://rust.godbolt.org/z/cE9YeoqYr. The relevant bit here is just that the relevant trait isn't gated at the AST level starting with that PR. It's still gated by a feature, but apparently being in a private crate behind a disabled
cfgis no match for our enthusiastic diagnostics.Linking some zulip discussion: #t-compiler/help > compiler_builtins isn't a private dependency
Rollup merge of rust-lang#143038 - Qelxiros:142676-private-dependency…
Rollup merge of rust-lang#143038 - Qelxiros:142676-private-dependency…
Rollup merge of rust-lang#143038 - Qelxiros:142676-private-dependency…
Rollup merge of rust-lang#143038 - Qelxiros:142676-private-dependency…
Auto merge of #143038 - Qelxiros:142676-private-dependency-traits, r=…
Rollup merge of rust-lang#143038 - Qelxiros:142676-private-dependency…
Rollup merge of rust-lang#143038 - Qelxiros:142676-private-dependency…
Unrolled build for #143038
Rollup merge of #143038 - Qelxiros:142676-private-dependency-traits, …
Rollup merge of #143038 - Qelxiros:142676-private-dependency-traits, …
Rollup merge of rust-lang#143038 - Qelxiros:142676-private-dependency…
suprohub commentedon Oct 17, 2025
Can someone reopen? I get now similar issue.
If i add in random place of my crate
f64::PI, it suggests me:No one of my crates use compiler builtins, and my Cargo.lock dont have compiler_builtins too.
My crate: https://github.com/suprohub/cos
tgross35 commentedon Oct 20, 2025
@suprohub could you open a new issue for this? Please include the rustc version you used and steps/code to reproduce as well.