@@ -794,18 +794,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
794794 // The auto impl might apply; we don't know.
795795 candidates. ambiguous = true ;
796796 }
797- ty:: Coroutine ( coroutine_def_id, _)
798- if self . tcx ( ) . is_lang_item ( def_id, LangItem :: Unpin ) =>
799- {
800- match self . tcx ( ) . coroutine_movability ( coroutine_def_id) {
801- hir:: Movability :: Static => {
802- // Immovable coroutines are never `Unpin`, so
803- // suppress the normal auto-impl candidate for it.
797+ ty:: Coroutine ( coroutine_def_id, _) => {
798+ if self . tcx ( ) . is_lang_item ( def_id, LangItem :: Unpin ) {
799+ match self . tcx ( ) . coroutine_movability ( coroutine_def_id) {
800+ hir:: Movability :: Static => {
801+ // Immovable coroutines are never `Unpin`, so
802+ // suppress the normal auto-impl candidate for it.
803+ }
804+ hir:: Movability :: Movable => {
805+ // Movable coroutines are always `Unpin`, so add an
806+ // unconditional builtin candidate with no sub-obligations.
807+ candidates. vec . push ( BuiltinCandidate ) ;
808+ }
804809 }
805- hir:: Movability :: Movable => {
806- // Movable coroutines are always `Unpin`, so add an
807- // unconditional builtin candidate.
808- candidates. vec . push ( BuiltinCandidate ) ;
810+ } else {
811+ if self . should_stall_coroutine ( coroutine_def_id) {
812+ candidates. ambiguous = true ;
813+ } else {
814+ // Coroutines implement all other auto traits normally.
815+ candidates. vec . push ( AutoImplCandidate ) ;
809816 }
810817 }
811818 }
@@ -842,12 +849,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
842849 }
843850 }
844851
845- ty:: CoroutineWitness ( def_id, _) => {
846- if self . should_stall_coroutine_witness ( def_id) {
847- candidates. ambiguous = true ;
848- } else {
849- candidates. vec . push ( AutoImplCandidate ) ;
850- }
852+ ty:: CoroutineWitness ( ..) => {
853+ candidates. vec . push ( AutoImplCandidate ) ;
851854 }
852855
853856 ty:: Bool
@@ -866,7 +869,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
866869 | ty:: FnPtr ( ..)
867870 | ty:: Closure ( ..)
868871 | ty:: CoroutineClosure ( ..)
869- | ty:: Coroutine ( ..)
870872 | ty:: Never
871873 | ty:: Tuple ( _)
872874 | ty:: UnsafeBinder ( _) => {
@@ -1153,15 +1155,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11531155 ty:: Ref ( _, _, hir:: Mutability :: Mut ) => { }
11541156
11551157 ty:: Coroutine ( coroutine_def_id, args) => {
1158+ if self . should_stall_coroutine ( coroutine_def_id) {
1159+ candidates. ambiguous = true ;
1160+ return ;
1161+ }
1162+
11561163 match self . tcx ( ) . coroutine_movability ( coroutine_def_id) {
11571164 hir:: Movability :: Static => { }
11581165 hir:: Movability :: Movable => {
11591166 if self . tcx ( ) . features ( ) . coroutine_clone ( ) {
11601167 let resolved_upvars =
11611168 self . infcx . shallow_resolve ( args. as_coroutine ( ) . tupled_upvars_ty ( ) ) ;
1162- let resolved_witness =
1163- self . infcx . shallow_resolve ( args. as_coroutine ( ) . witness ( ) ) ;
1164- if resolved_upvars. is_ty_var ( ) || resolved_witness. is_ty_var ( ) {
1169+ if resolved_upvars. is_ty_var ( ) {
11651170 // Not yet resolved.
11661171 candidates. ambiguous = true ;
11671172 } else {
@@ -1194,12 +1199,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11941199 }
11951200 }
11961201
1197- ty:: CoroutineWitness ( coroutine_def_id, _) => {
1198- if self . should_stall_coroutine_witness ( coroutine_def_id) {
1199- candidates. ambiguous = true ;
1200- } else {
1201- candidates. vec . push ( SizedCandidate ) ;
1202- }
1202+ ty:: CoroutineWitness ( ..) => {
1203+ candidates. vec . push ( SizedCandidate ) ;
12031204 }
12041205
12051206 // Fallback to whatever user-defined impls or param-env clauses exist in this case.
@@ -1238,7 +1239,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12381239 | ty:: RawPtr ( ..)
12391240 | ty:: Char
12401241 | ty:: Ref ( ..)
1241- | ty:: Coroutine ( ..)
12421242 | ty:: Array ( ..)
12431243 | ty:: Closure ( ..)
12441244 | ty:: CoroutineClosure ( ..)
@@ -1247,14 +1247,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12471247 candidates. vec . push ( SizedCandidate ) ;
12481248 }
12491249
1250- ty:: CoroutineWitness ( coroutine_def_id, _) => {
1251- if self . should_stall_coroutine_witness ( coroutine_def_id) {
1250+ ty:: Coroutine ( coroutine_def_id, _) => {
1251+ if self . should_stall_coroutine ( coroutine_def_id) {
12521252 candidates. ambiguous = true ;
12531253 } else {
12541254 candidates. vec . push ( SizedCandidate ) ;
12551255 }
12561256 }
12571257
1258+ ty:: CoroutineWitness ( ..) => {
1259+ candidates. vec . push ( SizedCandidate ) ;
1260+ }
1261+
12581262 // Conditionally `Sized`.
12591263 ty:: Tuple ( ..) | ty:: Pat ( ..) | ty:: Adt ( ..) | ty:: UnsafeBinder ( _) => {
12601264 candidates. vec . push ( SizedCandidate ) ;
0 commit comments