@@ -7,7 +7,7 @@ use rustc_hir as hir;
77use rustc_hir:: def_id:: { DefId , DefIdMap } ;
88use rustc_lint:: { LateContext , LateLintPass } ;
99use rustc_middle:: mir:: CoroutineLayout ;
10- use rustc_middle:: ty:: TyCtxt ;
10+ use rustc_middle:: ty:: { TyCtxt , Ty } ;
1111use rustc_session:: impl_lint_pass;
1212use rustc_span:: Span ;
1313
@@ -213,7 +213,8 @@ impl<'tcx> LateLintPass<'tcx> for AwaitHolding {
213213impl AwaitHolding {
214214 fn check_interior_types ( & self , cx : & LateContext < ' _ > , coroutine : & CoroutineLayout < ' _ > ) {
215215 for ( ty_index, ty_cause) in coroutine. field_tys . iter_enumerated ( ) {
216- if let rustc_middle:: ty:: Adt ( adt, _) = ty_cause. ty . kind ( ) {
216+ let coroutine_field_ty = maybe_unwrap_unsafe_pinned ( ty_cause. ty ) ;
217+ if let rustc_middle:: ty:: Adt ( adt, _) = coroutine_field_ty. kind ( ) {
217218 let await_points = || {
218219 coroutine
219220 . variant_source_info
@@ -226,6 +227,7 @@ impl AwaitHolding {
226227 } )
227228 . collect :: < Vec < _ > > ( )
228229 } ;
230+
229231 if is_mutex_guard ( cx, adt. did ( ) ) {
230232 span_lint_and_then (
231233 cx,
@@ -263,6 +265,18 @@ impl AwaitHolding {
263265 }
264266 }
265267 }
268+
269+ }
270+
271+
272+ // self-referential coroutine fields are wrapped in `UnsafePinned`.
273+ fn maybe_unwrap_unsafe_pinned < ' tcx > ( ty : Ty < ' tcx > ) -> Ty < ' tcx > {
274+ match ty. kind ( ) {
275+ rustc_middle:: ty:: Adt ( adt, args) if adt. is_unsafe_pinned ( ) => {
276+ args. type_at ( 0 )
277+ }
278+ _ => ty
279+ }
266280}
267281
268282fn emit_invalid_type (
0 commit comments