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;
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 ;
71
- use session:: config:: BorrowckMode ;
68
+ use std:: { cmp, fmt} ;
72
69
use syntax:: ast:: DUMMY_NODE_ID ;
73
70
use syntax_pos:: { Pos , Span } ;
74
- 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 } ;
75
74
76
75
mod note;
77
76
@@ -153,8 +152,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
153
152
}
154
153
155
154
// We shouldn't encounter an error message with ReClosureBound.
156
- ty:: ReCanonical ( ..) |
157
- ty:: ReClosureBound ( ..) => {
155
+ ty:: ReCanonical ( ..) | ty:: ReClosureBound ( ..) => {
158
156
bug ! ( "encountered unexpected ReClosureBound: {:?}" , region, ) ;
159
157
}
160
158
} ;
@@ -176,9 +174,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
176
174
177
175
fn msg_span_from_free_region ( self , region : ty:: Region < ' tcx > ) -> ( String , Option < Span > ) {
178
176
match * region {
179
- ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
177
+ ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
180
178
self . msg_span_from_early_bound_and_free_regions ( region)
181
- } ,
179
+ }
182
180
ty:: ReStatic => ( "the static lifetime" . to_owned ( ) , None ) ,
183
181
_ => bug ! ( "{:?}" , region) ,
184
182
}
@@ -197,25 +195,28 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
197
195
Some ( Node :: Item ( it) ) => Self :: item_scope_tag ( & it) ,
198
196
Some ( Node :: TraitItem ( it) ) => Self :: trait_item_scope_tag ( & it) ,
199
197
Some ( Node :: ImplItem ( it) ) => Self :: impl_item_scope_tag ( & it) ,
200
- _ => unreachable ! ( )
198
+ _ => unreachable ! ( ) ,
201
199
} ;
202
200
let ( prefix, span) = match * region {
203
201
ty:: ReEarlyBound ( ref br) => {
204
202
let mut sp = cm. def_span ( self . hir . span ( node) ) ;
205
- if let Some ( param) = self . hir . get_generics ( scope) . and_then ( |generics| {
206
- generics. get_named ( & br. name )
207
- } ) {
203
+ if let Some ( param) = self . hir
204
+ . get_generics ( scope)
205
+ . and_then ( |generics| generics. get_named ( & br. name ) )
206
+ {
208
207
sp = param. span ;
209
208
}
210
209
( format ! ( "the lifetime {} as defined on" , br. name) , sp)
211
210
}
212
211
ty:: ReFree ( ty:: FreeRegion {
213
- bound_region : ty:: BoundRegion :: BrNamed ( _, ref name) , ..
212
+ bound_region : ty:: BoundRegion :: BrNamed ( _, ref name) ,
213
+ ..
214
214
} ) => {
215
215
let mut sp = cm. def_span ( self . hir . span ( node) ) ;
216
- if let Some ( param) = self . hir . get_generics ( scope) . and_then ( |generics| {
217
- generics. get_named ( & name)
218
- } ) {
216
+ if let Some ( param) = self . hir
217
+ . get_generics ( scope)
218
+ . and_then ( |generics| generics. get_named ( & name) )
219
+ {
219
220
sp = param. span ;
220
221
}
221
222
( format ! ( "the lifetime {} as defined on" , name) , sp)
@@ -278,9 +279,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
278
279
fn impl_item_scope_tag ( item : & hir:: ImplItem ) -> & ' static str {
279
280
match item. node {
280
281
hir:: ImplItemKind :: Method ( ..) => "method body" ,
281
- hir:: ImplItemKind :: Const ( ..) |
282
- hir:: ImplItemKind :: Existential ( ..) |
283
- hir:: ImplItemKind :: Type ( ..) => "associated item" ,
282
+ hir:: ImplItemKind :: Const ( ..)
283
+ | hir:: ImplItemKind :: Existential ( ..)
284
+ | hir:: ImplItemKind :: Type ( ..) => "associated item" ,
284
285
}
285
286
}
286
287
@@ -298,20 +299,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
298
299
& self ,
299
300
region_scope_tree : & region:: ScopeTree ,
300
301
errors : & Vec < RegionResolutionError < ' tcx > > ,
301
- will_later_be_reported_by_nll : bool ,
302
+ suppress : SuppressRegionErrors ,
302
303
) {
303
- debug ! ( "report_region_errors(): {} errors to start" , errors. len( ) ) ;
304
-
305
- // If the errors will later be reported by NLL, choose wether to display them or not based
306
- // on the borrowck mode
307
- if will_later_be_reported_by_nll {
308
- match self . tcx . borrowck_mode ( ) {
309
- // If we're on AST or Migrate mode, report AST region errors
310
- BorrowckMode :: Ast | BorrowckMode :: Migrate => { } ,
311
- // If we're on MIR or Compare mode, don't report AST region errors as they should
312
- // be reported by NLL
313
- BorrowckMode :: Compare | BorrowckMode :: Mir => return ,
314
- }
304
+ debug ! (
305
+ "report_region_errors(): {} errors to start, suppress = {:?}" ,
306
+ errors. len( ) ,
307
+ suppress
308
+ ) ;
309
+
310
+ if suppress. suppressed ( ) {
311
+ return ;
315
312
}
316
313
317
314
// try to pre-process the errors, which will group some of them
@@ -482,17 +479,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
482
479
} else {
483
480
err. span_label ( arm_span, msg) ;
484
481
}
485
- } ,
486
- hir:: MatchSource :: TryDesugar => { // Issue #51632
482
+ }
483
+ hir:: MatchSource :: TryDesugar => {
484
+ // Issue #51632
487
485
if let Ok ( try_snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( arm_span) {
488
486
err. span_suggestion_with_applicability (
489
487
arm_span,
490
488
"try wrapping with a success variant" ,
491
489
format ! ( "Ok({})" , try_snippet) ,
492
- Applicability :: MachineApplicable
490
+ Applicability :: MachineApplicable ,
493
491
) ;
494
492
}
495
- } ,
493
+ }
496
494
_ => {
497
495
let msg = "match arm with an incompatible type" ;
498
496
if self . tcx . sess . source_map ( ) . is_multiline ( arm_span) {
@@ -641,16 +639,21 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
641
639
fn strip_generic_default_params (
642
640
& self ,
643
641
def_id : DefId ,
644
- substs : & ty:: subst:: Substs < ' tcx >
642
+ substs : & ty:: subst:: Substs < ' tcx > ,
645
643
) -> & ' tcx ty:: subst:: Substs < ' tcx > {
646
644
let generics = self . tcx . generics_of ( def_id) ;
647
645
let mut num_supplied_defaults = 0 ;
648
- let mut type_params = generics. params . iter ( ) . rev ( ) . filter_map ( |param| match param. kind {
649
- ty:: GenericParamDefKind :: Lifetime => None ,
650
- ty:: GenericParamDefKind :: Type { has_default, .. } => {
651
- Some ( ( param. def_id , has_default) )
652
- }
653
- } ) . 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 ( ) ;
654
657
let has_default = {
655
658
let has_default = type_params. peek ( ) . map ( |( _, has_default) | has_default) ;
656
659
* has_default. unwrap_or ( & false )
@@ -684,10 +687,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
684
687
| ( & ty:: Infer ( ty:: InferTy :: IntVar ( _) ) , & ty:: Infer ( ty:: InferTy :: IntVar ( _) ) )
685
688
| ( & ty:: Float ( _) , & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) )
686
689
| ( & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) , & ty:: Float ( _) )
687
- | (
688
- & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) ,
689
- & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) ,
690
- ) => true ,
690
+ | ( & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) , & ty:: Infer ( ty:: InferTy :: FloatVar ( _) ) ) => {
691
+ true
692
+ }
691
693
_ => false ,
692
694
}
693
695
}
@@ -703,11 +705,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
703
705
"&{}{}{}" ,
704
706
r,
705
707
if r == "" { "" } else { " " } ,
706
- if mutbl == hir:: MutMutable {
707
- "mut "
708
- } else {
709
- ""
710
- }
708
+ if mutbl == hir:: MutMutable { "mut " } else { "" }
711
709
) ) ;
712
710
s. push_normal ( ty. to_string ( ) ) ;
713
711
}
@@ -738,9 +736,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
738
736
let common_len = cmp:: min ( len1, len2) ;
739
737
let remainder1: Vec < _ > = sub1. types ( ) . skip ( common_len) . collect ( ) ;
740
738
let remainder2: Vec < _ > = sub2. types ( ) . skip ( common_len) . collect ( ) ;
741
- let common_default_params =
742
- remainder1. iter ( ) . rev ( ) . zip ( remainder2. iter ( ) . rev ( ) )
743
- . 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 ( ) ;
744
745
let len = sub1. len ( ) - common_default_params;
745
746
746
747
// Only draw `<...>` if there're lifetime/type arguments.
@@ -866,8 +867,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
866
867
}
867
868
868
869
// When encountering &T != &mut T, highlight only the borrow
869
- ( & ty:: Ref ( r1, ref_ty1, mutbl1) ,
870
- & 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
+ {
871
873
let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
872
874
push_ty_ref ( & r1, ref_ty1, mutbl1, & mut values. 0 ) ;
873
875
push_ty_ref ( & r2, ref_ty2, mutbl2, & mut values. 1 ) ;
@@ -1068,11 +1070,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1068
1070
bound_kind : GenericKind < ' tcx > ,
1069
1071
sub : Region < ' tcx > ,
1070
1072
) {
1071
- self . construct_generic_bound_failure ( region_scope_tree,
1072
- span,
1073
- origin,
1074
- bound_kind,
1075
- sub)
1073
+ self . construct_generic_bound_failure ( region_scope_tree, span, origin, bound_kind, sub)
1076
1074
. emit ( )
1077
1075
}
1078
1076
@@ -1083,8 +1081,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1083
1081
origin : Option < SubregionOrigin < ' tcx > > ,
1084
1082
bound_kind : GenericKind < ' tcx > ,
1085
1083
sub : Region < ' tcx > ,
1086
- ) -> DiagnosticBuilder < ' a >
1087
- {
1084
+ ) -> DiagnosticBuilder < ' a > {
1088
1085
// Attempt to obtain the span of the parameter so we can
1089
1086
// suggest adding an explicit lifetime bound to it.
1090
1087
let type_param_span = match ( self . in_progress_tables , bound_kind) {
@@ -1161,8 +1158,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1161
1158
let tail = if has_lifetimes { " + " } else { "" } ;
1162
1159
let suggestion = format ! ( "{}: {}{}" , bound_kind, sub, tail) ;
1163
1160
err. span_suggestion_short_with_applicability (
1164
- sp, consider, suggestion,
1165
- Applicability :: MaybeIncorrect // Issue #41966
1161
+ sp,
1162
+ consider,
1163
+ suggestion,
1164
+ Applicability :: MaybeIncorrect , // Issue #41966
1166
1165
) ;
1167
1166
} else {
1168
1167
err. help ( consider) ;
@@ -1358,12 +1357,10 @@ impl<'tcx> ObligationCause<'tcx> {
1358
1357
match self . code {
1359
1358
CompareImplMethodObligation { .. } => Error0308 ( "method not compatible with trait" ) ,
1360
1359
MatchExpressionArm { source, .. } => Error0308 ( match source {
1361
- hir:: MatchSource :: IfLetDesugar { .. } => {
1362
- "`if let` arms have incompatible types"
1363
- } ,
1360
+ hir:: MatchSource :: IfLetDesugar { .. } => "`if let` arms have incompatible types" ,
1364
1361
hir:: MatchSource :: TryDesugar => {
1365
1362
"try expression alternatives have incompatible types"
1366
- } ,
1363
+ }
1367
1364
_ => "match arms have incompatible types" ,
1368
1365
} ) ,
1369
1366
IfExpression => Error0308 ( "if and else have incompatible types" ) ,
0 commit comments