|
3 | 3 | use super::assembly::{self, structural_traits};
|
4 | 4 | use super::{EvalCtxt, SolverMode};
|
5 | 5 | use rustc_hir::def_id::DefId;
|
6 |
| -use rustc_hir::LangItem; |
| 6 | +use rustc_hir::{LangItem, Movability}; |
7 | 7 | use rustc_infer::traits::query::NoSolution;
|
8 | 8 | use rustc_infer::traits::util::supertraits;
|
9 | 9 | use rustc_middle::traits::solve::{CanonicalResponse, Certainty, Goal, QueryResult};
|
@@ -168,6 +168,23 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
|
168 | 168 |
|
169 | 169 | ty::Infer(_) | ty::Bound(_, _) => bug!("unexpected type `{self_ty}`"),
|
170 | 170 |
|
| 171 | + // Generators have one special built-in candidate, `Unpin`, which |
| 172 | + // takes precedence over the structural auto trait candidate being |
| 173 | + // assembled. |
| 174 | + ty::Generator(_, _, movability) |
| 175 | + if Some(goal.predicate.def_id()) == ecx.tcx().lang_items().unpin_trait() => |
| 176 | + { |
| 177 | + match movability { |
| 178 | + Movability::Static => { |
| 179 | + return Err(NoSolution); |
| 180 | + } |
| 181 | + Movability::Movable => { |
| 182 | + return ecx |
| 183 | + .evaluate_added_goals_and_make_canonical_response(Certainty::Yes); |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + |
171 | 188 | // For rigid types, we only register a builtin auto implementation
|
172 | 189 | // if there is no implementation that could ever apply to the self
|
173 | 190 | // type.
|
|
0 commit comments