Repository navigation
D183 (#2522): an integer at a narrower or other-signed demand converts with a range check (§4.2.6) - #2989
Merged
Conversation
…demanded converts with a range check (§4.2.6)
Sema admits the narrowing at every demand (a binding's annotation, an
argument, a return, a field, an element, a payload) and records the node
with the demanded type (checked_narrowings); the refusal "implicit integer
narrowing or sign change ... use an explicit `as` cast" is gone. The lint
the ruling asks for warns that the value narrows with a range check and
names the declaration it flows into (widen it, or write `as` for the
wrap). MIR converts the recorded node with the D71 shape: the
destination's bounds compared in the source's type, a panic edge
("integer does not fit `i32` (§4.2.6)", exit 134) and the cast on the
pass path; a check the source's own range makes redundant is not
emitted, and a 128-bit destination checks only its sign bound. Mixed
signedness in arithmetic, a float where an integer is demanded and the
wrapping operators keep their refusals.
A comptime value out of range was already a compile error (an integer
literal that does not fit, overflow in comptime).
Fixtures: behav_d183_checked_narrowing (every demand position, in range),
behav_d183_narrowing_out_of_range_panics, behav_d183_sign_change_out_of_
range_panics, behav_d183_narrowing_lints_the_declaration; the nineteen
err_1803 fixtures that pinned the refusal retire, the four that pin the
remaining refusals stay. Conformance rows D183 and D184 flip to
implemented. The `.len() as i32` sweep follows separately.
ehartford
force-pushed
the
d183-checked-narrowing
branch
from
November 2, 2026 22:06
aad6117 to
515734e
Compare
Contributor
Author
|
Battery green on 515734e ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 2 of bridge-the-impl-gap.md, ruled by Eric 2026-11-02 (D183). Sema admits the narrowing and records it; MIR emits the range check (D71's shape: compare in the source type, panic edge, cast on the pass path); a lint warns at the use naming the narrow declaration (pointing the span at the declaration itself is a follow-up). Nineteen
err_1803fixtures that pinned the old refusal retire; four new behavior fixtures; conformance rows D183 and D184 flip. The.len() as i32sweep is a separate PR. Battery to follow.