1
- use crate :: infer:: type_variable:: TypeVariableOriginKind ;
1
+ use crate :: infer:: { InferCtxtInner , type_variable:: TypeVariableOriginKind } ;
2
2
use crate :: infer:: InferCtxt ;
3
3
use rustc_errors:: { pluralize, struct_span_err, Applicability , DiagnosticBuilder } ;
4
4
use rustc_hir as hir;
@@ -16,8 +16,8 @@ use rustc_span::symbol::kw;
16
16
use rustc_span:: Span ;
17
17
use std:: borrow:: Cow ;
18
18
19
- struct FindHirNodeVisitor < ' a , ' tcx > {
20
- infcx : & ' a InferCtxt < ' a , ' tcx > ,
19
+ struct FindHirNodeVisitor < ' a , ' cx , ' tcx > {
20
+ infcx : & ' a mut InferCtxt < ' cx , ' tcx > ,
21
21
target : GenericArg < ' tcx > ,
22
22
target_span : Span ,
23
23
found_node_ty : Option < Ty < ' tcx > > ,
@@ -29,8 +29,8 @@ struct FindHirNodeVisitor<'a, 'tcx> {
29
29
found_use_diagnostic : Option < UseDiagnostic < ' tcx > > ,
30
30
}
31
31
32
- impl < ' a , ' tcx > FindHirNodeVisitor < ' a , ' tcx > {
33
- fn new ( infcx : & ' a InferCtxt < ' a , ' tcx > , target : GenericArg < ' tcx > , target_span : Span ) -> Self {
32
+ impl < ' a , ' cx , ' tcx > FindHirNodeVisitor < ' a , ' cx , ' tcx > {
33
+ fn new ( infcx : & ' a mut InferCtxt < ' cx , ' tcx > , target : GenericArg < ' tcx > , target_span : Span ) -> Self {
34
34
Self {
35
35
infcx,
36
36
target,
@@ -49,7 +49,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
49
49
self . infcx . in_progress_typeck_results ?. borrow ( ) . node_type_opt ( hir_id)
50
50
}
51
51
52
- fn node_ty_contains_target ( & self , hir_id : HirId ) -> Option < Ty < ' tcx > > {
52
+ fn node_ty_contains_target ( & mut self , hir_id : HirId ) -> Option < Ty < ' tcx > > {
53
53
self . node_type_opt ( hir_id) . map ( |ty| self . infcx . resolve_vars_if_possible ( ty) ) . filter ( |ty| {
54
54
ty. walk ( ) . any ( |inner| {
55
55
inner == self . target
@@ -80,7 +80,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
80
80
}
81
81
}
82
82
83
- impl < ' a , ' tcx > Visitor < ' tcx > for FindHirNodeVisitor < ' a , ' tcx > {
83
+ impl < ' a , ' tcx > Visitor < ' tcx > for FindHirNodeVisitor < ' a , ' _ , ' tcx > {
84
84
type Map = Map < ' tcx > ;
85
85
86
86
fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
@@ -345,15 +345,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
345
345
/// Extracts data used by diagnostic for either types or constants
346
346
/// which were stuck during inference.
347
347
pub fn extract_inference_diagnostics_data (
348
- & self ,
348
+ & mut self ,
349
349
arg : GenericArg < ' tcx > ,
350
350
highlight : Option < ty:: print:: RegionHighlightMode > ,
351
351
) -> InferenceDiagnosticsData {
352
352
match arg. unpack ( ) {
353
353
GenericArgKind :: Type ( ty) => {
354
354
if let ty:: Infer ( ty:: TyVar ( ty_vid) ) = * ty. kind ( ) {
355
- let mut inner = self . inner ;
356
- let ty_vars = & inner. type_variables ( ) ;
355
+ let ty_vars = & self . inner . type_variables ( ) ;
357
356
let var_origin = ty_vars. var_origin ( ty_vid) ;
358
357
if let TypeVariableOriginKind :: TypeParameterDefinition ( name, def_id) =
359
358
var_origin. kind
@@ -424,7 +423,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
424
423
}
425
424
426
425
pub fn emit_inference_failure_err (
427
- & self ,
426
+ & mut self ,
428
427
body_id : Option < hir:: BodyId > ,
429
428
span : Span ,
430
429
arg : GenericArg < ' tcx > ,
@@ -434,11 +433,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
434
433
let arg = self . resolve_vars_if_possible ( arg) ;
435
434
let arg_data = self . extract_inference_diagnostics_data ( arg, None ) ;
436
435
437
- let mut local_visitor = FindHirNodeVisitor :: new ( & self , arg, span) ;
438
- let ty_to_string = |ty : Ty < ' tcx > | -> String {
436
+ let tcx = self . tcx ;
437
+ let mut local_visitor = FindHirNodeVisitor :: new ( self , arg, span) ;
438
+ let ty_to_string = |ty : Ty < ' tcx > , inner : & mut InferCtxtInner < ' _ > | -> String {
439
439
let mut s = String :: new ( ) ;
440
- let mut printer = ty:: print:: FmtPrinter :: new ( self . tcx , & mut s, Namespace :: TypeNS ) ;
441
- let mut inner = self . inner ;
440
+ let mut printer = ty:: print:: FmtPrinter :: new ( tcx, & mut s, Namespace :: TypeNS ) ;
442
441
let ty_vars = inner. type_variables ( ) ;
443
442
let getter = move |ty_vid| {
444
443
let var_origin = ty_vars. var_origin ( ty_vid) ;
@@ -451,15 +450,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
451
450
let _ = if let ty:: FnDef ( ..) = ty. kind ( ) {
452
451
// We don't want the regular output for `fn`s because it includes its path in
453
452
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
454
- ty. fn_sig ( self . tcx ) . print ( printer)
453
+ ty. fn_sig ( tcx) . print ( printer)
455
454
} else {
456
455
ty. print ( printer)
457
456
} ;
458
457
s
459
458
} ;
460
459
461
460
if let Some ( body_id) = body_id {
462
- let expr = self . tcx . hir ( ) . expect_expr ( body_id. hir_id ) ;
461
+ let expr = tcx. hir ( ) . expect_expr ( body_id. hir_id ) ;
463
462
local_visitor. visit_expr ( expr) ;
464
463
}
465
464
let err_span = if let Some ( pattern) = local_visitor. found_arg_pattern {
@@ -491,7 +490,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
491
490
let is_named_and_not_impl_trait = |ty : Ty < ' _ > | {
492
491
& ty. to_string ( ) != "_" &&
493
492
// FIXME: Remove this check after `impl_trait_in_bindings` is stabilized. #63527
494
- ( !ty. is_impl_trait ( ) || self . tcx . features ( ) . impl_trait_in_bindings )
493
+ ( !ty. is_impl_trait ( ) || tcx. features ( ) . impl_trait_in_bindings )
495
494
} ;
496
495
497
496
let ty_msg = match ( local_visitor. found_node_ty , local_visitor. found_exact_method_call ) {
@@ -505,7 +504,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
505
504
format ! ( " for the closure `fn({}) -> {}`" , args, ret)
506
505
}
507
506
( Some ( ty) , _) if is_named_and_not_impl_trait ( ty) => {
508
- let ty = ty_to_string ( ty) ;
507
+ let ty = ty_to_string ( ty, & mut local_visitor . infcx . inner ) ;
509
508
format ! ( " for `{}`" , ty)
510
509
}
511
510
_ => String :: new ( ) ,
@@ -525,7 +524,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
525
524
// | the type parameter `E` is specified
526
525
// ```
527
526
let error_code = error_code. into ( ) ;
528
- let mut err = self . tcx . sess . struct_span_err_with_code (
527
+ let mut err = tcx. sess . struct_span_err_with_code (
529
528
err_span,
530
529
& format ! ( "type annotations needed{}" , ty_msg) ,
531
530
error_code,
@@ -555,7 +554,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
555
554
closure_return_type_suggestion (
556
555
& mut err,
557
556
& decl. output ,
558
- self . tcx . hir ( ) . body ( body_id) ,
557
+ tcx. hir ( ) . body ( body_id) ,
559
558
& ret,
560
559
) ;
561
560
// We don't want to give the other suggestions when the problem is the
@@ -575,11 +574,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
575
574
format ! ( "a boxed closure type like `Box<dyn Fn({}) -> {}>`" , args, ret)
576
575
}
577
576
Some ( ty) if is_named_and_not_impl_trait ( ty) && arg_data. name == "_" => {
578
- let ty = ty_to_string ( ty) ;
577
+ let ty = ty_to_string ( ty, & mut local_visitor . infcx . inner ) ;
579
578
format ! ( "the explicit type `{}`, with the type parameters specified" , ty)
580
579
}
581
580
Some ( ty) if is_named_and_not_impl_trait ( ty) && ty. to_string ( ) != arg_data. name => {
582
- let ty = ty_to_string ( ty) ;
581
+ let ty = ty_to_string ( ty, & mut local_visitor . infcx . inner ) ;
583
582
format ! (
584
583
"the explicit type `{}`, where the type parameter `{}` is specified" ,
585
584
ty, arg_data. name,
@@ -616,7 +615,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
616
615
// | this method call resolves to `std::option::Option<&T>`
617
616
// |
618
617
// = note: type must be known at this point
619
- self . annotate_method_call ( segment, e, & mut err) ;
618
+ local_visitor . infcx . annotate_method_call ( segment, e, & mut err) ;
620
619
}
621
620
} else if let Some ( pattern) = local_visitor. found_arg_pattern {
622
621
// We don't want to show the default label for closures.
@@ -717,7 +716,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
717
716
// | this method call resolves to `std::option::Option<&T>`
718
717
// |
719
718
// = note: type must be known at this point
720
- self . annotate_method_call ( segment, e, & mut err) ;
719
+ local_visitor . infcx . annotate_method_call ( segment, e, & mut err) ;
721
720
}
722
721
}
723
722
// Instead of the following:
@@ -831,7 +830,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
831
830
}
832
831
833
832
pub fn need_type_info_err_in_generator (
834
- & self ,
833
+ & mut self ,
835
834
kind : hir:: GeneratorKind ,
836
835
span : Span ,
837
836
ty : Ty < ' tcx > ,
0 commit comments