@@ -44,7 +44,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
44
44
#[ derive( Debug ) ]
45
45
pub enum GeneratorInteriorOrUpvar {
46
46
// span of interior type
47
- Interior ( Span ) ,
47
+ Interior ( Span , Option < ( Option < Span > , Span , Option < hir :: HirId > , Option < Span > ) > ) ,
48
48
// span of upvar
49
49
Upvar ( Span ) ,
50
50
}
@@ -283,7 +283,6 @@ pub trait TypeErrCtxtExt<'tcx> {
283
283
& self ,
284
284
err : & mut Diagnostic ,
285
285
interior_or_upvar_span : GeneratorInteriorOrUpvar ,
286
- interior_extra_info : Option < ( Option < Span > , Span , Option < hir:: HirId > , Option < Span > ) > ,
287
286
is_async : bool ,
288
287
outer_generator : Option < DefId > ,
289
288
trait_pred : ty:: TraitPredicate < ' tcx > ,
@@ -2003,17 +2002,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2003
2002
. as_local ( )
2004
2003
. and_then ( |def_id| hir. maybe_body_owned_by ( def_id) )
2005
2004
. map ( |body_id| hir. body ( body_id) ) ;
2006
- let is_async = match generator_did. as_local ( ) {
2007
- Some ( _) => generator_body
2008
- . and_then ( |body| body. generator_kind ( ) )
2009
- . map ( |generator_kind| matches ! ( generator_kind, hir:: GeneratorKind :: Async ( ..) ) )
2010
- . unwrap_or ( false ) ,
2011
- None => self
2012
- . tcx
2013
- . generator_kind ( generator_did)
2014
- . map ( |generator_kind| matches ! ( generator_kind, hir:: GeneratorKind :: Async ( ..) ) )
2015
- . unwrap_or ( false ) ,
2016
- } ;
2005
+ let is_async = self
2006
+ . tcx
2007
+ . generator_kind ( generator_did)
2008
+ . map ( |generator_kind| matches ! ( generator_kind, hir:: GeneratorKind :: Async ( ..) ) )
2009
+ . unwrap_or ( false ) ;
2017
2010
let mut visitor = AwaitsVisitor :: default ( ) ;
2018
2011
if let Some ( body) = generator_body {
2019
2012
visitor. visit_body ( body) ;
@@ -2043,61 +2036,60 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2043
2036
eq
2044
2037
} ;
2045
2038
2046
- let mut interior_or_upvar_span = None ;
2047
- let mut interior_extra_info = None ;
2048
-
2049
2039
// Get the typeck results from the infcx if the generator is the function we are currently
2050
2040
// type-checking; otherwise, get them by performing a query. This is needed to avoid
2051
2041
// cycles. If we can't use resolved types because the generator comes from another crate,
2052
2042
// we still provide a targeted error but without all the relevant spans.
2053
- let generator_data: Option < GeneratorData < ' tcx , ' _ > > = match & self . typeck_results {
2054
- Some ( t) if t. hir_owner . to_def_id ( ) == generator_did_root => {
2055
- Some ( GeneratorData :: Local ( & t) )
2056
- }
2043
+ let generator_data = match & self . typeck_results {
2044
+ Some ( t) if t. hir_owner . to_def_id ( ) == generator_did_root => GeneratorData :: Local ( & t) ,
2057
2045
_ if generator_did. is_local ( ) => {
2058
- Some ( GeneratorData :: Local ( self . tcx . typeck ( generator_did. expect_local ( ) ) ) )
2046
+ GeneratorData :: Local ( self . tcx . typeck ( generator_did. expect_local ( ) ) )
2059
2047
}
2060
- _ => self
2061
- . tcx
2062
- . generator_diagnostic_data ( generator_did)
2063
- . as_ref ( )
2064
- . map ( |generator_diag_data| GeneratorData :: Foreign ( generator_diag_data) ) ,
2048
+ _ if let Some ( generator_diag_data) = self . tcx . generator_diagnostic_data ( generator_did) => {
2049
+ GeneratorData :: Foreign ( generator_diag_data)
2050
+ }
2051
+ _ => return false ,
2065
2052
} ;
2066
2053
2067
- if let Some ( generator_data) = generator_data. as_ref ( ) {
2068
- interior_or_upvar_span =
2069
- generator_data. try_get_upvar_span ( & self , generator_did, ty_matches) ;
2054
+ let mut interior_or_upvar_span = None ;
2070
2055
2071
- // The generator interior types share the same binders
2072
- if let Some ( cause) =
2073
- generator_data. get_generator_interior_types ( ) . skip_binder ( ) . iter ( ) . find (
2074
- |ty:: GeneratorInteriorTypeCause { ty, .. } | {
2075
- ty_matches ( generator_data. get_generator_interior_types ( ) . rebind ( * ty) )
2076
- } ,
2077
- )
2078
- {
2079
- let from_awaited_ty = generator_data. get_from_await_ty ( visitor, hir, ty_matches) ;
2080
- let ty:: GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } =
2081
- cause;
2056
+ let from_awaited_ty = generator_data. get_from_await_ty ( visitor, hir, ty_matches) ;
2057
+ debug ! ( ?from_awaited_ty) ;
2082
2058
2083
- interior_or_upvar_span = Some ( GeneratorInteriorOrUpvar :: Interior ( * span) ) ;
2084
- interior_extra_info = Some ( ( * scope_span, * yield_span, * expr, from_awaited_ty) ) ;
2085
- }
2059
+ // The generator interior types share the same binders
2060
+ if let Some ( cause) =
2061
+ generator_data. get_generator_interior_types ( ) . skip_binder ( ) . iter ( ) . find (
2062
+ |ty:: GeneratorInteriorTypeCause { ty, .. } | {
2063
+ ty_matches ( generator_data. get_generator_interior_types ( ) . rebind ( * ty) )
2064
+ } ,
2065
+ )
2066
+ {
2067
+ let ty:: GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } = cause;
2086
2068
2087
- if interior_or_upvar_span. is_none ( ) && generator_data. is_foreign ( ) {
2088
- interior_or_upvar_span = Some ( GeneratorInteriorOrUpvar :: Interior ( span) ) ;
2089
- }
2069
+ interior_or_upvar_span = Some ( GeneratorInteriorOrUpvar :: Interior (
2070
+ * span,
2071
+ Some ( ( * scope_span, * yield_span, * expr, from_awaited_ty) ) ,
2072
+ ) ) ;
2090
2073
}
2091
2074
2075
+ if interior_or_upvar_span. is_none ( ) {
2076
+ interior_or_upvar_span =
2077
+ generator_data. try_get_upvar_span ( & self , generator_did, ty_matches) ;
2078
+ }
2079
+
2080
+ if interior_or_upvar_span. is_none ( ) && generator_data. is_foreign ( ) {
2081
+ interior_or_upvar_span = Some ( GeneratorInteriorOrUpvar :: Interior ( span, None ) ) ;
2082
+ }
2083
+
2084
+ debug ! ( ?interior_or_upvar_span) ;
2092
2085
if let Some ( interior_or_upvar_span) = interior_or_upvar_span {
2093
- let typeck_results = generator_data . and_then ( |generator_data| match generator_data {
2086
+ let typeck_results = match generator_data {
2094
2087
GeneratorData :: Local ( typeck_results) => Some ( typeck_results) ,
2095
2088
GeneratorData :: Foreign ( _) => None ,
2096
- } ) ;
2089
+ } ;
2097
2090
self . note_obligation_cause_for_async_await (
2098
2091
err,
2099
2092
interior_or_upvar_span,
2100
- interior_extra_info,
2101
2093
is_async,
2102
2094
outer_generator,
2103
2095
trait_ref,
@@ -2119,7 +2111,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2119
2111
& self ,
2120
2112
err : & mut Diagnostic ,
2121
2113
interior_or_upvar_span : GeneratorInteriorOrUpvar ,
2122
- interior_extra_info : Option < ( Option < Span > , Span , Option < hir:: HirId > , Option < Span > ) > ,
2123
2114
is_async : bool ,
2124
2115
outer_generator : Option < DefId > ,
2125
2116
trait_pred : ty:: TraitPredicate < ' tcx > ,
@@ -2241,7 +2232,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2241
2232
}
2242
2233
} ;
2243
2234
match interior_or_upvar_span {
2244
- GeneratorInteriorOrUpvar :: Interior ( interior_span) => {
2235
+ GeneratorInteriorOrUpvar :: Interior ( interior_span, interior_extra_info ) => {
2245
2236
if let Some ( ( scope_span, yield_span, expr, from_awaited_ty) ) = interior_extra_info {
2246
2237
if let Some ( await_span) = from_awaited_ty {
2247
2238
// The type causing this obligation is one being awaited at await_span.
0 commit comments