55
55
//! ported to this system, and which relies on string concatenation at the
56
56
//! time of error detection.
57
57
58
- use infer:: { self , SuppressRegionErrors } ;
59
- use super :: { InferCtxt , RegionVariableOrigin , SubregionOrigin , TypeTrace , ValuePairs } ;
60
- use super :: region_constraints:: GenericKind ;
61
58
use super :: lexical_region_resolve:: RegionResolutionError ;
59
+ use super :: region_constraints:: GenericKind ;
60
+ use super :: { InferCtxt , RegionVariableOrigin , SubregionOrigin , TypeTrace , ValuePairs } ;
61
+ use infer:: { self , SuppressRegionErrors } ;
62
62
63
- use std :: { cmp , fmt } ;
63
+ use errors :: { Applicability , DiagnosticBuilder , DiagnosticStyledString } ;
64
64
use hir;
65
- use hir:: Node ;
66
65
use hir:: def_id:: DefId ;
66
+ use hir:: Node ;
67
67
use middle:: region;
68
- use traits:: { ObligationCause , ObligationCauseCode } ;
69
- use ty:: { self , subst:: Subst , Region , Ty , TyCtxt , TypeFoldable , TyKind } ;
70
- use ty:: error:: TypeError ;
68
+ use std:: { cmp, fmt} ;
71
69
use syntax:: ast:: DUMMY_NODE_ID ;
72
70
use syntax_pos:: { Pos , Span } ;
73
- use errors:: { Applicability , DiagnosticBuilder , DiagnosticStyledString } ;
71
+ use traits:: { ObligationCause , ObligationCauseCode } ;
72
+ use ty:: error:: TypeError ;
73
+ use ty:: { self , subst:: Subst , Region , Ty , TyCtxt , TyKind , TypeFoldable } ;
74
74
75
75
mod note;
76
76
@@ -152,8 +152,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
152
152
}
153
153
154
154
// We shouldn't encounter an error message with ReClosureBound.
155
- ty:: ReCanonical ( ..) |
156
- ty:: ReClosureBound ( ..) => {
155
+ ty:: ReCanonical ( ..) | ty:: ReClosureBound ( ..) => {
157
156
bug ! ( "encountered unexpected ReClosureBound: {:?}" , region, ) ;
158
157
}
159
158
} ;
@@ -175,9 +174,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
175
174
176
175
fn msg_span_from_free_region ( self , region : ty:: Region < ' tcx > ) -> ( String , Option < Span > ) {
177
176
match * region {
178
- ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
177
+ ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
179
178
self . msg_span_from_early_bound_and_free_regions ( region)
180
- } ,
179
+ }
181
180
ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , None ) ,
182
181
_ => bug ! ( "{:?}" , region) ,
183
182
}
@@ -196,25 +195,28 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
196
195
Some ( Node :: Item ( it) ) => Self :: item_scope_tag ( & it) ,
197
196
Some ( Node :: TraitItem ( it) ) => Self :: trait_item_scope_tag ( & it) ,
198
197
Some ( Node :: ImplItem ( it) ) => Self :: impl_item_scope_tag ( & it) ,
199
- _ => unreachable ! ( )
198
+ _ => unreachable ! ( ) ,
200
199
} ;
201
200
let ( prefix, span) = match * region {
202
201
ty:: ReEarlyBound ( ref br) => {
203
202
let mut sp = cm. def_span ( self . hir . span ( node) ) ;
204
- if let Some ( param) = self . hir . get_generics ( scope) . and_then ( |generics| {
205
- generics. get_named ( & br. name )
206
- } ) {
203
+ if let Some ( param) = self . hir
204
+ . get_generics ( scope)
205
+ . and_then ( |generics| generics. get_named ( & br. name ) )
206
+ {
207
207
sp = param. span ;
208
208
}
209
209
( format ! ( "the lifetime {} as defined on" , br. name) , sp)
210
210
}
211
211
ty:: ReFree ( ty:: FreeRegion {
212
- bound_region : ty:: BoundRegion :: BrNamed ( _, ref name) , ..
212
+ bound_region : ty:: BoundRegion :: BrNamed ( _, ref name) ,
213
+ ..
213
214
} ) => {
214
215
let mut sp = cm. def_span ( self . hir . span ( node) ) ;
215
- if let Some ( param) = self . hir . get_generics ( scope) . and_then ( |generics| {
216
- generics. get_named ( & name)
217
- } ) {
216
+ if let Some ( param) = self . hir
217
+ . get_generics ( scope)
218
+ . and_then ( |generics| generics. get_named ( & name) )
219
+ {
218
220
sp = param. span ;
219
221
}
220
222
( format ! ( "the lifetime {} as defined on" , name) , sp)
@@ -277,9 +279,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
277
279
fn impl_item_scope_tag ( item : & hir:: ImplItem ) -> & ' static str {
278
280
match item. node {
279
281
hir:: ImplItemKind :: Method ( ..) => "method body" ,
280
- hir:: ImplItemKind :: Const ( ..) |
281
- hir:: ImplItemKind :: Existential ( ..) |
282
- hir:: ImplItemKind :: Type ( ..) => "associated item" ,
282
+ hir:: ImplItemKind :: Const ( ..)
283
+ | hir:: ImplItemKind :: Existential ( ..)
284
+ | hir:: ImplItemKind :: Type ( ..) => "associated item" ,
283
285
}
284
286
}
285
287
@@ -299,7 +301,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
299
301
errors : & Vec < RegionResolutionError < ' tcx > > ,
300
302
suppress : SuppressRegionErrors ,
301
303
) {
302
- debug ! ( "report_region_errors(): {} errors to start, suppress = {:?}" , errors. len( ) , suppress) ;
304
+ debug ! (
305
+ "report_region_errors(): {} errors to start, suppress = {:?}" ,
306
+ errors. len( ) ,
307
+ suppress
308
+ ) ;
303
309
304
310
if suppress. suppressed ( ) {
305
311
return ;
@@ -473,17 +479,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
473
479
} else {
474
480
err. span_label ( arm_span, msg) ;
475
481
}
476
- } ,
477
- hir:: MatchSource :: TryDesugar => { // Issue #51632
482
+ }
483
+ hir:: MatchSource :: TryDesugar => {
484
+ // Issue #51632
478
485
if let Ok ( try_snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( arm_span) {
479
486
err. span_suggestion_with_applicability (
480
487
arm_span,
481
488
"try wrapping with a success variant" ,
482
489
format ! ( "Ok({})" , try_snippet) ,
483
- Applicability :: MachineApplicable
490
+ Applicability :: MachineApplicable ,
484
491
) ;
485
492
}
486
- } ,
493
+ }
487
494
_ => {
488
495
let msg = "match arm with an incompatible type" ;
489
496
if self . tcx . sess . source_map ( ) . is_multiline ( arm_span) {
@@ -632,16 +639,21 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
632
639
fn strip_generic_default_params (
633
640
& self ,
634
641
def_id : DefId ,
635
- substs : & ty:: subst:: Substs < ' tcx >
642
+ substs : & ty:: subst:: Substs < ' tcx > ,
636
643
) -> & ' tcx ty:: subst:: Substs < ' tcx > {
637
644
let generics = self . tcx . generics_of ( def_id) ;
638
645
let mut num_supplied_defaults = 0 ;
639
- let mut type_params = generics. params . iter ( ) . rev ( ) . filter_map ( |param| match param. kind {
640
- ty:: GenericParamDefKind :: Lifetime => None ,
641
- ty:: GenericParamDefKind :: Type { has_default, .. } => {
642
- Some ( ( param. def_id , has_default) )
643
- }
644
- } ) . peekable ( ) ;
646
+ let mut type_params = generics
647
+ . params
648
+ . iter ( )
649
+ . rev ( )
650
+ . filter_map ( |param| match param. kind {
651
+ ty:: GenericParamDefKind :: Lifetime => None ,
652
+ ty:: GenericParamDefKind :: Type { has_default, .. } => {
653
+ Some ( ( param. def_id , has_default) )
654
+ }
655
+ } )
656
+ . peekable ( ) ;
645
657
let has_default = {
646
658
let has_default = type_params. peek ( ) . map ( |( _, has_default) | has_default) ;
647
659
* has_default. unwrap_or ( & false )
@@ -675,10 +687,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
675
687
| ( & ty:: Infer ( ty:: InferTy :: IntVar ( _) ) , & ty:: Infer ( ty:: InferTy :: IntVar ( _) ) )
676
688
| ( & ty:: Float ( _) , & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) )
677
689
| ( & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) , & ty:: Float ( _) )
678
- | (
679
- & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) ,
680
- & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) ,
681
- ) => true ,
690
+ | ( & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) , & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) ) => {
691
+ true
692
+ }
682
693
_ => false ,
683
694
}
684
695
}
@@ -694,11 +705,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
694
705
"&{}{}{}" ,
695
706
r,
696
707
if r == "" { "" } else { " " } ,
697
- if mutbl == hir:: MutMutable {
698
- "mut "
699
- } else {
700
- ""
701
- }
708
+ if mutbl == hir:: MutMutable { "mut " } else { "" }
702
709
) ) ;
703
710
s. push_normal ( ty. to_string ( ) ) ;
704
711
}
@@ -729,9 +736,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
729
736
let common_len = cmp:: min ( len1, len2) ;
730
737
let remainder1: Vec < _ > = sub1. types ( ) . skip ( common_len) . collect ( ) ;
731
738
let remainder2: Vec < _ > = sub2. types ( ) . skip ( common_len) . collect ( ) ;
732
- let common_default_params =
733
- remainder1. iter ( ) . rev ( ) . zip ( remainder2. iter ( ) . rev ( ) )
734
- . filter ( |( a, b) | a == b) . count ( ) ;
739
+ let common_default_params = remainder1
740
+ . iter ( )
741
+ . rev ( )
742
+ . zip ( remainder2. iter ( ) . rev ( ) )
743
+ . filter ( |( a, b) | a == b)
744
+ . count ( ) ;
735
745
let len = sub1. len ( ) - common_default_params;
736
746
737
747
// Only draw `<...>` if there're lifetime/type arguments.
@@ -857,8 +867,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
857
867
}
858
868
859
869
// When encountering &T != &mut T, highlight only the borrow
860
- ( & ty:: Ref ( r1, ref_ty1, mutbl1) ,
861
- & ty:: Ref ( r2, ref_ty2, mutbl2) ) if equals ( & ref_ty1, & ref_ty2) => {
870
+ ( & ty:: Ref ( r1, ref_ty1, mutbl1) , & ty:: Ref ( r2, ref_ty2, mutbl2) )
871
+ if equals ( & ref_ty1, & ref_ty2) =>
872
+ {
862
873
let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
863
874
push_ty_ref ( & r1, ref_ty1, mutbl1, & mut values. 0 ) ;
864
875
push_ty_ref ( & r2, ref_ty2, mutbl2, & mut values. 1 ) ;
@@ -1059,11 +1070,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1059
1070
bound_kind : GenericKind < ' tcx > ,
1060
1071
sub : Region < ' tcx > ,
1061
1072
) {
1062
- self . construct_generic_bound_failure ( region_scope_tree,
1063
- span,
1064
- origin,
1065
- bound_kind,
1066
- sub)
1073
+ self . construct_generic_bound_failure ( region_scope_tree, span, origin, bound_kind, sub)
1067
1074
. emit ( )
1068
1075
}
1069
1076
@@ -1074,8 +1081,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1074
1081
origin : Option < SubregionOrigin < ' tcx > > ,
1075
1082
bound_kind : GenericKind < ' tcx > ,
1076
1083
sub : Region < ' tcx > ,
1077
- ) -> DiagnosticBuilder < ' a >
1078
- {
1084
+ ) -> DiagnosticBuilder < ' a > {
1079
1085
// Attempt to obtain the span of the parameter so we can
1080
1086
// suggest adding an explicit lifetime bound to it.
1081
1087
let type_param_span = match ( self . in_progress_tables , bound_kind) {
@@ -1152,8 +1158,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1152
1158
let tail = if has_lifetimes { " + " } else { "" } ;
1153
1159
let suggestion = format ! ( "{}: {}{}" , bound_kind, sub, tail) ;
1154
1160
err. span_suggestion_short_with_applicability (
1155
- sp, consider, suggestion,
1156
- Applicability :: MaybeIncorrect // Issue #41966
1161
+ sp,
1162
+ consider,
1163
+ suggestion,
1164
+ Applicability :: MaybeIncorrect , // Issue #41966
1157
1165
) ;
1158
1166
} else {
1159
1167
err. help ( consider) ;
@@ -1349,12 +1357,10 @@ impl<'tcx> ObligationCause<'tcx> {
1349
1357
match self . code {
1350
1358
CompareImplMethodObligation { .. } => Error0308 ( "method not compatible with trait" ) ,
1351
1359
MatchExpressionArm { source, .. } => Error0308 ( match source {
1352
- hir:: MatchSource :: IfLetDesugar { .. } => {
1353
- "`if let` arms have incompatible types"
1354
- } ,
1360
+ hir:: MatchSource :: IfLetDesugar { .. } => "`if let` arms have incompatible types" ,
1355
1361
hir:: MatchSource :: TryDesugar => {
1356
1362
"try expression alternatives have incompatible types"
1357
- } ,
1363
+ }
1358
1364
_ => "match arms have incompatible types" ,
1359
1365
} ) ,
1360
1366
IfExpression => Error0308 ( "if and else have incompatible types" ) ,
0 commit comments