Skip to main content

Spanned

Trait Spanned 

Source
pub trait Spanned {
    // Required method
    fn span(&self) -> Span;
}
Expand description

Every AST node must implement this trait.

The trait returns the node’s source Span — the byte-offset range in the original source file that this node corresponds to. This is a hard requirement for provenance tracking (R12) and diagnostic quality (every diagnostic has a non-empty Span pointing to the offending source range, plan §7.6).

§Contract

  • span() MUST return the tightest bounding span that covers all tokens belonging to this node.
  • For nodes that span multiple non-contiguous ranges (e.g., a package spec with a separate body), span() returns the primary span (the spec keyword range). Related spans are carried via SpanLabel in the Evidence or Diagnostic types.

Required Methods§

Source

fn span(&self) -> Span

The source span of this AST node.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§