Use same_type
instead of duplicating logic
This commit is contained in:
parent
8da6727e96
commit
0ecc128ccb
@ -1005,26 +1005,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
{
|
||||
let mut show_suggestion = true;
|
||||
for (exp_ty, found_ty) in exp_substs.types().zip(found_substs.types()) {
|
||||
if let TyKind::Ref(_, exp_ty, _) = exp_ty.sty {
|
||||
match (&exp_ty.sty, &found_ty.sty) {
|
||||
(TyKind::Adt(exp_did, _), TyKind::Adt(found_did, _))
|
||||
if exp_did == found_did => {}
|
||||
(TyKind::Bool, TyKind::Bool) |
|
||||
(TyKind::Char, TyKind::Char) |
|
||||
(TyKind::Str, TyKind::Str) |
|
||||
(_, TyKind::Param(_)) |
|
||||
(_, TyKind::Infer(_)) |
|
||||
(TyKind::Param(_), _) |
|
||||
(TyKind::Infer(_), _) => {}
|
||||
(TyKind::Int(x), TyKind::Int(y)) if x == y => {}
|
||||
(TyKind::Uint(x), TyKind::Uint(y)) if x == y => {}
|
||||
(TyKind::Int(x), TyKind::Int(y)) if x == y => {}
|
||||
(TyKind::Uint(x), TyKind::Uint(y)) if x == y => {}
|
||||
(TyKind::Float(x), TyKind::Float(y)) if x == y => {}
|
||||
_ => show_suggestion = false,
|
||||
match exp_ty.sty {
|
||||
TyKind::Ref(_, exp_ty, _) => {
|
||||
match (&exp_ty.sty, &found_ty.sty) {
|
||||
(_, TyKind::Param(_)) |
|
||||
(_, TyKind::Infer(_)) |
|
||||
(TyKind::Param(_), _) |
|
||||
(TyKind::Infer(_), _) => {}
|
||||
_ if ty::TyS::same_type(exp_ty, found_ty) => {}
|
||||
_ => show_suggestion = false,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
show_suggestion = false;
|
||||
TyKind::Param(_) | TyKind::Infer(_) => {}
|
||||
_ => show_suggestion = false,
|
||||
}
|
||||
}
|
||||
if let (Ok(snippet), true) = (
|
||||
|
@ -658,6 +658,19 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
tcx.needs_drop_raw(param_env.and(self))
|
||||
}
|
||||
|
||||
pub fn same_type(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||
match (&a.sty, &b.sty) {
|
||||
(&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => {
|
||||
if did_a != did_b {
|
||||
return false;
|
||||
}
|
||||
|
||||
substs_a.types().zip(substs_b.types()).all(|(a, b)| Self::same_type(a, b))
|
||||
}
|
||||
_ => a == b,
|
||||
}
|
||||
}
|
||||
|
||||
/// Check whether a type is representable. This means it cannot contain unboxed
|
||||
/// structural recursion. This check is needed for structs and enums.
|
||||
pub fn is_representable(&'tcx self,
|
||||
@ -730,19 +743,6 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn same_type<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||
match (&a.sty, &b.sty) {
|
||||
(&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => {
|
||||
if did_a != did_b {
|
||||
return false;
|
||||
}
|
||||
|
||||
substs_a.types().zip(substs_b.types()).all(|(a, b)| same_type(a, b))
|
||||
}
|
||||
_ => a == b,
|
||||
}
|
||||
}
|
||||
|
||||
// Does the type `ty` directly (without indirection through a pointer)
|
||||
// contain any types on stack `seen`?
|
||||
fn is_type_structurally_recursive<'a, 'tcx>(
|
||||
@ -807,7 +807,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
// struct Foo { Option<Option<Foo>> }
|
||||
|
||||
for &seen_type in iter {
|
||||
if same_type(ty, seen_type) {
|
||||
if ty::TyS::same_type(ty, seen_type) {
|
||||
debug!("ContainsRecursive: {:?} contains {:?}",
|
||||
seen_type,
|
||||
ty);
|
||||
|
Loading…
x
Reference in New Issue
Block a user