proofs.rs

Document state requirements for Incomplete::try_complete

Document state requirements for Incomplete::try_complete

Found in Report #40 v1 · Updated 2026-11-27 11:58 UTC

Description

Incomplete::try_complete can panic when an Incomplete is constructed with bytes that are not an incomplete UTF-8 suffix. The constructor and fields are public, but their required state is not documented. Could the allowed states and panic behavior be documented, or should this input be handled differently?

Steps to Reproduce

With utf-8 = "=0.7.6", run:

let mut state = utf8::Incomplete::new(&[0x61, 0xff]);
let _ = state.try_complete(&[]);
Expected Behavior

The API should specify whether such a manually constructed state is permitted and what happens when completing it.

Actual Behavior

The call panics when a checked subtraction returns None and is unwrapped.

Environment

utf-8 0.7.6, rustc 1.91.0, default unoptimized build.

Screenshots/Logs

called Option::unwrap() on a None value

Additional Context

The documented workflow passes an incomplete suffix from decode; this example does not show that workflow failing. An empty state or proper incomplete UTF-8 prefix avoids this particular issue.

Change history
  1. v1 · created · 2026-11-27 11:58 UTC
    {
      "title": "Document state requirements for Incomplete::try_complete",
      "body": "## Description\n\n`Incomplete::try_complete` can panic when an `Incomplete` is constructed with bytes that are not an incomplete UTF-8 suffix. The constructor and fields are public, but their required state is not documented. Could the allowed states and panic behavior be documented, or should this input be handled differently?\n\n## Steps to Reproduce\n\nWith `utf-8 = \"=0.7.6\"`, run:\n\n```rust\nlet mut state = utf8::Incomplete::new(&[0x61, 0xff]);\nlet _ = state.try_complete(&[]);\n```\n\n## Expected Behavior\n\nThe API should specify whether such a manually constructed state is permitted and what happens when completing it.\n\n## Actual Behavior\n\nThe call panics when a checked subtraction returns `None` and is unwrapped.\n\n## Environment\n\n`utf-8` 0.7.6, rustc 1.91.0, default unoptimized build.\n\n## Screenshots/Logs\n\n`called Option::unwrap() on a None value`\n\n## Additional Context\n\nThe documented workflow passes an incomplete suffix from `decode`; this example does not show that workflow failing. An empty state or proper incomplete UTF-8 prefix avoids this particular issue.",
      "validity": "reported",
      "upstream_status": "not_reported"
    }

Read and join the discussion on the report →