@@ -4,7 +4,6 @@ use rustc_errors::{self, AddToDiagnostic, Diagnostic, IntoDiagnosticArg, Subdiag
44use rustc_middle:: ty:: { self , TyCtxt } ;
55use rustc_span:: { symbol:: kw, Span } ;
66
7- #[ derive( Default ) ]
87struct DescriptionCtx < ' a > {
98 span : Option < Span > ,
109 kind : & ' a str ,
@@ -17,96 +16,74 @@ impl<'a> DescriptionCtx<'a> {
1716 region : ty:: Region < ' tcx > ,
1817 alt_span : Option < Span > ,
1918 ) -> Option < Self > {
20- let mut me = DescriptionCtx :: default ( ) ;
21- me. span = alt_span;
22- match * region {
23- ty:: ReEarlyBound ( _) | ty:: ReFree ( _) => {
24- return Self :: from_early_bound_and_free_regions ( tcx, region) ;
25- }
26- ty:: ReStatic => {
27- me. kind = "restatic" ;
28- }
29-
30- ty:: RePlaceholder ( _) => return None ,
31-
32- ty:: ReError ( _) => return None ,
33-
34- // FIXME(#13998) RePlaceholder should probably print like
35- // ReFree rather than dumping Debug output on the user.
36- //
37- // We shouldn't really be having unification failures with ReVar
38- // and ReLateBound though.
39- ty:: ReVar ( _) | ty:: ReLateBound ( ..) | ty:: ReErased => {
40- me. kind = "revar" ;
41- me. arg = format ! ( "{:?}" , region) ;
42- }
43- } ;
44- Some ( me)
45- }
46-
47- fn from_early_bound_and_free_regions < ' tcx > (
48- tcx : TyCtxt < ' tcx > ,
49- region : ty:: Region < ' tcx > ,
50- ) -> Option < Self > {
51- let mut me = DescriptionCtx :: default ( ) ;
52- let scope = region. free_region_binding_scope ( tcx) . expect_local ( ) ;
53- match * region {
19+ let ( span, kind, arg) = match * region {
5420 ty:: ReEarlyBound ( ref br) => {
55- let mut sp = tcx. def_span ( scope ) ;
56- if let Some ( param) =
21+ let scope = region . free_region_binding_scope ( tcx) . expect_local ( ) ;
22+ let span = if let Some ( param) =
5723 tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( br. name ) )
5824 {
59- sp = param. span ;
60- }
61- if br. has_name ( ) {
62- me. kind = "as_defined" ;
63- me. arg = br. name . to_string ( ) ;
25+ param. span
6426 } else {
65- me . kind = "as_defined_anon" ;
27+ tcx . def_span ( scope )
6628 } ;
67- me. span = Some ( sp)
29+ if br. has_name ( ) {
30+ ( Some ( span) , "as_defined" , br. name . to_string ( ) )
31+ } else {
32+ ( Some ( span) , "as_defined_anon" , String :: new ( ) )
33+ }
6834 }
6935 ty:: ReFree ( ref fr) => {
7036 if !fr. bound_region . is_named ( )
7137 && let Some ( ( ty, _) ) = find_anon_type ( tcx, region, & fr. bound_region )
7238 {
73- me. kind = "defined_here" ;
74- me. span = Some ( ty. span ) ;
39+ ( Some ( ty. span ) , "defined_here" , String :: new ( ) )
7540 } else {
41+ let scope = region. free_region_binding_scope ( tcx) . expect_local ( ) ;
7642 match fr. bound_region {
7743 ty:: BoundRegionKind :: BrNamed ( _, name) => {
78- let mut sp = tcx. def_span ( scope) ;
79- if let Some ( param) =
80- tcx. hir ( ) . get_generics ( scope) . and_then ( |generics| generics. get_named ( name) )
44+ let span = if let Some ( param) = tcx
45+ . hir ( )
46+ . get_generics ( scope)
47+ . and_then ( |generics| generics. get_named ( name) )
8148 {
82- sp = param. span ;
83- }
84- if name == kw:: UnderscoreLifetime {
85- me. kind = "as_defined_anon" ;
49+ param. span
8650 } else {
87- me. kind = "as_defined" ;
88- me. arg = name. to_string ( ) ;
51+ tcx. def_span ( scope)
8952 } ;
90- me. span = Some ( sp) ;
53+ if name == kw:: UnderscoreLifetime {
54+ ( Some ( span) , "as_defined_anon" , String :: new ( ) )
55+ } else {
56+ ( Some ( span) , "as_defined" , name. to_string ( ) )
57+ }
9158 }
9259 ty:: BrAnon ( span) => {
93- me. kind = "defined_here" ;
94- me. span = match span {
60+ let span = match span {
9561 Some ( _) => span,
9662 None => Some ( tcx. def_span ( scope) ) ,
97- }
98- } ,
63+ } ;
64+ ( span, "defined_here" , String :: new ( ) )
65+ }
9966 _ => {
100- me. kind = "defined_here_reg" ;
101- me. arg = region. to_string ( ) ;
102- me. span = Some ( tcx. def_span ( scope) ) ;
103- } ,
67+ ( Some ( tcx. def_span ( scope) ) , "defined_here_reg" , region. to_string ( ) )
68+ }
10469 }
10570 }
10671 }
107- _ => bug ! ( ) ,
108- }
109- Some ( me)
72+
73+ ty:: ReStatic => ( alt_span, "restatic" , String :: new ( ) ) ,
74+
75+ ty:: RePlaceholder ( _) | ty:: ReError ( _) => return None ,
76+
77+ // FIXME(#13998) RePlaceholder should probably print like
78+ // ReFree rather than dumping Debug output on the user.
79+ //
80+ // We shouldn't really be having unification failures with ReVar
81+ // and ReLateBound though.
82+ ty:: ReVar ( _) | ty:: ReLateBound ( ..) | ty:: ReErased => {
83+ ( alt_span, "revar" , format ! ( "{:?}" , region) )
84+ }
85+ } ;
86+ Some ( DescriptionCtx { span, kind, arg } )
11087 }
11188}
11289
0 commit comments