Skip to content

Commit 645ef50

Browse files
committed
Auto merge of #6257 - giraffate:sync-from-rust, r=ebroto
Rustup changelog: none
2 parents de83f09 + e83e79f commit 645ef50

File tree

10 files changed

+24
-141
lines changed

10 files changed

+24
-141
lines changed

.github/driver.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ unset CARGO_MANIFEST_DIR
2222

2323
# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
2424
# FIXME: How to match the clippy invocation in compile-test.rs?
25-
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/cstring.rs 2> cstring.stderr && exit 1
26-
sed -e "s,tests/ui,\$DIR," -e "/= help/d" cstring.stderr > normalized.stderr
27-
diff normalized.stderr tests/ui/cstring.stderr
25+
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2> double_neg.stderr && exit 1
26+
sed -e "s,tests/ui,\$DIR," -e "/= help/d" double_neg.stderr > normalized.stderr
27+
diff normalized.stderr tests/ui/double_neg.stderr
2828

2929

3030
# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same

clippy_lints/src/deprecated_lints.rs

+9
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,12 @@ declare_deprecated_lint! {
172172
pub DROP_BOUNDS,
173173
"this lint has been uplifted to rustc and is now called `drop_bounds`"
174174
}
175+
176+
declare_deprecated_lint! {
177+
/// **What it does:** Nothing. This lint has been deprecated.
178+
///
179+
/// **Deprecation reason:** This lint has been uplifted to rustc and is now called
180+
/// `temporary_cstring_as_ptr`.
181+
pub TEMPORARY_CSTRING_AS_PTR,
182+
"this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`"
183+
}

clippy_lints/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
488488
"clippy::drop_bounds",
489489
"this lint has been uplifted to rustc and is now called `drop_bounds`",
490490
);
491+
store.register_removed(
492+
"clippy::temporary_cstring_as_ptr",
493+
"this lint has been uplifted to rustc and is now called `temporary_cstring_as_ptr`",
494+
);
491495
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
492496

493497
// 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:
712716
&methods::SKIP_WHILE_NEXT,
713717
&methods::STRING_EXTEND_CHARS,
714718
&methods::SUSPICIOUS_MAP,
715-
&methods::TEMPORARY_CSTRING_AS_PTR,
716719
&methods::UNINIT_ASSUMED_INIT,
717720
&methods::UNNECESSARY_FILTER_MAP,
718721
&methods::UNNECESSARY_FOLD,
@@ -1436,7 +1439,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14361439
LintId::of(&methods::SKIP_WHILE_NEXT),
14371440
LintId::of(&methods::STRING_EXTEND_CHARS),
14381441
LintId::of(&methods::SUSPICIOUS_MAP),
1439-
LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR),
14401442
LintId::of(&methods::UNINIT_ASSUMED_INIT),
14411443
LintId::of(&methods::UNNECESSARY_FILTER_MAP),
14421444
LintId::of(&methods::UNNECESSARY_FOLD),
@@ -1793,7 +1795,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17931795
LintId::of(&mem_replace::MEM_REPLACE_WITH_UNINIT),
17941796
LintId::of(&methods::CLONE_DOUBLE_REF),
17951797
LintId::of(&methods::ITERATOR_STEP_BY_ZERO),
1796-
LintId::of(&methods::TEMPORARY_CSTRING_AS_PTR),
17971798
LintId::of(&methods::UNINIT_ASSUMED_INIT),
17981799
LintId::of(&methods::ZST_OFFSET),
17991800
LintId::of(&minmax::MIN_MAX),

clippy_lints/src/methods/mod.rs

-56
Original file line numberDiff line numberDiff line change
@@ -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-
835801
declare_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-
22302174
fn 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));

clippy_lints/src/utils/paths.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"];
2121
pub const CMP_MAX: [&str; 3] = ["core", "cmp", "max"];
2222
pub const CMP_MIN: [&str; 3] = ["core", "cmp", "min"];
2323
pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"];
24-
pub const CSTRING: [&str; 4] = ["std", "ffi", "c_str", "CString"];
2524
pub const CSTRING_AS_C_STR: [&str; 5] = ["std", "ffi", "c_str", "CString", "as_c_str"];
2625
pub const DEFAULT_TRAIT: [&str; 3] = ["core", "default", "Default"];
2726
pub const DEFAULT_TRAIT_METHOD: [&str; 4] = ["core", "default", "Default", "default"];

src/lintlist/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -2293,13 +2293,6 @@ vec![
22932293
deprecation: None,
22942294
module: "temporary_assignment",
22952295
},
2296-
Lint {
2297-
name: "temporary_cstring_as_ptr",
2298-
group: "correctness",
2299-
desc: "getting the inner pointer of a temporary `CString`",
2300-
deprecation: None,
2301-
module: "methods",
2302-
},
23032296
Lint {
23042297
name: "to_digit_is_some",
23052298
group: "style",

tests/ui/cstring.rs

-24
This file was deleted.

tests/ui/cstring.stderr

-46
This file was deleted.

tests/ui/deprecated.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
#[warn(clippy::unused_label)]
1010
#[warn(clippy::regex_macro)]
1111
#[warn(clippy::drop_bounds)]
12+
#[warn(clippy::temporary_cstring_as_ptr)]
1213

1314
fn main() {}

tests/ui/deprecated.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ error: lint `clippy::drop_bounds` has been removed: `this lint has been uplifted
6666
LL | #[warn(clippy::drop_bounds)]
6767
| ^^^^^^^^^^^^^^^^^^^
6868

69+
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``
70+
--> $DIR/deprecated.rs:12:8
71+
|
72+
LL | #[warn(clippy::temporary_cstring_as_ptr)]
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
6975
error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
7076
--> $DIR/deprecated.rs:1:8
7177
|
7278
LL | #[warn(clippy::str_to_string)]
7379
| ^^^^^^^^^^^^^^^^^^^^^
7480

75-
error: aborting due to 12 previous errors
81+
error: aborting due to 13 previous errors
7682

0 commit comments

Comments
 (0)