@@ -110,12 +110,9 @@ mod boxed_resolver {
110110 }
111111
112112 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
114114 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 > ,
119116 {
120117 let mut boxed_resolver = Box :: new ( BoxedResolverInner {
121118 session,
@@ -127,14 +124,14 @@ mod boxed_resolver {
127124 // returns a resolver with the same lifetime as the arena. We ensure that the arena
128125 // outlives the resolver in the drop impl and elsewhere so these transmutes are sound.
129126 unsafe {
130- let ( crate_ , resolver) = make_resolver (
127+ let resolver = make_resolver (
131128 std:: mem:: transmute :: < & Session , & Session > ( & boxed_resolver. session ) ,
132129 std:: mem:: transmute :: < & ResolverArenas < ' _ > , & ResolverArenas < ' _ > > (
133130 boxed_resolver. resolver_arenas . as_ref ( ) . unwrap ( ) ,
134131 ) ,
135- ) ? ;
132+ ) ;
136133 boxed_resolver. resolver = Some ( resolver) ;
137- Ok ( ( crate_ , BoxedResolver ( Pin :: new_unchecked ( boxed_resolver) ) ) )
134+ BoxedResolver ( Pin :: new_unchecked ( boxed_resolver) )
138135 }
139136 }
140137
@@ -165,35 +162,20 @@ mod boxed_resolver {
165162 }
166163}
167164
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 (
175166 sess : Lrc < Session > ,
176- lint_store : Lrc < LintStore > ,
177167 metadata_loader : Box < MetadataLoaderDyn > ,
178- krate : ast:: Crate ,
168+ krate : & ast:: Crate ,
179169 crate_name : & str ,
180- ) -> Result < ( ast :: Crate , BoxedResolver ) > {
181- tracing:: trace!( "configure_and_expand " ) ;
170+ ) -> BoxedResolver {
171+ tracing:: trace!( "create_resolver " ) ;
182172 // Currently, we ignore the name resolution data structures for the purposes of dependency
183173 // tracking. Instead we will run name resolution and include its output in the hash of each
184174 // item, much like we do for macro expansion. In other words, the hash reflects not just
185175 // its contents but the results of name resolution on those contents. Hopefully we'll push
186176 // this back at some point.
187- let crate_name = crate_name. to_string ( ) ;
188177 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)
197179 } )
198180}
199181
@@ -278,28 +260,26 @@ fn pre_expansion_lint(
278260 } ) ;
279261}
280262
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 ,
283271 lint_store : & LintStore ,
284272 mut krate : ast:: Crate ,
285273 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" ) ;
290277 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) ;
294279
295280 krate = sess. time ( "crate_injection" , || {
296281 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)
303283 } ) ;
304284
305285 util:: check_attr_crate_type ( & sess, & krate. attrs , & mut resolver. lint_buffer ( ) ) ;
@@ -354,7 +334,7 @@ fn configure_and_expand_inner<'a>(
354334 pre_expansion_lint ( sess, lint_store, & krate, & ident. name . as_str ( ) ) ;
355335 ( krate. attrs , krate. items )
356336 } ;
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) ) ;
358338
359339 // Expand macros now!
360340 let krate = sess. time ( "expand_crate" , || ecx. monotonic_expander ( ) . expand_crate ( krate) ) ;
@@ -396,16 +376,16 @@ fn configure_and_expand_inner<'a>(
396376 } ) ?;
397377
398378 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)
400380 } ) ;
401381
402382 if let Some ( PpMode :: Source ( PpSourceMode :: EveryBodyLoops ) ) = sess. opts . pretty {
403383 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) ;
405385 }
406386
407387 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 ( ) )
409389 } ) ;
410390
411391 let crate_types = sess. crate_types ( ) ;
@@ -431,7 +411,7 @@ fn configure_and_expand_inner<'a>(
431411 let is_test_crate = sess. opts . test ;
432412 rustc_builtin_macros:: proc_macro_harness:: inject (
433413 & sess,
434- & mut resolver,
414+ resolver,
435415 krate,
436416 is_proc_macro_crate,
437417 has_proc_macro_decls,
@@ -471,7 +451,7 @@ fn configure_and_expand_inner<'a>(
471451 }
472452 } ) ;
473453
474- Ok ( ( krate, resolver ) )
454+ Ok ( krate)
475455}
476456
477457pub fn lower_to_hir < ' res , ' tcx > (
0 commit comments