view_with_name_token

func view_with_name_token(view: &DeclView, source_id: Int, source: String, token: Token, use_site: &SyntaxContext) -> SyntaxResult<Decl>

Rebuild the declaration with a caller-provided identifier as the binder (ADR 0026's intentional exposure path). The token must come from use-site syntax — typically the wrapper's argument tree — and keeps its use-site context, so callers can see the rebuilt name.

View Source
pub func view_with_name_token(view: &DeclView, source_id: Int, source: String, token: Token, use_site: &SyntaxContext) -> SyntaxResult<Decl> {
	if view.name_index < 0 {
		return lens_failure(code: "syntax.lens.no-name", message: "The viewed declaration declares no replaceable name")
	}
	if token.kind != .identifier {
		return lens_failure(code: "syntax.lens.not-identifier", message: "A declaration name must be spliced from an identifier token")
	}
	let leading = view.atoms[view.name_index].leading.clone()
	let named = SyntaxToken(
		kind: .identifier,
		leading: leading,
		spelling: source_slice(view: source.utf8(), range: token.span),
		lexeme_start: token.lexeme.lower - token.span.lower,
		lexeme_end: token.lexeme.upper - token.span.lower,
		source_id: source_id,
		source_span: token.span.lower..<token.span.upper,
		context: copy_syntax_context(context: use_site),
		origin: .use_site
	)
	rebuilt_with_name(view: view, token: named)
}