func view_with_name(view: &DeclView, name: String, context: &QuoteContext) -> SyntaxResult<Decl>Rebuild the declaration with a fresh, hygienically introduced name: the binder carries the definition site plus the expansion scope, so it neither captures caller names nor leaks into caller scope.
View Source
pub func view_with_name(view: &DeclView, name: String, context: &QuoteContext) -> SyntaxResult<Decl> {
if view.name_index < 0 {
return lens_failure(code: "syntax.lens.no-name", message: "The viewed declaration declares no replaceable name")
}
let leading = view.atoms[view.name_index].leading.clone()
let token = SyntaxToken(
kind: .identifier,
leading: leading,
spelling: name.clone(),
lexeme_start: 0,
lexeme_end: name.utf8().count(),
source_id: 0 - 1,
source_span: 0..<0,
context: introduced_context(context: context),
origin: .definition_site
)
rebuilt_with_name(view: view, token: token)
}