From 96422b648929d8fe9637cc567a0a0838ab970ca9 Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Mon, 19 Aug 2024 05:32:30 +0000 Subject: [PATCH] refactor(ast): make AstBuilder non-exhaustive (#4925) --- crates/oxc_ast/src/generated/ast_builder.rs | 1 + crates/oxc_transformer/src/lib.rs | 6 +++--- tasks/ast_tools/src/generators/ast_builder.rs | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index 1c81192b537b1..ebaf45bf99641 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -14,6 +14,7 @@ use crate::ast::*; /// AST builder for creating AST nodes #[derive(Clone, Copy)] +#[non_exhaustive] pub struct AstBuilder<'a> { pub allocator: &'a Allocator, } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 47b332255aefb..5709cfb79ac00 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -34,7 +34,7 @@ use es2019::ES2019; use es2020::ES2020; use es2021::ES2021; use oxc_allocator::{Allocator, Vec}; -use oxc_ast::{ast::*, AstBuilder, Trivias}; +use oxc_ast::{ast::*, Trivias}; use oxc_diagnostics::OxcDiagnostic; use oxc_semantic::{ScopeTree, SemanticBuilder, SymbolTable}; use oxc_span::SourceType; @@ -107,7 +107,7 @@ impl<'a> Transformer<'a> { .build(program) .semantic .into_symbol_table_and_scope_tree(); - let TransformCtx { ast: AstBuilder { allocator }, .. } = *self.ctx; + let allocator: &'a Allocator = self.ctx.ast.allocator; let (symbols, scopes) = traverse_mut(&mut self, allocator, program, symbols, scopes); TransformerReturn { errors: self.ctx.take_errors(), symbols, scopes } } @@ -118,7 +118,7 @@ impl<'a> Transformer<'a> { scopes: ScopeTree, program: &mut Program<'a>, ) -> TransformerReturn { - let TransformCtx { ast: AstBuilder { allocator }, .. } = *self.ctx; + let allocator: &'a Allocator = self.ctx.ast.allocator; let (symbols, scopes) = traverse_mut(&mut self, allocator, program, symbols, scopes); TransformerReturn { errors: self.ctx.take_errors(), symbols, scopes } } diff --git a/tasks/ast_tools/src/generators/ast_builder.rs b/tasks/ast_tools/src/generators/ast_builder.rs index d1c215a712e6d..dee73cb70710c 100644 --- a/tasks/ast_tools/src/generators/ast_builder.rs +++ b/tasks/ast_tools/src/generators/ast_builder.rs @@ -57,6 +57,7 @@ impl Generator for AstBuilderGenerator { ///@@line_break /// AST builder for creating AST nodes #[derive(Clone, Copy)] + #[non_exhaustive] pub struct AstBuilder<'a> { pub allocator: &'a Allocator, }