     into processCodeUnit: (CodeUnit) -> Void
   ) {
     var c = UInt32(input)
-    var buf3 = UInt8(c & 0xFF)
-
-    if c >= UInt32(1 &<< 7) {
+    var buf3 = UInt8(extendingOrTruncating: c & 0xFF)
+
+    if c >= ((1 as UInt32) &<< 7) {
       c &>>= 6
       buf3 = (buf3 & 0x3F) | 0x80 // 10xxxxxx
-      var buf2 = UInt8(c & 0xFF)
-      if c < UInt32(1 &<< 5) {
+      var buf2 = UInt8(extendingOrTruncating: c & 0xFF)
+      if c < ((1 as UInt32) &<< 5) {
         buf2 |= 0xC0              // 110xxxxx
       }
       else {
         c &>>= 6
         buf2 = (buf2 & 0x3F) | 0x80 // 10xxxxxx
-        var buf1 = UInt8(c & 0xFF)
+        var buf1 = UInt8(extendingOrTruncating: c & 0xFF)
         if c < UInt32(1 &<< 4) {
           buf1 |= 0xE0              // 1110xxxx
         }
         else {
           c &>>= 6
           buf1 = (buf1 & 0x3F) | 0x80 // 10xxxxxx
-          processCodeUnit(UInt8(c | 0xF0)) // 11110xxx
+          processCodeUnit(UInt8(extendingOrTruncating: c | 0xF0)) // 11110xxx
         }
         processCodeUnit(buf1)
       }

  /// - SeeAlso: `UTF16.width(_:)`, `UTF16.leadSurrogate(_:)`
  public static func trailSurrogate(_ x: UnicodeScalar) -> UTF16.CodeUnit {
    _precondition(width(x) == 2)
    return UTF16.CodeUnit(
      (x.value - 0x1_0000) & (((1 as UInt32) &<< 10) - 1)
    ) + 0xDC00
  }

  /// Returns a Boolean value indicating whether the specified code unit is a

      guard let codeUnit = input.next() else { return .emptyInput }
      // ASCII, return immediately.
      if codeUnit & 0x80 == 0 {
        return .scalarValue(UnicodeScalar(
          _unchecked: UInt32(extendingOrTruncating: codeUnit)))
      }
      // Non-ASCII, proceed to buffering mode.
      _decodeBuffer = UInt32(extendingOrTruncating: codeUnit)
      _bitsInBuffer = 8
    } else if (_decodeBuffer & 0x80 == 0) {
      // ASCII in buffer.  We don't refill the buffer so we can return
