@@ -110,12 +110,9 @@ mod boxed_resolver {
110
110
}
111
111
112
112
impl BoxedResolver {
113
- pub ( super ) fn new < F > ( session : Lrc < Session > , make_resolver : F ) -> Result < ( ast :: Crate , Self ) >
113
+ pub ( super ) fn new < F > ( session : Lrc < Session > , make_resolver : F ) -> Self
114
114
where
115
- F : for < ' a > FnOnce (
116
- & ' a Session ,
117
- & ' a ResolverArenas < ' a > ,
118
- ) -> Result < ( ast:: Crate , Resolver < ' a > ) > ,
115
+ F : for < ' a > FnOnce ( & ' a Session , & ' a ResolverArenas < ' a > ) -> Resolver < ' a > ,
119
116
{
120
117
let mut boxed_resolver = Box :: new ( BoxedResolverInner {
121
118
session,
@@ -127,14 +124,14 @@ mod boxed_resolver {
127
124
// returns a resolver with the same lifetime as the arena. We ensure that the arena
128
125
// outlives the resolver in the drop impl and elsewhere so these transmutes are sound.
129
126
unsafe {
130
- let ( crate_ , resolver) = make_resolver (
127
+ let resolver = make_resolver (
131
128
std:: mem:: transmute :: < & Session , & Session > ( & boxed_resolver. session ) ,
132
129
std:: mem:: transmute :: < & ResolverArenas < ' _ > , & ResolverArenas < ' _ > > (
133
130
boxed_resolver. resolver_arenas . as_ref ( ) . unwrap ( ) ,
134
131
) ,
135
- ) ? ;
132
+ ) ;
136
133
boxed_resolver. resolver = Some ( resolver) ;
137
- Ok ( ( crate_ , BoxedResolver ( Pin :: new_unchecked ( boxed_resolver) ) ) )
134
+ BoxedResolver ( Pin :: new_unchecked ( boxed_resolver) )
138
135
}
139
136
}
140
137
@@ -165,35 +162,20 @@ mod boxed_resolver {
165
162
}
166
163
}
167
164
168
- /// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
169
- /// syntax expansion, secondary `cfg` expansion, synthesis of a test
170
- /// harness if one is to be provided, injection of a dependency on the
171
- /// standard library and prelude, and name resolution.
172
- ///
173
- /// Returns [`None`] if we're aborting after handling -W help.
174
- pub fn configure_and_expand (
165
+ pub fn create_resolver (
175
166
sess : Lrc < Session > ,
176
- lint_store : Lrc < LintStore > ,
177
167
metadata_loader : Box < MetadataLoaderDyn > ,
178
- krate : ast:: Crate ,
168
+ krate : & ast:: Crate ,
179
169
crate_name : & str ,
180
- ) -> Result < ( ast :: Crate , BoxedResolver ) > {
181
- tracing:: trace!( "configure_and_expand " ) ;
170
+ ) -> BoxedResolver {
171
+ tracing:: trace!( "create_resolver " ) ;
182
172
// Currently, we ignore the name resolution data structures for the purposes of dependency
183
173
// tracking. Instead we will run name resolution and include its output in the hash of each
184
174
// item, much like we do for macro expansion. In other words, the hash reflects not just
185
175
// its contents but the results of name resolution on those contents. Hopefully we'll push
186
176
// this back at some point.
187
- let crate_name = crate_name. to_string ( ) ;
188
177
BoxedResolver :: new ( sess, move |sess, resolver_arenas| {
189
- configure_and_expand_inner (
190
- sess,
191
- & lint_store,
192
- krate,
193
- & crate_name,
194
- & resolver_arenas,
195
- metadata_loader,
196
- )
178
+ Resolver :: new ( sess, & krate, & crate_name, metadata_loader, & resolver_arenas)
197
179
} )
198
180
}
199
181
@@ -278,28 +260,26 @@ fn pre_expansion_lint(
278
260
} ) ;
279
261
}
280
262
281
- fn configure_and_expand_inner < ' a > (
282
- sess : & ' a Session ,
263
+ /// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
264
+ /// syntax expansion, secondary `cfg` expansion, synthesis of a test
265
+ /// harness if one is to be provided, injection of a dependency on the
266
+ /// standard library and prelude, and name resolution.
267
+ ///
268
+ /// Returns [`None`] if we're aborting after handling -W help.
269
+ pub fn configure_and_expand (
270
+ sess : & Session ,
283
271
lint_store : & LintStore ,
284
272
mut krate : ast:: Crate ,
285
273
crate_name : & str ,
286
- resolver_arenas : & ' a ResolverArenas < ' a > ,
287
- metadata_loader : Box < MetadataLoaderDyn > ,
288
- ) -> Result < ( ast:: Crate , Resolver < ' a > ) > {
289
- tracing:: trace!( "configure_and_expand_inner" ) ;
274
+ resolver : & mut Resolver < ' _ > ,
275
+ ) -> Result < ast:: Crate > {
276
+ tracing:: trace!( "configure_and_expand" ) ;
290
277
pre_expansion_lint ( sess, lint_store, & krate, crate_name) ;
291
-
292
- let mut resolver = Resolver :: new ( sess, & krate, crate_name, metadata_loader, & resolver_arenas) ;
293
- rustc_builtin_macros:: register_builtin_macros ( & mut resolver) ;
278
+ rustc_builtin_macros:: register_builtin_macros ( resolver) ;
294
279
295
280
krate = sess. time ( "crate_injection" , || {
296
281
let alt_std_name = sess. opts . alt_std_name . as_ref ( ) . map ( |s| Symbol :: intern ( s) ) ;
297
- rustc_builtin_macros:: standard_library_imports:: inject (
298
- krate,
299
- & mut resolver,
300
- & sess,
301
- alt_std_name,
302
- )
282
+ rustc_builtin_macros:: standard_library_imports:: inject ( krate, resolver, & sess, alt_std_name)
303
283
} ) ;
304
284
305
285
util:: check_attr_crate_type ( & sess, & krate. attrs , & mut resolver. lint_buffer ( ) ) ;
@@ -354,7 +334,7 @@ fn configure_and_expand_inner<'a>(
354
334
pre_expansion_lint ( sess, lint_store, & krate, & ident. name . as_str ( ) ) ;
355
335
( krate. attrs , krate. items )
356
336
} ;
357
- let mut ecx = ExtCtxt :: new ( & sess, cfg, & mut resolver, Some ( & extern_mod_loaded) ) ;
337
+ let mut ecx = ExtCtxt :: new ( & sess, cfg, resolver, Some ( & extern_mod_loaded) ) ;
358
338
359
339
// Expand macros now!
360
340
let krate = sess. time ( "expand_crate" , || ecx. monotonic_expander ( ) . expand_crate ( krate) ) ;
@@ -396,16 +376,16 @@ fn configure_and_expand_inner<'a>(
396
376
} ) ?;
397
377
398
378
sess. time ( "maybe_building_test_harness" , || {
399
- rustc_builtin_macros:: test_harness:: inject ( & sess, & mut resolver, & mut krate)
379
+ rustc_builtin_macros:: test_harness:: inject ( & sess, resolver, & mut krate)
400
380
} ) ;
401
381
402
382
if let Some ( PpMode :: Source ( PpSourceMode :: EveryBodyLoops ) ) = sess. opts . pretty {
403
383
tracing:: debug!( "replacing bodies with loop {{}}" ) ;
404
- util:: ReplaceBodyWithLoop :: new ( & mut resolver) . visit_crate ( & mut krate) ;
384
+ util:: ReplaceBodyWithLoop :: new ( resolver) . visit_crate ( & mut krate) ;
405
385
}
406
386
407
387
let has_proc_macro_decls = sess. time ( "AST_validation" , || {
408
- rustc_ast_passes:: ast_validation:: check_crate ( sess, & krate, & mut resolver. lint_buffer ( ) )
388
+ rustc_ast_passes:: ast_validation:: check_crate ( sess, & krate, resolver. lint_buffer ( ) )
409
389
} ) ;
410
390
411
391
let crate_types = sess. crate_types ( ) ;
@@ -431,7 +411,7 @@ fn configure_and_expand_inner<'a>(
431
411
let is_test_crate = sess. opts . test ;
432
412
rustc_builtin_macros:: proc_macro_harness:: inject (
433
413
& sess,
434
- & mut resolver,
414
+ resolver,
435
415
krate,
436
416
is_proc_macro_crate,
437
417
has_proc_macro_decls,
@@ -471,7 +451,7 @@ fn configure_and_expand_inner<'a>(
471
451
}
472
452
} ) ;
473
453
474
- Ok ( ( krate, resolver ) )
454
+ Ok ( krate)
475
455
}
476
456
477
457
pub fn lower_to_hir < ' res , ' tcx > (
0 commit comments