@@ -43,13 +43,8 @@ pub use type_certainty::expr_type_is_certain;
43
43
/// Lower a [`hir::Ty`] to a [`rustc_middle::ty::Ty`].
44
44
pub fn ty_from_hir_ty < ' tcx > ( cx : & LateContext < ' tcx > , hir_ty : & hir:: Ty < ' tcx > ) -> Ty < ' tcx > {
45
45
cx. maybe_typeck_results ( )
46
- . and_then ( |results| {
47
- if results. hir_owner == hir_ty. hir_id . owner {
48
- results. node_type_opt ( hir_ty. hir_id )
49
- } else {
50
- None
51
- }
52
- } )
46
+ . filter ( |results| results. hir_owner == hir_ty. hir_id . owner )
47
+ . and_then ( |results| results. node_type_opt ( hir_ty. hir_id ) )
53
48
. unwrap_or_else ( || lower_ty ( cx. tcx , hir_ty) )
54
49
}
55
50
@@ -475,6 +470,11 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
475
470
needs_ordered_drop_inner ( cx, ty, & mut FxHashSet :: default ( ) )
476
471
}
477
472
473
+ /// Returns `true` if `ty` denotes an `unsafe fn`.
474
+ pub fn is_unsafe_fn < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> bool {
475
+ ty. is_fn ( ) && ty. fn_sig ( cx. tcx ) . safety ( ) . is_unsafe ( )
476
+ }
477
+
478
478
/// Peels off all references on the type. Returns the underlying type, the number of references
479
479
/// removed, and whether the pointer is ultimately mutable or not.
480
480
pub fn peel_mid_ty_refs_is_mutable ( ty : Ty < ' _ > ) -> ( Ty < ' _ > , usize , Mutability ) {
@@ -488,15 +488,10 @@ pub fn peel_mid_ty_refs_is_mutable(ty: Ty<'_>) -> (Ty<'_>, usize, Mutability) {
488
488
f ( ty, 0 , Mutability :: Mut )
489
489
}
490
490
491
- /// Returns `true` if the given type is an `unsafe` function.
492
- pub fn type_is_unsafe_function < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> bool {
493
- ty. is_fn ( ) && ty. fn_sig ( cx. tcx ) . safety ( ) . is_unsafe ( )
494
- }
495
-
496
491
/// Returns the base type for HIR references and pointers.
497
492
pub fn walk_ptrs_hir_ty < ' tcx > ( ty : & ' tcx hir:: Ty < ' tcx > ) -> & ' tcx hir:: Ty < ' tcx > {
498
- match ty. kind {
499
- TyKind :: Ptr ( ref mut_ty) | TyKind :: Ref ( _, ref mut_ty) => walk_ptrs_hir_ty ( mut_ty. ty ) ,
493
+ match & ty. kind {
494
+ TyKind :: Ptr ( mut_ty) | TyKind :: Ref ( _, mut_ty) => walk_ptrs_hir_ty ( mut_ty. ty ) ,
500
495
_ => ty,
501
496
}
502
497
}
0 commit comments