Repository navigation
Tracking Issue for integer extension and truncation methods #154330
Description
Activity
- addedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.
on Mar 24, 2026 Amanieu commented
on Mar 24, 2026 on Mar 24, 2026 · Hidden as resolvedAuthorshow commentMore actionsIs there any reason not to include widening unsigned->signed conversions as part of
ExtendTarget? E.g.u8toi16is lossless.Is there any reason not to include widening unsigned->signed conversions as part of
ExtendTarget? E.g.u8toi16is lossless.We discussed this in the @rust-lang/libs-api meeting, and felt that either code should write these as separate conversions (e.g.
.extend().cast_signed()) or use.into()which already provides "conversion via multiple operations at once".Not doing so ensures the methods serve exactly one purpose. It's trivial to chain that and
.cast_signed()(already stable) in that situation. Imo it's more explicit about what is happening.Last I checked,
timeis the only code base usingnum-conv, so check that out if you want to see real world code. Otherwise it's just examples, realistically.Reacted by Josh Triplett13 remaining items
@Qelxiros That would be nice, with clippy's usual mechanism for only issuing such lints if your MSRV allows it.
Has the name
widenbeen discussed instead ofextend? Keeping in mindwidening_mulhaving similar functionality (now that it's to return a wider integer.)Reacted by Simon Sapin, waffle, John Schug, Orson Peters, Josh Triplett, Amanieu d'Antras and Arto Bendiken@bjoernager That's a really good thought.
widenwould be more consistent, and would avoid conflicts with the meaning ofextendin collections. Big 👍 to changing that. Nominating to discuss.Reacted by Arto BendikenReacted by waffle, Gabriel Bjørnager Jensen and Arto Bendiken- addedI-libs-api-nominated[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
on May 7, 2026 If we adopt
widenthen for symmetry we should also rename the truncating operations to narrow. Proposed names:truncating_narrowsaturating_narrowchecked_narrow
And possibly even an
unchecked_narrowwhich is UB if the original value doesn't fit in the narrowed type.Reacted by Gabriel Bjørnager Jensen, Arto Bendiken, Sabrina Jewson and Josh Triplettis there any architecture with instructions for
unchecked_narrowwith some advantage overtruncating_narrow?I'd guess that
truncating_narrowis a bitmask of some sort, while the caller ofunchecked_narrowmust guarantee that value already fits in the smaller size, so it can be a no-op (assuming the value lives in a register at that program point). I'm not 100% sure though.unchecked_narrowimproves optimizations since it tells LLVM the input is in range so if LLVM needs to widen the values to fit in registers it needs no explicit conversion and probably other optimizations too.Reacted by Gabriel Bjørnager JensenUpdated
num-convwithwiden. I'm also now subscribed to this issue since apparently I wasn't before.Reacted by Arto BendikenReacted by Gabriel Bjørnager Jensen, Josh Triplett and Arto Bendiken"truncate" and "extend" are well known terms that have been used for decades to describe this specific operation, is there a reason that the libs team prefers the new names?
Reacted by waffle@asquared31415 One reason is that we already have
extendmethods in the standard library that means something else (adding items to a collection).Reacted by Gabriel Bjørnager Jensen- addedT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.and removedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
on Aug 12, 2026
View all comments
Feature gate:
#![feature(integer_extend_truncate)]This is a tracking issue for integer extension and truncation methods.
Public API
Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