@@ -49,14 +49,19 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
4949 && as_ptr_path. ident . name == sym:: as_ptr
5050 && let ExprKind :: MethodCall ( unwrap_path, unwrap_receiver, ..) = as_ptr_receiver. kind
5151 && ( 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 ( ) )
5358 {
5459 cx. emit_span_lint (
5560 TEMPORARY_CSTRING_AS_PTR ,
5661 as_ptr_path. ident . span ,
5762 InstantlyDangling {
5863 callee : as_ptr_path. ident . name ,
59- ty : "CString" . into ( ) ,
64+ ty,
6065 ptr_span : as_ptr_path. ident . span ,
6166 temporary_span : as_ptr_receiver. span ,
6267 } ,
@@ -75,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
7580 method. ident . span ,
7681 InstantlyDangling {
7782 callee : method. ident . name ,
78- ty : ty . to_string ( ) ,
83+ ty,
7984 ptr_span : method. ident . span ,
8085 temporary_span : receiver. span ,
8186 } ,
@@ -84,20 +89,6 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
8489 }
8590}
8691
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-
10192fn is_temporary_rvalue ( expr : & Expr < ' _ > ) -> bool {
10293 match expr. kind {
10394 // Const is not temporary.
0 commit comments