@@ -129,8 +129,8 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
129129 c. items . push ( mk_main ( & mut self . cx ) ) ;
130130 }
131131
132- fn flat_map_item ( & mut self , mut i : P < ast :: Item > ) -> SmallVec < [ P < ast:: Item > ; 1 ] > {
133- let item = & mut * i ;
132+ fn visit_item ( & mut self , i : & mut P < ast:: Item > ) {
133+ let item = i . deref_mut ( ) ;
134134 if let Some ( name) = get_test_name ( & item) {
135135 debug ! ( "this is a test item" ) ;
136136
@@ -158,7 +158,6 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
158158 // But in those cases, we emit a lint to warn the user of these missing tests.
159159 walk_item ( & mut InnerItemLinter { sess : self . cx . ext_cx . sess } , & item) ;
160160 }
161- smallvec ! [ i]
162161 }
163162}
164163
@@ -198,40 +197,33 @@ struct EntryPointCleaner<'a> {
198197}
199198
200199impl < ' a > MutVisitor for EntryPointCleaner < ' a > {
201- fn flat_map_item ( & mut self , i : P < ast :: Item > ) -> SmallVec < [ P < ast:: Item > ; 1 ] > {
200+ fn visit_item ( & mut self , i : & mut P < ast:: Item > ) {
202201 self . depth += 1 ;
203- let item = walk_flat_map_item ( self , i) . expect_one ( "noop did something" ) ;
202+ walk_item ( self , i) ;
204203 self . depth -= 1 ;
205204
206205 // Remove any #[rustc_main] or #[start] from the AST so it doesn't
207206 // clash with the one we're going to add, but mark it as
208207 // #[allow(dead_code)] to avoid printing warnings.
209- let item = match entry_point_type ( & item, self . depth == 0 ) {
208+ match entry_point_type ( & item, self . depth == 0 ) {
210209 EntryPointType :: MainNamed | EntryPointType :: RustcMainAttr | EntryPointType :: Start => {
211- item. map ( |ast:: Item { id, ident, attrs, kind, vis, span, tokens } | {
212- let allow_dead_code = attr:: mk_attr_nested_word (
213- & self . sess . psess . attr_id_generator ,
214- ast:: AttrStyle :: Outer ,
215- ast:: Safety :: Default ,
216- sym:: allow,
217- sym:: dead_code,
218- self . def_site ,
219- ) ;
220- let attrs = attrs
221- . into_iter ( )
222- . filter ( |attr| {
223- !attr. has_name ( sym:: rustc_main) && !attr. has_name ( sym:: start)
224- } )
225- . chain ( iter:: once ( allow_dead_code) )
226- . collect ( ) ;
227-
228- ast:: Item { id, ident, attrs, kind, vis, span, tokens }
229- } )
210+ let allow_dead_code = attr:: mk_attr_nested_word (
211+ & self . sess . psess . attr_id_generator ,
212+ ast:: AttrStyle :: Outer ,
213+ ast:: Safety :: Default ,
214+ sym:: allow,
215+ sym:: dead_code,
216+ self . def_site ,
217+ ) ;
218+ item. attrs = item
219+ . attrs
220+ . into_iter ( )
221+ . filter ( |attr| !attr. has_name ( sym:: rustc_main) && !attr. has_name ( sym:: start) )
222+ . chain ( iter:: once ( allow_dead_code) )
223+ . collect ( ) ;
230224 }
231- EntryPointType :: None | EntryPointType :: OtherMain => item ,
225+ EntryPointType :: None | EntryPointType :: OtherMain => { }
232226 } ;
233-
234- smallvec ! [ item]
235227 }
236228}
237229
@@ -292,7 +284,7 @@ fn generate_test_harness(
292284/// Most of the Ident have the usual def-site hygiene for the AST pass. The
293285/// exception is the `test_const`s. These have a syntax context that has two
294286/// opaque marks: one from the expansion of `test` or `test_case`, and one
295- /// generated in `TestHarnessGenerator::flat_map_item `. When resolving this
287+ /// generated in `TestHarnessGenerator::visit_item `. When resolving this
296288/// identifier after failing to find a matching identifier in the root module
297289/// we remove the outer mark, and try resolving at its def-site, which will
298290/// then resolve to `test_const`.
0 commit comments