|
1 | 1 | use crate::mir::Mutability;
|
2 | 2 | use crate::ty::subst::GenericArgKind;
|
3 |
| -use crate::ty::{self, Ty, TyCtxt, TypeVisitableExt}; |
| 3 | +use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeVisitableExt}; |
4 | 4 | use rustc_hir::def_id::DefId;
|
5 | 5 | use std::fmt::Debug;
|
6 | 6 | use std::hash::Hash;
|
@@ -188,22 +188,24 @@ pub struct DeepRejectCtxt {
|
188 | 188 | }
|
189 | 189 |
|
190 | 190 | impl DeepRejectCtxt {
|
191 |
| - pub fn generic_args_may_unify<'tcx>( |
| 191 | + pub fn substs_refs_may_unify<'tcx>( |
192 | 192 | self,
|
193 |
| - obligation_arg: ty::GenericArg<'tcx>, |
194 |
| - impl_arg: ty::GenericArg<'tcx>, |
| 193 | + obligation_substs: SubstsRef<'tcx>, |
| 194 | + impl_substs: SubstsRef<'tcx>, |
195 | 195 | ) -> bool {
|
196 |
| - match (obligation_arg.unpack(), impl_arg.unpack()) { |
197 |
| - // We don't fast reject based on regions for now. |
198 |
| - (GenericArgKind::Lifetime(_), GenericArgKind::Lifetime(_)) => true, |
199 |
| - (GenericArgKind::Type(obl), GenericArgKind::Type(imp)) => { |
200 |
| - self.types_may_unify(obl, imp) |
201 |
| - } |
202 |
| - (GenericArgKind::Const(obl), GenericArgKind::Const(imp)) => { |
203 |
| - self.consts_may_unify(obl, imp) |
| 196 | + iter::zip(obligation_substs, impl_substs).all(|(obl, imp)| { |
| 197 | + match (obl.unpack(), imp.unpack()) { |
| 198 | + // We don't fast reject based on regions for now. |
| 199 | + (GenericArgKind::Lifetime(_), GenericArgKind::Lifetime(_)) => true, |
| 200 | + (GenericArgKind::Type(obl), GenericArgKind::Type(imp)) => { |
| 201 | + self.types_may_unify(obl, imp) |
| 202 | + } |
| 203 | + (GenericArgKind::Const(obl), GenericArgKind::Const(imp)) => { |
| 204 | + self.consts_may_unify(obl, imp) |
| 205 | + } |
| 206 | + _ => bug!("kind mismatch: {obl} {imp}"), |
204 | 207 | }
|
205 |
| - _ => bug!("kind mismatch: {obligation_arg} {impl_arg}"), |
206 |
| - } |
| 208 | + }) |
207 | 209 | }
|
208 | 210 |
|
209 | 211 | pub fn types_may_unify<'tcx>(self, obligation_ty: Ty<'tcx>, impl_ty: Ty<'tcx>) -> bool {
|
@@ -258,9 +260,7 @@ impl DeepRejectCtxt {
|
258 | 260 | },
|
259 | 261 | ty::Adt(obl_def, obl_substs) => match k {
|
260 | 262 | &ty::Adt(impl_def, impl_substs) => {
|
261 |
| - obl_def == impl_def |
262 |
| - && iter::zip(obl_substs, impl_substs) |
263 |
| - .all(|(obl, imp)| self.generic_args_may_unify(obl, imp)) |
| 263 | + obl_def == impl_def && self.substs_refs_may_unify(obl_substs, impl_substs) |
264 | 264 | }
|
265 | 265 | _ => false,
|
266 | 266 | },
|
|
0 commit comments