about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-28 21:53:23 +0000
committerbors <bors@rust-lang.org>2020-10-28 21:53:23 +0000
commit645ef505da378b6f810b1567806d1bcc2856395f (patch)
treec6e946348b0d2638cb3cddc78830645fef187933
parentde83f09be8694b241bf3d924c0d1e70ca71c38da (diff)
parente83e79f1c21f7bf08b639c9f3cb04b38b7fecf81 (diff)
downloadrust-645ef505da378b6f810b1567806d1bcc2856395f.tar.gz
rust-645ef505da378b6f810b1567806d1bcc2856395f.zip
Auto merge of #6257 - giraffate:sync-from-rust, r=ebroto
Rustup

changelog: none
-rw-r--r--.github/driver.sh6
-rw-r--r--clippy_lints/src/deprecated_lints.rs9
-rw-r--r--clippy_lints/src/lib.rs7
-rw-r--r--clippy_lints/src/methods/mod.rs56
-rw-r--r--clippy_lints/src/utils/paths.rs1
-rw-r--r--src/lintlist/mod.rs7
-rw-r--r--tests/ui/cstring.rs24
-rw-r--r--tests/ui/cstring.stderr46
-rw-r--r--tests/ui/deprecated.rs1
-rw-r--r--tests/ui/deprecated.stderr8
10 files changed, 24 insertions, 141 deletions
diff --git a/.github/driver.sh b/.github/driver.sh
index 2c17c4203ae..e9054c459ed 100644
--- a/.github/driver.sh
+++ b/.github/driver.sh
@@ -22,9 +22,9 @@ unset CARGO_MANIFEST_DIR
 
 # Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
 # FIXME: How to match the clippy invocation in compile-test.rs?
-./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cstring.rs 2> cstring.stderr && exit 1
-sed -e "s,tests/ui,\$DIR," -e "/= help/d" cstring.stderr > normalized.stderr
-diff normalized.stderr tests/ui/cstring.stderr
+./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2> double_neg.stderr && exit 1
+sed -e "s,tests/ui,\$DIR," -e "/= help/d" double_neg.stderr > normalized.stderr
+diff normalized.stderr tests/ui/double_neg.stderr
 
 
 # make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs
index c5884361dff..461c6e31d3e 100644
--- a/clippy_lints/src/deprecated_lints.rs
+++ b/clippy_lints/src/deprecated_lints.rs
@@ -172,3 +172,12 @@ declare_deprecated_lint! {
     pub DROP_BOUNDS,
     "this lint has been uplifted to rustc and is now called `drop_bounds`"
 }
+
+declare_deprecated_lint! {
+    /// **What it does:** Nothing. This lint has been deprecated.
+    ///
+    /// **Deprecation reason:** This lint has been uplifted to rustc and is now called
+    /// `temporary_cstring_as_ptr`.
+    pub TEMPORARY_CSTRING_AS_PTR,
+    "this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`"
+}
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index 459fdd70443..2d374969846 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -488,6 +488,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
         "clippy::drop_bounds",
         "this lint has been uplifted to rustc and is now called `drop_bounds`",
     );
+    store.register_removed(
+        "clippy::temporary_cstring_as_ptr",
+        "this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`",
+    );
     // end deprecated lints, do not remove this comment, it’s used in `update_lints`
 
     // begin register lints, do not remove this comment, it’s used in `update_lints`
@@ -712,7 +716,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
         &methods::SKIP_WHILE_NEXT,
         &methods::STRING_EXTEND_CHARS,
         &methods::SUSPICIOUS_MAP,
-        &methods::TEMPORARY_CSTRING_AS_PTR,
         &methods::UNINIT_ASSUMED_INIT,
         &methods::UNNECESSARY_FILTER_MAP,
         &methods::UNNECESSARY_FOLD,
@@ -1436,7 +1439,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
         LintId::of(&methods::SKIP_WHILE_NEXT),
         LintId::of(&methods::STRING_EXTEND_CHARS),
         LintId::of(&methods::SUSPICIOUS_MAP),
-        LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR),
         LintId::of(&methods::UNINIT_ASSUMED_INIT),
         LintId::of(&methods::UNNECESSARY_FILTER_MAP),
         LintId::of(&methods::UNNECESSARY_FOLD),
@@ -1793,7 +1795,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
         LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT),
         LintId::of(&methods::CLONE_DOUBLE_REF),
         LintId::of(&methods::ITERATOR_STEP_BY_ZERO),
