@@ -49,14 +49,19 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
49
49
&& as_ptr_path. ident . name == sym:: as_ptr
50
50
&& let ExprKind :: MethodCall ( unwrap_path, unwrap_receiver, ..) = as_ptr_receiver. kind
51
51
&& ( unwrap_path. ident . name == sym:: unwrap || unwrap_path. ident . name == sym:: expect)
52
- && lint_cstring_as_ptr ( cx, unwrap_receiver)
52
+ && let source_type = cx. typeck_results ( ) . expr_ty ( unwrap_receiver)
53
+ && let ty:: Adt ( def, args) = source_type. kind ( )
54
+ && cx. tcx . is_diagnostic_item ( sym:: Result , def. did ( ) )
55
+ && let ty = args. type_at ( 0 )
56
+ && let ty:: Adt ( adt, _) = ty. kind ( )
57
+ && cx. tcx . is_diagnostic_item ( sym:: cstring_type, adt. did ( ) )
53
58
{
54
59
cx. emit_span_lint (
55
60
TEMPORARY_CSTRING_AS_PTR ,
56
61
as_ptr_path. ident . span ,
57
62
InstantlyDangling {
58
63
callee : as_ptr_path. ident . name ,
59
- ty : "CString" . into ( ) ,
64
+ ty,
60
65
ptr_span : as_ptr_path. ident . span ,
61
66
temporary_span : as_ptr_receiver. span ,
62
67
} ,
@@ -75,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
75
80
method. ident . span ,
76
81
InstantlyDangling {
77
82
callee : method. ident . name ,
78
- ty : ty . to_string ( ) ,
83
+ ty,
79
84
ptr_span : method. ident . span ,
80
85
temporary_span : receiver. span ,
81
86
} ,
@@ -84,20 +89,6 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
84
89
}
85
90
}
86
91
87
- fn lint_cstring_as_ptr ( cx : & LateContext < ' _ > , source : & rustc_hir:: Expr < ' _ > ) -> bool {
88
- let source_type = cx. typeck_results ( ) . expr_ty ( source) ;
89
- if let ty:: Adt ( def, args) = source_type. kind ( ) {
90
- if cx. tcx . is_diagnostic_item ( sym:: Result , def. did ( ) ) {
91
- if let ty:: Adt ( adt, _) = args. type_at ( 0 ) . kind ( ) {
92
- if cx. tcx . is_diagnostic_item ( sym:: cstring_type, adt. did ( ) ) {
93
- return true ;
94
- }
95
- }
96
- }
97
- }
98
- false
99
- }
100
-
101
92
fn is_temporary_rvalue ( expr : & Expr < ' _ > ) -> bool {
102
93
match expr. kind {
103
94
// Const is not temporary.
0 commit comments