1515//! crate as a kind of pass. This should eventually be factored away.
1616
1717use std:: assert_matches:: assert_matches;
18- use std:: cell:: { Cell , RefCell } ;
18+ use std:: cell:: Cell ;
1919use std:: iter;
2020use std:: ops:: Bound ;
2121
@@ -130,8 +130,6 @@ pub(crate) fn provide(providers: &mut Providers) {
130130pub ( crate ) struct ItemCtxt < ' tcx > {
131131 tcx : TyCtxt < ' tcx > ,
132132 item_def_id : LocalDefId ,
133- placeholder_types : RefCell < Vec < Span > > ,
134- infer_replacements : RefCell < Vec < ( Span , String ) > > ,
135133 tainted_by_errors : Cell < Option < ErrorGuaranteed > > ,
136134}
137135
@@ -243,13 +241,7 @@ fn bad_placeholder<'cx, 'tcx>(
243241
244242impl < ' tcx > ItemCtxt < ' tcx > {
245243 pub ( crate ) fn new ( tcx : TyCtxt < ' tcx > , item_def_id : LocalDefId ) -> ItemCtxt < ' tcx > {
246- ItemCtxt {
247- tcx,
248- item_def_id,
249- tainted_by_errors : Cell :: new ( None ) ,
250- placeholder_types : Default :: default ( ) ,
251- infer_replacements : Default :: default ( ) ,
252- }
244+ ItemCtxt { tcx, item_def_id, tainted_by_errors : Cell :: new ( None ) }
253245 }
254246
255247 pub ( crate ) fn lower_ty ( & self , hir_ty : & hir:: Ty < ' tcx > ) -> Ty < ' tcx > {
@@ -265,12 +257,6 @@ impl<'tcx> ItemCtxt<'tcx> {
265257 }
266258
267259 fn check_tainted_by_errors ( & self ) -> Result < ( ) , ErrorGuaranteed > {
268- let placeholder_types = std:: mem:: take ( & mut * self . placeholder_types . borrow_mut ( ) ) ;
269- let infer_replacements = std:: mem:: take ( & mut * self . infer_replacements . borrow_mut ( ) ) ;
270-
271- if !placeholder_types. is_empty ( ) || !infer_replacements. is_empty ( ) {
272- self . report_placeholder_type_error ( placeholder_types, infer_replacements) ;
273- }
274260 match self . tainted_by_errors . get ( ) {
275261 Some ( err) => Err ( err) ,
276262 None => Ok ( ( ) ) ,
@@ -281,7 +267,7 @@ impl<'tcx> ItemCtxt<'tcx> {
281267 & self ,
282268 placeholder_types : Vec < Span > ,
283269 infer_replacements : Vec < ( Span , String ) > ,
284- ) {
270+ ) -> ErrorGuaranteed {
285271 let node = self . tcx . hir_node_by_def_id ( self . item_def_id ) ;
286272 let generics = node. generics ( ) ;
287273 let kind_id = match node {
@@ -320,13 +306,7 @@ impl<'tcx> ItemCtxt<'tcx> {
320306 ) ;
321307 }
322308
323- diag. emit ( ) ;
324- }
325- }
326-
327- impl Drop for ItemCtxt < ' _ > {
328- fn drop ( & mut self ) {
329- _ = self . check_tainted_by_errors ( ) ;
309+ diag. emit ( )
330310 }
331311}
332312
@@ -362,13 +342,13 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
362342
363343 fn ty_infer ( & self , _: Option < & ty:: GenericParamDef > , span : Span ) -> Ty < ' tcx > {
364344 if !self . tcx . dcx ( ) . has_stashed_diagnostic ( span, StashKey :: ItemNoType ) {
365- self . placeholder_types . borrow_mut ( ) . push ( span) ;
345+ self . report_placeholder_type_error ( vec ! [ span] , vec ! [ ] ) ;
366346 }
367347 Ty :: new_error_with_message ( self . tcx ( ) , span, "bad placeholder type" )
368348 }
369349
370350 fn ct_infer ( & self , _: Option < & ty:: GenericParamDef > , span : Span ) -> Const < ' tcx > {
371- self . placeholder_types . borrow_mut ( ) . push ( span) ;
351+ self . report_placeholder_type_error ( vec ! [ span] , vec ! [ ] ) ;
372352 ty:: Const :: new_error_with_message ( self . tcx ( ) , span, "bad placeholder constant" )
373353 }
374354
@@ -549,6 +529,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
549529 ) -> ( Vec < Ty < ' tcx > > , Ty < ' tcx > ) {
550530 let tcx = self . tcx ( ) ;
551531
532+ let mut infer_replacements = vec ! [ ] ;
533+
552534 let input_tys = decl
553535 . inputs
554536 . iter ( )
@@ -558,9 +540,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
558540 if let Some ( suggested_ty) =
559541 self . lowerer ( ) . suggest_trait_fn_ty_for_impl_fn_infer ( hir_id, Some ( i) )
560542 {
561- self . infer_replacements
562- . borrow_mut ( )
563- . push ( ( a. span , suggested_ty. to_string ( ) ) ) ;
543+ infer_replacements. push ( ( a. span , suggested_ty. to_string ( ) ) ) ;
564544 return Ty :: new_error_with_message ( tcx, a. span , suggested_ty. to_string ( ) ) ;
565545 }
566546 }
@@ -575,9 +555,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
575555 && let Some ( suggested_ty) =
576556 self . lowerer ( ) . suggest_trait_fn_ty_for_impl_fn_infer ( hir_id, None )
577557 {
578- self . infer_replacements
579- . borrow_mut ( )
580- . push ( ( output. span , suggested_ty. to_string ( ) ) ) ;
558+ infer_replacements. push ( ( output. span , suggested_ty. to_string ( ) ) ) ;
581559 Ty :: new_error_with_message ( tcx, output. span , suggested_ty. to_string ( ) )
582560 } else {
583561 self . lower_ty ( output)
@@ -586,6 +564,9 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
586564 hir:: FnRetTy :: DefaultReturn ( ..) => tcx. types . unit ,
587565 } ;
588566
567+ if !infer_replacements. is_empty ( ) {
568+ self . report_placeholder_type_error ( vec ! [ ] , infer_replacements) ;
569+ }
589570 ( input_tys, output_ty)
590571 }
591572
0 commit comments