@@ -41,7 +41,7 @@ use tracing::debug;
4141use super :: link:: { self , ensure_removed} ;
4242use super :: lto:: { self , SerializedModule } ;
4343use super :: symbol_export:: symbol_name_for_instance_in_crate;
44- use crate :: errors:: { AutodiffWithoutLto , ErrorCreatingRemarkDir } ;
44+ use crate :: errors:: { AutodiffLibraryBuild , AutodiffWithoutLto , ErrorCreatingRemarkDir } ;
4545use crate :: traits:: * ;
4646use crate :: {
4747 CachedModuleCodegen , CodegenResults , CompiledModule , CrateInfo , ModuleCodegen , ModuleKind ,
@@ -419,7 +419,12 @@ fn generate_lto_work<B: ExtraBackendMethods>(
419419 } else {
420420 if !autodiff. is_empty ( ) {
421421 let dcx = cgcx. create_dcx ( ) ;
422- dcx. handle ( ) . emit_fatal ( AutodiffWithoutLto { } ) ;
422+ if cgcx. crate_types . contains ( & CrateType :: Rlib ) {
423+ dcx. handle ( ) . emit_fatal ( AutodiffLibraryBuild { } ) ;
424+ }
425+ if cgcx. lto != Lto :: Fat {
426+ dcx. handle ( ) . emit_fatal ( AutodiffWithoutLto { } ) ;
427+ }
423428 }
424429 assert ! ( needs_fat_lto. is_empty( ) ) ;
425430 let ( lto_modules, copy_jobs) = B :: run_thin_lto ( cgcx, needs_thin_lto, import_only_modules)
@@ -1456,6 +1461,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14561461 if needs_fat_lto. is_empty ( )
14571462 && needs_thin_lto. is_empty ( )
14581463 && lto_import_only_modules. is_empty ( )
1464+ && autodiff_items. is_empty ( )
14591465 {
14601466 // Nothing more to do!
14611467 break ;
@@ -1469,13 +1475,14 @@ fn start_executing_work<B: ExtraBackendMethods>(
14691475 assert ! ( !started_lto) ;
14701476 started_lto = true ;
14711477
1478+ let autodiff_items = mem:: take ( & mut autodiff_items) ;
14721479 let needs_fat_lto = mem:: take ( & mut needs_fat_lto) ;
14731480 let needs_thin_lto = mem:: take ( & mut needs_thin_lto) ;
14741481 let import_only_modules = mem:: take ( & mut lto_import_only_modules) ;
14751482
14761483 for ( work, cost) in generate_lto_work (
14771484 & cgcx,
1478- autodiff_items. clone ( ) ,
1485+ autodiff_items,
14791486 needs_fat_lto,
14801487 needs_thin_lto,
14811488 import_only_modules,
0 commit comments