@@ -43,13 +43,8 @@ pub use type_certainty::expr_type_is_certain;
4343/// Lower a [`hir::Ty`] to a [`rustc_middle::ty::Ty`].
4444pub fn ty_from_hir_ty < ' tcx > ( cx : & LateContext < ' tcx > , hir_ty : & hir:: Ty < ' tcx > ) -> Ty < ' tcx > {
4545 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 ) )
5348 . unwrap_or_else ( || lower_ty ( cx. tcx , hir_ty) )
5449}
5550
@@ -475,6 +470,11 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
475470 needs_ordered_drop_inner ( cx, ty, & mut FxHashSet :: default ( ) )
476471}
477472
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+
478478/// Peels off all references on the type. Returns the underlying type, the number of references
479479/// removed, and whether the pointer is ultimately mutable or not.
480480pub 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) {
488488 f ( ty, 0 , Mutability :: Mut )
489489}
490490
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-
496491/// Returns the base type for HIR references and pointers.
497492pub 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 ) ,
500495 _ => ty,
501496 }
502497}
0 commit comments