@@ -797,40 +797,6 @@ declare_clippy_lint! {
797797 "using a single-character str where a char could be used, e.g., `_.split(\" x\" )`"
798798}
799799
800- declare_clippy_lint ! {
801- /// **What it does:** Checks for getting the inner pointer of a temporary
802- /// `CString`.
803- ///
804- /// **Why is this bad?** The inner pointer of a `CString` is only valid as long
805- /// as the `CString` is alive.
806- ///
807- /// **Known problems:** None.
808- ///
809- /// **Example:**
810- /// ```rust
811- /// # use std::ffi::CString;
812- /// # fn call_some_ffi_func(_: *const i8) {}
813- /// #
814- /// let c_str = CString::new("foo").unwrap().as_ptr();
815- /// unsafe {
816- /// call_some_ffi_func(c_str);
817- /// }
818- /// ```
819- /// Here `c_str` points to a freed address. The correct use would be:
820- /// ```rust
821- /// # use std::ffi::CString;
822- /// # fn call_some_ffi_func(_: *const i8) {}
823- /// #
824- /// let c_str = CString::new("foo").unwrap();
825- /// unsafe {
826- /// call_some_ffi_func(c_str.as_ptr());
827- /// }
828- /// ```
829- pub TEMPORARY_CSTRING_AS_PTR ,
830- correctness,
831- "getting the inner pointer of a temporary `CString`"
832- }
833-
834800declare_clippy_lint ! {
835801 /// **What it does:** Checks for calling `.step_by(0)` on iterators which panics.
836802 ///
@@ -1405,7 +1371,6 @@ declare_lint_pass!(Methods => [
14051371 SINGLE_CHAR_PATTERN ,
14061372 SINGLE_CHAR_PUSH_STR ,
14071373 SEARCH_IS_SOME ,
1408- TEMPORARY_CSTRING_AS_PTR ,
14091374 FILTER_NEXT ,
14101375 SKIP_WHILE_NEXT ,
14111376 FILTER_MAP ,
@@ -1486,7 +1451,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
14861451 lint_search_is_some ( cx, expr, "rposition" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] )
14871452 } ,
14881453 [ "extend" , ..] => lint_extend ( cx, expr, arg_lists[ 0 ] ) ,
1489- [ "as_ptr" , "unwrap" | "expect" ] => lint_cstring_as_ptr ( cx, expr, & arg_lists[ 1 ] [ 0 ] , & arg_lists[ 0 ] [ 0 ] ) ,
14901454 [ "nth" , "iter" ] => lint_iter_nth ( cx, expr, & arg_lists, false ) ,
14911455 [ "nth" , "iter_mut" ] => lint_iter_nth ( cx, expr, & arg_lists, true ) ,
14921456 [ "nth" , ..] => lint_iter_nth_zero ( cx, expr, arg_lists[ 0 ] ) ,
@@ -2235,26 +2199,6 @@ fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>
22352199 }
22362200}
22372201
2238- fn lint_cstring_as_ptr ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , source : & hir:: Expr < ' _ > , unwrap : & hir:: Expr < ' _ > ) {
2239- if_chain ! {
2240- let source_type = cx. typeck_results( ) . expr_ty( source) ;
2241- if let ty:: Adt ( def, substs) = source_type. kind( ) ;
2242- if cx. tcx. is_diagnostic_item( sym!( result_type) , def. did) ;
2243- if match_type( cx, substs. type_at( 0 ) , & paths:: CSTRING ) ;
2244- then {
2245- span_lint_and_then(
2246- cx,
2247- TEMPORARY_CSTRING_AS_PTR ,
2248- expr. span,
2249- "you are getting the inner pointer of a temporary `CString`" ,
2250- |diag| {
2251- diag. note( "that pointer will be invalid outside this expression" ) ;
2252- diag. span_help( unwrap. span, "assign the `CString` to a variable to extend its lifetime" ) ;
2253- } ) ;
2254- }
2255- }
2256- }
2257-
22582202fn lint_iter_cloned_collect < ' tcx > ( cx : & LateContext < ' tcx > , expr : & hir:: Expr < ' _ > , iter_args : & ' tcx [ hir:: Expr < ' _ > ] ) {
22592203 if_chain ! {
22602204 if is_type_diagnostic_item( cx, cx. typeck_results( ) . expr_ty( expr) , sym!( vec_type) ) ;
0 commit comments