@@ -798,40 +798,6 @@ declare_clippy_lint! {
798798 "using a single-character str where a char could be used, e.g., `_.split(\" x\" )`"
799799}
800800
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-
835801declare_clippy_lint ! {
836802 /// **What it does:** Checks for calling `.step_by(0)` on iterators which panics.
837803 ///
@@ -1406,7 +1372,6 @@ declare_lint_pass!(Methods => [
14061372 SINGLE_CHAR_PATTERN ,
14071373 SINGLE_CHAR_PUSH_STR ,
14081374 SEARCH_IS_SOME ,
1409- TEMPORARY_CSTRING_AS_PTR ,
14101375 FILTER_NEXT ,
14111376 SKIP_WHILE_NEXT ,
14121377 FILTER_MAP ,
@@ -1490,7 +1455,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
14901455 lint_search_is_some ( cx, expr, "rposition" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] )
14911456 } ,
14921457 [ "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 ] ) ,
14941458 [ "nth" , "iter" ] => lint_iter_nth ( cx, expr, & arg_lists, false ) ,
14951459 [ "nth" , "iter_mut" ] => lint_iter_nth ( cx, expr, & arg_lists, true ) ,
14961460 [ "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<'_>
22072171 }
22082172}
22092173
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-
22302174fn lint_iter_cloned_collect < ' tcx > ( cx : & LateContext < ' tcx > , expr : & hir:: Expr < ' _ > , iter_args : & ' tcx [ hir:: Expr < ' _ > ] ) {
22312175 if_chain ! {
22322176 if is_type_diagnostic_item( cx, cx. typeck_results( ) . expr_ty( expr) , sym!( vec_type) ) ;
0 commit comments