@@ -798,40 +798,6 @@ declare_clippy_lint! {
798
798
"using a single-character str where a char could be used, e.g., `_.split(\" x\" )`"
799
799
}
800
800
801
- declare_clippy_lint ! {
802
- /// **What it does:** Checks for getting the inner pointer of a temporary
803
- /// `CString`.
804
- ///
805
- /// **Why is this bad?** The inner pointer of a `CString` is only valid as long
806
- /// as the `CString` is alive.
807
- ///
808
- /// **Known problems:** None.
809
- ///
810
- /// **Example:**
811
- /// ```rust
812
- /// # use std::ffi::CString;
813
- /// # fn call_some_ffi_func(_: *const i8) {}
814
- /// #
815
- /// let c_str = CString::new("foo").unwrap().as_ptr();
816
- /// unsafe {
817
- /// call_some_ffi_func(c_str);
818
- /// }
819
- /// ```
820
- /// Here `c_str` points to a freed address. The correct use would be:
821
- /// ```rust
822
- /// # use std::ffi::CString;
823
- /// # fn call_some_ffi_func(_: *const i8) {}
824
- /// #
825
- /// let c_str = CString::new("foo").unwrap();
826
- /// unsafe {
827
- /// call_some_ffi_func(c_str.as_ptr());
828
- /// }
829
- /// ```
830
- pub TEMPORARY_CSTRING_AS_PTR ,
831
- correctness,
832
- "getting the inner pointer of a temporary `CString`"
833
- }
834
-
835
801
declare_clippy_lint ! {
836
802
/// **What it does:** Checks for calling `.step_by(0)` on iterators which panics.
837
803
///
@@ -1406,7 +1372,6 @@ declare_lint_pass!(Methods => [
1406
1372
SINGLE_CHAR_PATTERN ,
1407
1373
SINGLE_CHAR_PUSH_STR ,
1408
1374
SEARCH_IS_SOME ,
1409
- TEMPORARY_CSTRING_AS_PTR ,
1410
1375
FILTER_NEXT ,
1411
1376
SKIP_WHILE_NEXT ,
1412
1377
FILTER_MAP ,
@@ -1490,7 +1455,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1490
1455
lint_search_is_some ( cx, expr, "rposition" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] )
1491
1456
} ,
1492
1457
[ "extend" , ..] => lint_extend ( cx, expr, arg_lists[ 0 ] ) ,
1493
- [ "as_ptr" , "unwrap" | "expect" ] => lint_cstring_as_ptr ( cx, expr, & arg_lists[ 1 ] [ 0 ] , & arg_lists[ 0 ] [ 0 ] ) ,
1494
1458
[ "nth" , "iter" ] => lint_iter_nth ( cx, expr, & arg_lists, false ) ,
1495
1459
[ "nth" , "iter_mut" ] => lint_iter_nth ( cx, expr, & arg_lists, true ) ,
1496
1460
[ "nth" , ..] => lint_iter_nth_zero ( cx, expr, arg_lists[ 0 ] ) ,
@@ -2207,26 +2171,6 @@ fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>
2207
2171
}
2208
2172
}
2209
2173
2210
- fn lint_cstring_as_ptr ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , source : & hir:: Expr < ' _ > , unwrap : & hir:: Expr < ' _ > ) {
2211
- if_chain ! {
2212
- let source_type = cx. typeck_results( ) . expr_ty( source) ;
2213
- if let ty:: Adt ( def, substs) = source_type. kind( ) ;
2214
- if cx. tcx. is_diagnostic_item( sym!( result_type) , def. did) ;
2215
- if match_type( cx, substs. type_at( 0 ) , & paths:: CSTRING ) ;
2216
- then {
2217
- span_lint_and_then(
2218
- cx,
2219
- TEMPORARY_CSTRING_AS_PTR ,
2220
- expr. span,
2221
- "you are getting the inner pointer of a temporary `CString`" ,
2222
- |diag| {
2223
- diag. note( "that pointer will be invalid outside this expression" ) ;
2224
- diag. span_help( unwrap. span, "assign the `CString` to a variable to extend its lifetime" ) ;
2225
- } ) ;
2226
- }
2227
- }
2228
- }
2229
-
2230
2174
fn lint_iter_cloned_collect < ' tcx > ( cx : & LateContext < ' tcx > , expr : & hir:: Expr < ' _ > , iter_args : & ' tcx [ hir:: Expr < ' _ > ] ) {
2231
2175
if_chain ! {
2232
2176
if is_type_diagnostic_item( cx, cx. typeck_results( ) . expr_ty( expr) , sym!( vec_type) ) ;
0 commit comments