rust-lang/rust-analyzer · warning

no block

Error message

no block

What it means

This expect lives in the test blocks_with_no_items_have_no_id: it asserts the fixture source actually contains a BlockExpr before checking that item-free blocks get no AST id. Panicking with 'no block' means the test fixture no longer parses into any BlockExpr, i.e. the fixture text or Edition drifted rather than production behavior failing.

Source

Thrown at crates/span/src/ast_id.rs:1042

            macro_call_bar_id.raw.hash_value(),
            "hashes are equal"
        );
    }

    #[test]
    fn blocks_with_no_items_have_no_id() {
        let syntax = SourceFile::parse(
            r#"
fn foo() {
    let foo = 1;
    bar(foo);
}
        "#,
            Edition::CURRENT,
        )
        .syntax_node();
        let ast_id_map = AstIdMap::from_source(&syntax);
        let block = syntax.descendants().find_map(ast::BlockExpr::cast).expect("no block");
        assert!(ast_id_map.ast_id_for_block(&block).is_none());
    }
}

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Inspect the fixture string in the test and restore a construct that parses as a BlockExpr.
  2. Run the parser/debug dump on the fixture to see what it now parses into.
  3. If grammar changed intentionally, update the test to cast the correct new node type.

Example fix

// before (fixture changed so no block parses)
let block = syntax.descendants().find_map(ast::BlockExpr::cast).expect("no block");
// after
let block = syntax.descendants().find_map(ast::BlockExpr::cast)
    .unwrap_or_else(|| panic!("fixture no longer contains a BlockExpr: {syntax:?}"));
Defensive patterns

Strategy: validation

Validate before calling

assert!(syntax.descendants().any(|n| ast::BlockExpr::can_cast(n.kind())),
    "fixture no longer contains a BlockExpr");

Prevention

When it happens

Trigger: Only when running rust-analyzer's span crate tests after someone edited the fixture source string or parser grammar so the fixture no longer contains a castable BlockExpr.

Common situations: Developers refactoring the test fixture, changing Edition::CURRENT handling, or modifying the parser such that the fixture's block is no longer parsed as ast::BlockExpr.

Related errors


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/4e6b713c626f2e10. Report an issue: GitHub.