rust-lang/rust · error · anyhow::Error

target block for the title is not found

Error message

target block for the title is not found

What it means

Thrown by rust-analyzer's AsciiDoc-to-Markdown converter after it consumes a '.Caption' line in process_block_with_title. The converter peeks at the next line to find the target block (image:: or video::) that the caption applies to. If self.iter.peek() returns None — meaning the input ended right after the title line — there is no block to attach the caption to and this error fires.

Source

Thrown at src/tools/rust-analyzer/xtask/src/publish/notes.rs:189

                    return Ok(());
                } else {
                    self.write_line(&line, level);
                }
            }
            bail!("listing block is not terminated")
        }
        bail!("not a listing block")
    }

    fn process_block_with_title(&mut self, level: usize) -> anyhow::Result<()> {
        if let Some(Ok(line)) = self.iter.next() {
            let title =
                line.strip_prefix('.').ok_or_else(|| anyhow!("extraction of the title failed"))?;

            let line = self
                .iter
                .peek()
                .ok_or_else(|| anyhow!("target block for the title is not found"))?;
            let line = line.as_deref().map_err(|e| anyhow!("{e}"))?;
            if line.starts_with(IMAGE_BLOCK_PREFIX) {
                return self.process_image_block(Some(title), level);
            } else if line.starts_with(VIDEO_BLOCK_PREFIX) {
                return self.process_video_block(Some(title), level);
            } else {
                bail!("title for that block type is not supported");
            }
        }
        bail!("not a title")
    }

    fn process_image_block(&mut self, caption: Option<&str>, level: usize) -> anyhow::Result<()> {
        if let Some(Ok(line)) = self.iter.next()
            && let Some((url, attrs)) = parse_media_block(&line, IMAGE_BLOCK_PREFIX)
        {
            let alt =
                if let Some(stripped) = attrs.strip_prefix('"').and_then(|s| s.strip_suffix('"')) {

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Add the missing image::filename[alt] or video::filename[attrs] block immediately after the '.Caption' line.
  2. Remove the orphaned '.Caption' line if the block was intentionally deleted.
  3. Run the converter on the file locally (cargo test -p xtask or the test_asciidoc_to_markdown_conversion test) to verify the fix before committing.

Example fix

// before (dangling title in .adoc):
.Screenshot of the new UI
// (EOF — no block follows)
// after:
.Screenshot of the new UI
image::screenshot.png[Screenshot of the new UI]
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate that every block title (.Caption) has a following media block.
fn check_titles_have_blocks(input: &str) -> Result<(), String> {
    let lines: Vec<&str> = input.lines().collect();
    for (i, line) in lines.iter().enumerate() {
        if line.strip_prefix('.').is_some() && !line.starts_with("..") {
            match lines.get(i + 1) {
                Some(next) if next.starts_with("image::") || next.starts_with("video::") => {}
                _ => return Err(format!("block title '{}' at line {} has no target block", line, i + 1)),
            }
        }
    }
    Ok(())
}

Try / catch

// Rust: convert_asciidoc_to_markdown returns anyhow::Result<String>
let markdown = convert_asciidoc_to_markdown(std::io::Cursor::new(&input))
    .map_err(|e| format!("release notes conversion error: {e:#}"))?;

Prevention

When it happens

Trigger: Feeding an AsciiDoc file whose last non-blank line is a block title (e.g., '.My Screenshot') with no subsequent image::[] or video::[] block. Also triggered if the title line is followed only by blank lines or EOF.

Common situations: Release notes draft left incomplete with a dangling caption; copy-paste of an AsciiDoc snippet that included a caption but not its media block; trailing '.' line left by an editor auto-format.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/653b54f23dea3edd. Report an issue: GitHub.