Closed Patryk27 closed 1 year ago
What's curious, calling it on a reference to a number:
let val = std::intrinsics::wrapping_sub(&1, &2);
... yields a better error, since it at least says Cannot perform arithmetic on type &i32
(although in a weird place):
warning: unused variable: `val`
--> src/main.rs:4:9
|
4 | let val = std::intrinsics::wrapping_sub(&1, &2);
| ^^^ help: if this is intentional, prefix it with an underscore: `_val`
|
= note: `#[warn(unused_variables)]` on by default
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:3 ~ playground[e443]::main), const_param_did: None }) (after phase change to runtime-optimized) at bb0[2]:
Cannot perform arithmetic on type &i32
--> src/main.rs:4:15
|
4 | let val = std::intrinsics::wrapping_sub(&1, &2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: delayed at 0: <rustc_errors::HandlerInner>::emit_diagnostic
...
If you cannot call an intrinsic without enabling the core_intrinsics
or platform_intrinsics
feature: That is because it is an implementation detail that is exposed for... uh. Reasons? Possibly not entirely good ones? Possibly to work around some issue like macro expansion.
Feel free to submit a PR documenting correct usage, but we will likely not be going to much effort to make these emit good errors, as you are firmly in "how the sausage is made" territory so it is not very useful to make the sausage grinder be less of a grinder. The acceptable amount of compile time to trade off for catching these kinds of things before they land at a horrible, illegible error is near 0.
I see - nah, in this case it’s not worthwhile to waste any time working on this; thanks for responding 🙂
Code
Current output
Desired output
Ideally some error message pointing at
wrapping_sub()
and saying that it's been used with an unsupported / invalid type.Rationale and extra context
No response
Other cases
No response
Anything else?
No response