-        LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR),
         LintId::of(&methods::UNINIT_ASSUMED_INIT),
         LintId::of(&methods::ZST_OFFSET),
         LintId::of(&minmax::MIN_MAX),
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index c0824bacbc7..d250bfd71e9 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -799,40 +799,6 @@ declare_clippy_lint! {
 }
 
 declare_clippy_lint! {
-    /// **What it does:** Checks for getting the inner pointer of a temporary
-    /// `CString`.
-    ///
-    /// **Why is this bad?** The inner pointer of a `CString` is only valid as long
-    /// as the `CString` is alive.
-    ///
-    /// **Known problems:** None.
-    ///
-    /// **Example:**
-    /// ```rust
-    /// # use std::ffi::CString;
-    /// # fn call_some_ffi_func(_: *const i8) {}
-    /// #
-    /// let c_str = CString::new("foo").unwrap().as_ptr();
-    /// unsafe {
-    ///     call_some_ffi_func(c_str);
-    /// }
-    /// ```
-    /// Here `c_str` points to a freed address. The correct use would be:
-    /// ```rust
-    /// # use std::ffi::CString;
-    /// # fn call_some_ffi_func(_: *const i8) {}
-    /// #
-    /// let c_str = CString::new("foo").unwrap();
-    /// unsafe {
-    ///     call_some_ffi_func(c_str.as_ptr());
-    /// }
-    /// ```
-    pub TEMPORARY_CSTRING_AS_PTR,
-    correctness,
-    "getting the inner pointer of a temporary `CString`"
-}
-
-declare_clippy_lint! {
     /// **What it does:** Checks for calling `.step_by(0)` on iterators which panics.
     ///
     /// **Why is this bad?** This very much looks like an oversight. Use `panic!()` instead if you
@@ -1406,7 +1372,6 @@ declare_lint_pass!(Methods => [
     SINGLE_CHAR_PATTERN,
     SINGLE_CHAR_PUSH_STR,
     SEARCH_IS_SOME,
-    TEMPORARY_CSTRING_AS_PTR,
     FILTER_NEXT,
     SKIP_WHILE_NEXT,
     FILTER_MAP,
@@ -1490,7 +1455,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
                 lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1])
             },
             ["extend", ..] => lint_extend(cx, expr, arg_lists[0]),
-            ["as_ptr", "unwrap" | "expect"] => lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0]),
             ["nth", "iter"] => lint_iter_nth(cx, expr, &arg_lists, false),
             ["nth", "iter_mut"] => lint_iter_nth(cx, expr, &arg_lists, true),
             ["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<'_>
     }
 }
 
