<p dir="auto">We need some way to interpret a <code class="notranslate">&amp;[u8]</code> as UTF-8, using the replacement character for invalid sequences instead of conditions. This would ideally be provided in the form of an <code class="notranslate">Iterator&lt;char&gt;</code>.</p>
<p dir="auto">The current code for <code class="notranslate">str::not_utf8</code> condition does this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        cond.raise(fmt!(&quot;from_bytes: input is not UTF-8; first bad byte is %u&quot;,
                        first_bad_byte as uint))"><pre class="notranslate"><code class="notranslate">        cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u",
                        first_bad_byte as uint))
</code></pre></div>
<p dir="auto">It might be more reasonable for condition handlers to recover in this situation if they had a reference to the original byte vector, rather than just a string describing what was wrong.</p>
<p dir="auto">(In one case, the byte vector being passed is a <code class="notranslate">~[u8]</code>, but in another it is <code class="notranslate">&amp;[u8]</code>; in the latter, case, attempting to do this would run into <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="12003195" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/5370" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/5370/hovercard" href="https://github.com/rust-lang/rust/issues/5370">#5370</a>, unless we were willing to allocate a copy when raising the condition, which is probably not a good idea.)</p>
<p dir="auto">(Update: blake2-ppc makes a reasonable suggestion in his comment below, though it involves a more substantial revision to the code.  I've generalized the title of this ticket accordingly.)</p>