@@ -61,7 +61,6 @@ use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6161use rustc_hir as hir;
6262use rustc_hir:: def_id:: DefId ;
6363use rustc_hir:: Node ;
64- use rustc_middle:: middle:: region;
6564use rustc_middle:: ty:: error:: TypeError ;
6665use rustc_middle:: ty:: {
6766 self ,
@@ -81,58 +80,12 @@ pub mod nice_region_error;
8180
8281pub ( super ) fn note_and_explain_region (
8382 tcx : TyCtxt < ' tcx > ,
84- region_scope_tree : & region:: ScopeTree ,
8583 err : & mut DiagnosticBuilder < ' _ > ,
8684 prefix : & str ,
8785 region : ty:: Region < ' tcx > ,
8886 suffix : & str ,
8987) {
9088 let ( description, span) = match * region {
91- ty:: ReScope ( scope) => {
92- let new_string;
93- let unknown_scope =
94- || format ! ( "{}unknown scope: {:?}{}. Please report a bug." , prefix, scope, suffix) ;
95- let span = scope. span ( tcx, region_scope_tree) ;
96- let hir_id = scope. hir_id ( region_scope_tree) ;
97- let tag = match hir_id. and_then ( |hir_id| tcx. hir ( ) . find ( hir_id) ) {
98- Some ( Node :: Block ( _) ) => "block" ,
99- Some ( Node :: Expr ( expr) ) => match expr. kind {
100- hir:: ExprKind :: Call ( ..) => "call" ,
101- hir:: ExprKind :: MethodCall ( ..) => "method call" ,
102- hir:: ExprKind :: Match ( .., hir:: MatchSource :: IfLetDesugar { .. } ) => "if let" ,
103- hir:: ExprKind :: Match ( .., hir:: MatchSource :: WhileLetDesugar ) => "while let" ,
104- hir:: ExprKind :: Match ( .., hir:: MatchSource :: ForLoopDesugar ) => "for" ,
105- hir:: ExprKind :: Match ( ..) => "match" ,
106- _ => "expression" ,
107- } ,
108- Some ( Node :: Stmt ( _) ) => "statement" ,
109- Some ( Node :: Item ( it) ) => item_scope_tag ( & it) ,
110- Some ( Node :: TraitItem ( it) ) => trait_item_scope_tag ( & it) ,
111- Some ( Node :: ImplItem ( it) ) => impl_item_scope_tag ( & it) ,
112- Some ( _) | None => {
113- err. span_note ( span, & unknown_scope ( ) ) ;
114- return ;
115- }
116- } ;
117- let scope_decorated_tag = match scope. data {
118- region:: ScopeData :: Node => tag,
119- region:: ScopeData :: CallSite => "scope of call-site for function" ,
120- region:: ScopeData :: Arguments => "scope of function body" ,
121- region:: ScopeData :: Destruction => {
122- new_string = format ! ( "destruction scope surrounding {}" , tag) ;
123- & new_string[ ..]
124- }
125- region:: ScopeData :: Remainder ( first_statement_index) => {
126- new_string = format ! (
127- "block suffix following statement {}" ,
128- first_statement_index. index( )
129- ) ;
130- & new_string[ ..]
131- }
132- } ;
133- explain_span ( tcx, scope_decorated_tag, span)
134- }
135-
13689 ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic => {
13790 msg_span_from_free_region ( tcx, region)
13891 }
@@ -284,7 +237,6 @@ fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option
284237
285238pub fn unexpected_hidden_region_diagnostic (
286239 tcx : TyCtxt < ' tcx > ,
287- region_scope_tree : Option < & region:: ScopeTree > ,
288240 span : Span ,
289241 hidden_ty : Ty < ' tcx > ,
290242 hidden_region : ty:: Region < ' tcx > ,
@@ -297,64 +249,56 @@ pub fn unexpected_hidden_region_diagnostic(
297249 ) ;
298250
299251 // Explain the region we are capturing.
300- if let ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic | ty:: ReEmpty ( _) = hidden_region {
301- // Assuming regionck succeeded (*), we ought to always be
302- // capturing *some* region from the fn header, and hence it
303- // ought to be free. So under normal circumstances, we will go
304- // down this path which gives a decent human readable
305- // explanation.
306- //
307- // (*) if not, the `tainted_by_errors` field would be set to
308- // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
309- note_and_explain_free_region (
310- tcx,
311- & mut err,
312- & format ! ( "hidden type `{}` captures " , hidden_ty) ,
313- hidden_region,
314- "" ,
315- ) ;
316- } else {
317- // Ugh. This is a painful case: the hidden region is not one
318- // that we can easily summarize or explain. This can happen
319- // in a case like
320- // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
321- //
322- // ```
323- // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
324- // if condition() { a } else { b }
325- // }
326- // ```
327- //
328- // Here the captured lifetime is the intersection of `'a` and
329- // `'b`, which we can't quite express.
330-
331- if let Some ( region_scope_tree) = region_scope_tree {
332- // If the `region_scope_tree` is available, this is being
333- // invoked from the "region inferencer error". We can at
334- // least report a really cryptic error for now.
335- note_and_explain_region (
252+ match hidden_region {
253+ ty:: ReEmpty ( ty:: UniverseIndex :: ROOT ) => {
254+ // All lifetimes shorter than the function body are `empty` in
255+ // lexical region resolution. The default explanation of "an empty
256+ // lifetime" isn't really accurate here.
257+ let message = format ! (
258+ "hidden type `{}` captures lifetime smaller than the function body" ,
259+ hidden_ty
260+ ) ;
261+ err. span_note ( span, & message) ;
262+ }
263+ ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic | ty:: ReEmpty ( _) => {
264+ // Assuming regionck succeeded (*), we ought to always be
265+ // capturing *some* region from the fn header, and hence it
266+ // ought to be free. So under normal circumstances, we will go
267+ // down this path which gives a decent human readable
268+ // explanation.
269+ //
270+ // (*) if not, the `tainted_by_errors` field would be set to
271+ // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
272+ note_and_explain_free_region (
336273 tcx,
337- region_scope_tree,
338274 & mut err,
339275 & format ! ( "hidden type `{}` captures " , hidden_ty) ,
340276 hidden_region,
341277 "" ,
342278 ) ;
343- } else {
344- // If the `region_scope_tree` is *unavailable*, this is
345- // being invoked by the code that comes *after* region
346- // inferencing. This is a bug, as the region inferencer
347- // ought to have noticed the failed constraint and invoked
348- // error reporting, which in turn should have prevented us
349- // from getting trying to infer the hidden type
350- // completely.
351- tcx. sess . delay_span_bug (
352- span,
353- & format ! (
354- "hidden type captures unexpected lifetime `{:?}` \
355- but no region inference failure",
356- hidden_region,
357- ) ,
279+ }
280+ _ => {
281+ // Ugh. This is a painful case: the hidden region is not one
282+ // that we can easily summarize or explain. This can happen
283+ // in a case like
284+ // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
285+ //
286+ // ```
287+ // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
288+ // if condition() { a } else { b }
289+ // }
290+ // ```
291+ //
292+ // Here the captured lifetime is the intersection of `'a` and
293+ // `'b`, which we can't quite express.
294+
295+ // We can at least report a really cryptic error for now.
296+ note_and_explain_region (
297+ tcx,
298+ & mut err,
299+ & format ! ( "hidden type `{}` captures " , hidden_ty) ,
300+ hidden_region,
301+ "" ,
358302 ) ;
359303 }
360304 }
@@ -363,11 +307,7 @@ pub fn unexpected_hidden_region_diagnostic(
363307}
364308
365309impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
366- pub fn report_region_errors (
367- & self ,
368- region_scope_tree : & region:: ScopeTree ,
369- errors : & Vec < RegionResolutionError < ' tcx > > ,
370- ) {
310+ pub fn report_region_errors ( & self , errors : & Vec < RegionResolutionError < ' tcx > > ) {
371311 debug ! ( "report_region_errors(): {} errors to start" , errors. len( ) ) ;
372312
373313 // try to pre-process the errors, which will group some of them
@@ -390,17 +330,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
390330 // general bit of code that displays the error information
391331 RegionResolutionError :: ConcreteFailure ( origin, sub, sup) => {
392332 if sub. is_placeholder ( ) || sup. is_placeholder ( ) {
393- self . report_placeholder_failure ( region_scope_tree, origin, sub, sup)
394- . emit ( ) ;
333+ self . report_placeholder_failure ( origin, sub, sup) . emit ( ) ;
395334 } else {
396- self . report_concrete_failure ( region_scope_tree, origin, sub, sup)
397- . emit ( ) ;
335+ self . report_concrete_failure ( origin, sub, sup) . emit ( ) ;
398336 }
399337 }
400338
401339 RegionResolutionError :: GenericBoundFailure ( origin, param_ty, sub) => {
402340 self . report_generic_bound_failure (
403- region_scope_tree,
404341 origin. span ( ) ,
405342 Some ( origin) ,
406343 param_ty,
@@ -417,29 +354,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
417354 sup_r,
418355 ) => {
419356 if sub_r. is_placeholder ( ) {
420- self . report_placeholder_failure (
421- region_scope_tree,
422- sub_origin,
423- sub_r,
424- sup_r,
425- )
426- . emit ( ) ;
357+ self . report_placeholder_failure ( sub_origin, sub_r, sup_r) . emit ( ) ;
427358 } else if sup_r. is_placeholder ( ) {
428- self . report_placeholder_failure (
429- region_scope_tree,
430- sup_origin,
431- sub_r,
432- sup_r,
433- )
434- . emit ( ) ;
359+ self . report_placeholder_failure ( sup_origin, sub_r, sup_r) . emit ( ) ;
435360 } else {
436361 self . report_sub_sup_conflict (
437- region_scope_tree,
438- var_origin,
439- sub_origin,
440- sub_r,
441- sup_origin,
442- sup_r,
362+ var_origin, sub_origin, sub_r, sup_origin, sup_r,
443363 ) ;
444364 }
445365 }
@@ -460,13 +380,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
460380 // value.
461381 let sub_r = self . tcx . mk_region ( ty:: ReEmpty ( var_universe) ) ;
462382
463- self . report_placeholder_failure (
464- region_scope_tree,
465- sup_origin,
466- sub_r,
467- sup_r,
468- )
469- . emit ( ) ;
383+ self . report_placeholder_failure ( sup_origin, sub_r, sup_r) . emit ( ) ;
470384 }
471385
472386 RegionResolutionError :: MemberConstraintFailure {
@@ -477,7 +391,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
477391 let hidden_ty = self . resolve_vars_if_possible ( & hidden_ty) ;
478392 unexpected_hidden_region_diagnostic (
479393 self . tcx ,
480- Some ( region_scope_tree) ,
481394 span,
482395 hidden_ty,
483396 member_region,
@@ -1754,19 +1667,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17541667
17551668 pub fn report_generic_bound_failure (
17561669 & self ,
1757- region_scope_tree : & region:: ScopeTree ,
17581670 span : Span ,
17591671 origin : Option < SubregionOrigin < ' tcx > > ,
17601672 bound_kind : GenericKind < ' tcx > ,
17611673 sub : Region < ' tcx > ,
17621674 ) {
1763- self . construct_generic_bound_failure ( region_scope_tree, span, origin, bound_kind, sub)
1764- . emit ( ) ;
1675+ self . construct_generic_bound_failure ( span, origin, bound_kind, sub) . emit ( ) ;
17651676 }
17661677
17671678 pub fn construct_generic_bound_failure (
17681679 & self ,
1769- region_scope_tree : & region:: ScopeTree ,
17701680 span : Span ,
17711681 origin : Option < SubregionOrigin < ' tcx > > ,
17721682 bound_kind : GenericKind < ' tcx > ,
@@ -1918,7 +1828,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19181828 ) ) ;
19191829 note_and_explain_region (
19201830 self . tcx ,
1921- region_scope_tree,
19221831 & mut err,
19231832 & format ! ( "{} must be valid for " , labeled_user_string) ,
19241833 sub,
@@ -1936,7 +1845,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19361845
19371846 fn report_sub_sup_conflict (
19381847 & self ,
1939- region_scope_tree : & region:: ScopeTree ,
19401848 var_origin : RegionVariableOrigin ,
19411849 sub_origin : SubregionOrigin < ' tcx > ,
19421850 sub_region : Region < ' tcx > ,
@@ -1947,7 +1855,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19471855
19481856 note_and_explain_region (
19491857 self . tcx ,
1950- region_scope_tree,
19511858 & mut err,
19521859 "first, the lifetime cannot outlive " ,
19531860 sup_region,
@@ -1973,7 +1880,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19731880 if sub_expected == sup_expected && sub_found == sup_found {
19741881 note_and_explain_region (
19751882 self . tcx ,
1976- region_scope_tree,
19771883 & mut err,
19781884 "...but the lifetime must also be valid for " ,
19791885 sub_region,
@@ -1995,7 +1901,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19951901
19961902 note_and_explain_region (
19971903 self . tcx ,
1998- region_scope_tree,
19991904 & mut err,
20001905 "but, the lifetime must be valid for " ,
20011906 sub_region,
0 commit comments