-fn lint_cstring_as_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) {
-    if_chain! {
-        let source_type = cx.typeck_results().expr_ty(source);
-        if let ty::Adt(def, substs) = source_type.kind();
-        if cx.tcx.is_diagnostic_item(sym!(result_type), def.did);
-        if match_type(cx, substs.type_at(0), &paths::CSTRING);
-        then {
-            span_lint_and_then(
-                cx,
-                TEMPORARY_CSTRING_AS_PTR,
-                expr.span,
-                "you are getting the inner pointer of a temporary `CString`",
-                |diag| {
-                    diag.note("that pointer will be invalid outside this expression");
-                    diag.span_help(unwrap.span, "assign the `CString` to a variable to extend its lifetime");
-                });
-        }
-    }
-}
-
 fn lint_iter_cloned_collect<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, iter_args: &'tcx [hir::Expr<'_>]) {
     if_chain! {
         if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym!(vec_type));
diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs
index d5a0e0d1f29..cd72fdd61fd 100644
--- a/clippy_lints/src/utils/paths.rs
+++ b/clippy_lints/src/utils/paths.rs
@@ -21,7 +21,6 @@ pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"];
 pub const CMP_MAX: [&str; 3] = ["core", "cmp", "max"];
 pub const CMP_MIN: [&str; 3] = ["core", "cmp", "min"];
 pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"];
-pub const CSTRING: [&str; 4] = ["std", "ffi", "c_str", "CString"];
 pub const CSTRING_AS_C_STR: [&str; 5] = ["std", "ffi", "c_str", "CString", "as_c_str"];
 pub const DEFAULT_TRAIT: [&str; 3] = ["core", "default", "Default"];
 pub const DEFAULT_TRAIT_METHOD: [&str; 4] = ["core", "default", "Default", "default"];
diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs
index aba436e5c02..c2e63ecb581 100644
--- a/src/lintlist/mod.rs
+++ b/src/lintlist/mod.rs
@@ -2294,13 +2294,6 @@ vec![
         module: "temporary_assignment",
     },
     Lint {
-        name: "temporary_cstring_as_ptr",
-        group: "correctness",
-        desc: "getting the inner pointer of a temporary `CString`",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
         name: "to_digit_is_some",
         group: "style",
         desc: "`char.is_digit()` is clearer",
diff --git a/tests/ui/cstring.rs b/tests/ui/cstring.rs
deleted file mode 100644
index 6cdd6b4ff6e..00000000000
--- a/tests/ui/cstring.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-#![deny(clippy::temporary_cstring_as_ptr)]
-
-fn main() {}
-
-fn temporary_cstring() {
-    use std::ffi::CString;
-
-    CString::new("foo").unwrap().as_ptr();
-    CString::new("foo").expect("dummy").as_ptr();
-}
-
-mod issue4375 {
-    use std::ffi::CString;
-    use std::os::raw::c_char;
-
-    extern "C" {
-        fn foo(data: *const c_char);
-    }
-
-    pub fn bar(v: &[u8]) {
-        let cstr = CString::new(v);
-        unsafe { foo(cstr.unwrap().as_ptr()) }
-    }
-}
diff --git a/tests/ui/cstring.stderr b/tests/ui/cstring.stderr
deleted file mode 100644
index 87cb29be577..00000000000
--- a/tests/ui/cstring.stderr
+++ /dev/null
@@ -1,46 +0,0 @@
-error: you are getting the inner pointer of a temporary `CString`
-  --> $DIR/cstring.rs:8:5
-   |
-LL |     CString::new("foo").unwrap().as_ptr();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: the lint level is defined here
-  --> $DIR/cstring.rs:1:9
-   |
-LL | #![deny(clippy::temporary_cstring_as_ptr)]
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: that pointer will be invalid outside this expression
-help: assign the `CString` to a variable to extend its lifetime
-  --> $DIR/cstring.rs:8:5
-   |
-LL |     CString::new("foo").unwrap().as_ptr();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: you are getting the inner pointer of a temporary `CString`
-  --> $DIR/cstring.rs:9:5
-   |
-LL |     CString::new("foo").expect("dummy").as_ptr();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: that pointer will be invalid outside this expression
-help: assign the `CString` to a variable to extend its lifetime
-  --> $DIR/cstring.rs:9:5
-   |
-LL |     CString::new("foo").expect("dummy").as_ptr();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: you are getting the inner pointer of a temporary `CString`
-  --> $DIR/cstring.rs:22:22
-   |
-LL |         unsafe { foo(cstr.unwrap().as_ptr()) }
-   |                      ^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: that pointer will be invalid outside this expression
-help: assign the `CString` to a variable to extend its lifetime
-  --> $DIR/cstring.rs:22:22
-   |
-LL |         unsafe { foo(cstr.unwrap().as_ptr()) }
-   |                      ^^^^^^^^^^^^^
-
-error: aborting due to 3 previous errors
-
diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs
index 9e32fe36ece..56755596c97 100644
--- a/tests/ui/deprecated.rs
+++ b/tests/ui/deprecated.rs
@@ -9,5 +9,6 @@
 #[warn(clippy::unused_label)]
 #[warn(clippy::regex_macro)]
 #[warn(clippy::drop_bounds)]
+#[warn(clippy::temporary_cstring_as_ptr)]
 
 fn main() {}
diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr
index d3400a7be09..37b726fc00f 100644
--- a/tests/ui/deprecated.stderr
+++ b/tests/ui/deprecated.stderr
@@ -66,11 +66,17 @@ error: lint `clippy::drop_bounds` has been removed: `this lint has been uplifted
 LL | #[warn(clippy::drop_bounds)]
    |        ^^^^^^^^^^^^^^^^^^^
 
+error: lint `clippy::temporary_cstring_as_ptr` has been removed: `this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr``
+  --> $DIR/deprecated.rs:12:8
+   |
+LL | #[warn(clippy::temporary_cstring_as_ptr)]
+   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
 error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
   --> $DIR/deprecated.rs:1:8
    |
 LL | #[warn(clippy::str_to_string)]
    |        ^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 12 previous errors
+error: aborting due to 13 previous errors