15
15
//! crate as a kind of pass. This should eventually be factored away.
16
16
17
17
use std:: assert_matches:: assert_matches;
18
- use std:: cell:: { Cell , RefCell } ;
18
+ use std:: cell:: Cell ;
19
19
use std:: iter;
20
20
use std:: ops:: Bound ;
21
21
@@ -130,8 +130,6 @@ pub(crate) fn provide(providers: &mut Providers) {
130
130
pub ( crate ) struct ItemCtxt < ' tcx > {
131
131
tcx : TyCtxt < ' tcx > ,
132
132
item_def_id : LocalDefId ,
133
- placeholder_types : RefCell < Vec < Span > > ,
134
- infer_replacements : RefCell < Vec < ( Span , String ) > > ,
135
133
tainted_by_errors : Cell < Option < ErrorGuaranteed > > ,
136
134
}
137
135
@@ -243,13 +241,7 @@ fn bad_placeholder<'cx, 'tcx>(
243
241
244
242
impl < ' tcx > ItemCtxt < ' tcx > {
245
243
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 ) }
253
245
}
254
246
255
247
pub ( crate ) fn lower_ty ( & self , hir_ty : & hir:: Ty < ' tcx > ) -> Ty < ' tcx > {
@@ -265,12 +257,6 @@ impl<'tcx> ItemCtxt<'tcx> {
265
257
}
266
258
267
259
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
- }
274
260
match self . tainted_by_errors . get ( ) {
275
261
Some ( err) => Err ( err) ,
276
262
None => Ok ( ( ) ) ,
@@ -281,7 +267,7 @@ impl<'tcx> ItemCtxt<'tcx> {
281
267
& self ,
282
268
placeholder_types : Vec < Span > ,
283
269
infer_replacements : Vec < ( Span , String ) > ,
284
- ) {
270
+ ) -> ErrorGuaranteed {
285
271
let node = self . tcx . hir_node_by_def_id ( self . item_def_id ) ;
286
272
let generics = node. generics ( ) ;
287
273
let kind_id = match node {
@@ -320,13 +306,7 @@ impl<'tcx> ItemCtxt<'tcx> {
320
306
) ;
321
307
}
322
308
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 ( )
330
310
}
331
311
}
332
312
@@ -362,13 +342,13 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
362
342
363
343
fn ty_infer ( & self , _: Option < & ty:: GenericParamDef > , span : Span ) -> Ty < ' tcx > {
364
344
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 ! [ ] ) ;
366
346
}
367
347
Ty :: new_error_with_message ( self . tcx ( ) , span, "bad placeholder type" )
368
348
}
369
349
370
350
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 ! [ ] ) ;
372
352
ty:: Const :: new_error_with_message ( self . tcx ( ) , span, "bad placeholder constant" )
373
353
}
374
354
@@ -549,6 +529,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
549
529
) -> ( Vec < Ty < ' tcx > > , Ty < ' tcx > ) {
550
530
let tcx = self . tcx ( ) ;
551
531
532
+ let mut infer_replacements = vec ! [ ] ;
533
+
552
534
let input_tys = decl
553
535
. inputs
554
536
. iter ( )
@@ -558,9 +540,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
558
540
if let Some ( suggested_ty) =
559
541
self . lowerer ( ) . suggest_trait_fn_ty_for_impl_fn_infer ( hir_id, Some ( i) )
560
542
{
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 ( ) ) ) ;
564
544
return Ty :: new_error_with_message ( tcx, a. span , suggested_ty. to_string ( ) ) ;
565
545
}
566
546
}
@@ -575,9 +555,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
575
555
&& let Some ( suggested_ty) =
576
556
self . lowerer ( ) . suggest_trait_fn_ty_for_impl_fn_infer ( hir_id, None )
577
557
{
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 ( ) ) ) ;
581
559
Ty :: new_error_with_message ( tcx, output. span , suggested_ty. to_string ( ) )
582
560
} else {
583
561
self . lower_ty ( output)
@@ -586,6 +564,9 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
586
564
hir:: FnRetTy :: DefaultReturn ( ..) => tcx. types . unit ,
587
565
} ;
588
566
567
+ if !infer_replacements. is_empty ( ) {
568
+ self . report_placeholder_type_error ( vec ! [ ] , infer_replacements) ;
569
+ }
589
570
( input_tys, output_ty)
590
571
}
591
572
0 commit comments