1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Tests to ensure lifetimes prevent references to escape visitor functions.
//! If they could, it'd allow aliasing, which would be undefined behavior.
//!
//! These tests were originally implemented using `trybuild` crate,
//! but it disproportionately hurt time taken to run tests.
//! So using `compile_fail` doc tests instead.
//! <https://github.com/oxc-project/oxc/issues/4537>
/**
```compile_fail
use oxc_ast::ast::IdentifierReference;
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
struct Trans<'a, 'b> {
ancestor: Option<Ancestor<'a, 'b>>,
}
impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
self.ancestor = Some(ctx.parent());
}
}
```
*/
const CANNOT_HOLD_ONTO_ANCESTOR: = ;
/**
```compile_fail
use oxc_ast::ast::IdentifierReference;
use oxc_traverse::{ancestor::ProgramWithoutDirectives, Ancestor, Traverse, TraverseCtx};
struct Trans<'a, 'b> {
program: Option<ProgramWithoutDirectives<'a, 'b>>,
}
impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
if let Ancestor::ProgramDirectives(program) = ctx.parent() {
self.program = Some(program);
}
}
}
```
*/
const CANNOT_HOLD_ONTO_ANCESTOR_NODE: = ;
/**
```compile_fail
use oxc_ast::ast::{IdentifierReference, Statement};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
struct Trans<'a, 'b> {
stmt: Option<&'b Statement<'a>>,
}
impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
if let Ancestor::ProgramDirectives(program) = ctx.parent() {
let body = program.body();
let stmt = &body[0];
self.stmt = Some(stmt);
}
}
}
```
*/
const CANNOT_HOLD_ONTO_AST_NODE: = ;
/**
```compile_fail
use oxc_ast::ast::IdentifierReference;
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
struct Trans<'a, 'b> {
ancestor: Option<Ancestor<'a, 'b>>,
}
impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
self.ancestor = ctx.ancestors().next();
}
}
```
*/
const CANNOT_HOLD_ONTO_ANCESTOR_FROM_ANCESTORS_ITERATOR: = ;
/**
```compile_fail
use oxc_ast::ast::IdentifierReference;
use oxc_traverse::{ancestor::ProgramWithoutDirectives, Ancestor, Traverse, TraverseCtx};
struct Trans<'a, 'b> {
program: Option<ProgramWithoutDirectives<'a, 'b>>,
}
impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let parent = ctx.ancestors().next().unwrap();
if let Ancestor::ProgramDirectives(program) = parent {
self.program = Some(program);
}
}
}
```
*/
const CANNOT_HOLD_ONTO_ANCESTOR_NODE_FROM_ANCESTORS_ITERATOR: = ;
/**
```compile_fail
use oxc_ast::ast::{IdentifierReference, Statement};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
struct Trans<'a, 'b> {
stmt: Option<&'b Statement<'a>>,
}
impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let parent = ctx.ancestors().next().unwrap();
if let Ancestor::ProgramDirectives(program) = parent {
let body = program.body();
let stmt = &body[0];
self.stmt = Some(stmt);
}
}
}
```
*/
const CANNOT_HOLD_ONTO_AST_NODE_FROM_ANCESTORS_ITERATOR: = ;