Skip to content

Commit 494c130

Browse files
committed
Cleanup: Use rustc's same_types for our same_tys
This delegates our `same_tys` to [ty::TyS::same_type][same_type] to remove some duplication. Our `same_tys` was introduced 4 years ago in rust-lang#730. Before, `same_tys` was building an inference context to be able to call `can_eq` to compare the types. The `rustc-dev-guide` has some more details about `can_eq` in [Type Inference -> Trying equality][try_eq]. Now, using the rustc function, we are essentially comparing the `DefId`s of the given types, which also makes more sense, IMO. I also confirmed that the FIXME is resolved via a bit of `dbg!`, however no UI tests were affected. [same_type]: https://github.com/rust-lang/rust/blob/659951c4a0d7450e43f61c61c0e87d0ceae17087/src/librustc_middle/ty/util.rs#L777 [try_eq]: https://rustc-dev-guide.rust-lang.org/type-inference.html#trying-equality
1 parent 6ffe725 commit 494c130

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -890,17 +890,8 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> T
890890
}
891891

892892
/// Checks if two types are the same.
893-
///
894-
/// This discards any lifetime annotations, too.
895-
//
896-
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` ==
897-
// `for <'b> Foo<'b>`, but not for type parameters).
898893
pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
899-
let a = cx.tcx.erase_late_bound_regions(&Binder::bind(a));
900-
let b = cx.tcx.erase_late_bound_regions(&Binder::bind(b));
901-
cx.tcx
902-
.infer_ctxt()
903-
.enter(|infcx| infcx.can_eq(cx.param_env, a, b).is_ok())
894+
ty::TyS::same_type(a, b)
904895
}
905896

906897
/// Returns `true` if the given type is an `unsafe` function.

0 commit comments

Comments
 (0)