@@ -213,8 +213,8 @@ pub fn unsized_info(
213213 vtable_ptr. llvm_type ( cx) )
214214 }
215215 _ => bug ! ( "unsized_info: invalid unsizing {:?} -> {:?}" ,
216- source,
217- target) ,
216+ source,
217+ target) ,
218218 }
219219}
220220
@@ -340,11 +340,11 @@ pub fn cast_shift_expr_rhs(
340340}
341341
342342fn cast_shift_rhs < ' ll , F , G > ( op : hir:: BinOpKind ,
343- lhs : & ' ll Value ,
344- rhs : & ' ll Value ,
345- trunc : F ,
346- zext : G )
347- -> & ' ll Value
343+ lhs : & ' ll Value ,
344+ rhs : & ' ll Value ,
345+ trunc : F ,
346+ zext : G )
347+ -> & ' ll Value
348348 where F : FnOnce ( & ' ll Value , & ' ll Type ) -> & ' ll Value ,
349349 G : FnOnce ( & ' ll Value , & ' ll Type ) -> & ' ll Value
350350{
@@ -363,8 +363,8 @@ fn cast_shift_rhs<'ll, F, G>(op: hir::BinOpKind,
363363 if lhs_sz < rhs_sz {
364364 trunc ( rhs, lhs_llty)
365365 } else if lhs_sz > rhs_sz {
366- // FIXME (#1877: If shifting by negative
367- // values becomes not undefined then this is wrong.
366+ // FIXME (#1877: If in the future shifting by negative
367+ // values is no longer undefined then this is wrong.
368368 zext ( rhs, lhs_llty)
369369 } else {
370370 rhs
@@ -495,10 +495,8 @@ pub fn codegen_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, instance: Instance<'
495495 let sig = common:: ty_fn_sig ( cx, fn_ty) ;
496496 let sig = cx. tcx . normalize_erasing_late_bound_regions ( ty:: ParamEnv :: reveal_all ( ) , & sig) ;
497497
498- let lldecl = match cx. instances . borrow ( ) . get ( & instance) {
499- Some ( & val) => val,
500- None => bug ! ( "Instance `{:?}` not already declared" , instance)
501- } ;
498+ let lldecl = cx. instances . borrow ( ) . get ( & instance) . cloned ( ) . unwrap_or_else ( ||
499+ bug ! ( "Instance `{:?}` not already declared" , instance) ) ;
502500
503501 cx. stats . borrow_mut ( ) . n_closures += 1 ;
504502
@@ -566,8 +564,8 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
566564 if declare:: get_defined_value ( cx, "main" ) . is_some ( ) {
567565 // FIXME: We should be smart and show a better diagnostic here.
568566 cx. sess ( ) . struct_span_err ( sp, "entry symbol `main` defined multiple times" )
569- . help ( "did you use #[no_mangle] on `fn main`? Use #[start] instead" )
570- . emit ( ) ;
567+ . help ( "did you use #[no_mangle] on `fn main`? Use #[start] instead" )
568+ . emit ( ) ;
571569 cx. sess ( ) . abort_if_errors ( ) ;
572570 bug ! ( ) ;
573571 }
@@ -736,9 +734,9 @@ fn determine_cgu_reuse<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
736734}
737735
738736pub fn codegen_crate < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
739- rx : mpsc:: Receiver < Box < dyn Any + Send > > )
740- -> OngoingCodegen {
741-
737+ rx : mpsc:: Receiver < Box < dyn Any + Send > > )
738+ -> OngoingCodegen
739+ {
742740 check_for_rustc_errors_attr ( tcx) ;
743741
744742 if let Some ( true ) = tcx. sess . opts . debugging_opts . thinlto {
@@ -803,8 +801,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
803801
804802 // Run the monomorphization collector and partition the collected items into
805803 // codegen units.
806- let codegen_units =
807- tcx. collect_and_partition_mono_items ( LOCAL_CRATE ) . 1 ;
804+ let codegen_units = tcx. collect_and_partition_mono_items ( LOCAL_CRATE ) . 1 ;
808805 let codegen_units = ( * codegen_units) . clone ( ) ;
809806
810807 // Force all codegen_unit queries so they are already either red or green
@@ -837,12 +834,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
837834 . iter ( )
838835 . any ( |( _, list) | {
839836 use rustc:: middle:: dependency_format:: Linkage ;
840- list. iter ( ) . any ( |linkage| {
841- match linkage {
842- Linkage :: Dynamic => true ,
843- _ => false ,
844- }
845- } )
837+ list. iter ( ) . any ( |& linkage| linkage == Linkage :: Dynamic )
846838 } ) ;
847839 let allocator_module = if any_dynamic_crate {
848840 None
@@ -988,7 +980,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>(
988980 if mode_string != "lazy" {
989981 let message = format ! ( "Unknown codegen-item collection mode '{}'. \
990982 Falling back to 'lazy' mode.",
991- mode_string) ;
983+ mode_string) ;
992984 tcx. sess . warn ( & message) ;
993985 }
994986
@@ -1123,7 +1115,15 @@ impl CrateInfo {
11231115 info. load_wasm_imports ( tcx, LOCAL_CRATE ) ;
11241116 }
11251117
1126- for & cnum in tcx. crates ( ) . iter ( ) {
1118+ let crates = tcx. crates ( ) ;
1119+
1120+ let n_crates = crates. len ( ) ;
1121+ info. native_libraries . reserve ( n_crates) ;
1122+ info. crate_name . reserve ( n_crates) ;
1123+ info. used_crate_source . reserve ( n_crates) ;
1124+ info. missing_lang_items . reserve ( n_crates) ;
1125+
1126+ for & cnum in crates. iter ( ) {
11271127 info. native_libraries . insert ( cnum, tcx. native_libraries ( cnum) ) ;
11281128 info. crate_name . insert ( cnum, tcx. crate_name ( cnum) . to_string ( ) ) ;
11291129 info. used_crate_source . insert ( cnum, tcx. used_crate_source ( cnum) ) ;
@@ -1165,11 +1165,12 @@ impl CrateInfo {
11651165 }
11661166
11671167 fn load_wasm_imports ( & mut self , tcx : TyCtxt , cnum : CrateNum ) {
1168- for ( & id , module ) in tcx. wasm_import_module_map ( cnum) . iter ( ) {
1168+ self . wasm_imports . extend ( tcx. wasm_import_module_map ( cnum) . iter ( ) . map ( | ( & id , module ) | {
11691169 let instance = Instance :: mono ( tcx, id) ;
11701170 let import_name = tcx. symbol_name ( instance) ;
1171- self . wasm_imports . insert ( import_name. to_string ( ) , module. clone ( ) ) ;
1172- }
1171+
1172+ ( import_name. to_string ( ) , module. clone ( ) )
1173+ } ) ) ;
11731174 }
11741175}
11751176
0 commit comments