Skip to content

Commit 435a8ad

Browse files
committed
Auto merge of #10802 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 28dddc7 + 2e95a4f commit 435a8ad

32 files changed

+151
-855
lines changed

clippy_lints/src/declared_lints.rs

-4
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,8 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
134134
crate::doc::NEEDLESS_DOCTEST_MAIN_INFO,
135135
crate::doc::UNNECESSARY_SAFETY_DOC_INFO,
136136
crate::double_parens::DOUBLE_PARENS_INFO,
137-
crate::drop_forget_ref::DROP_COPY_INFO,
138137
crate::drop_forget_ref::DROP_NON_DROP_INFO,
139-
crate::drop_forget_ref::DROP_REF_INFO,
140-
crate::drop_forget_ref::FORGET_COPY_INFO,
141138
crate::drop_forget_ref::FORGET_NON_DROP_INFO,
142-
crate::drop_forget_ref::FORGET_REF_INFO,
143139
crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO,
144140
crate::duplicate_mod::DUPLICATE_MOD_INFO,
145141
crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO,

clippy_lints/src/dereference.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ fn ty_auto_deref_stability<'tcx>(
14241424
continue;
14251425
},
14261426
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
1427+
ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"),
14271428
ty::Alias(ty::Projection, _) if ty.has_non_region_param() => {
14281429
TyPosition::new_deref_stable_for_result(precedence, ty)
14291430
},

clippy_lints/src/drop_forget_ref.rs

+5-112
Original file line numberDiff line numberDiff line change
@@ -7,102 +7,6 @@ use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::sym;
99

10-
declare_clippy_lint! {
11-
/// ### What it does
12-
/// Checks for calls to `std::mem::drop` with a reference
13-
/// instead of an owned value.
14-
///
15-
/// ### Why is this bad?
16-
/// Calling `drop` on a reference will only drop the
17-
/// reference itself, which is a no-op. It will not call the `drop` method (from
18-
/// the `Drop` trait implementation) on the underlying referenced value, which
19-
/// is likely what was intended.
20-
///
21-
/// ### Example
22-
/// ```ignore
23-
/// let mut lock_guard = mutex.lock();
24-
/// std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
25-
/// // still locked
26-
/// operation_that_requires_mutex_to_be_unlocked();
27-
/// ```
28-
#[clippy::version = "pre 1.29.0"]
29-
pub DROP_REF,
30-
correctness,
31-
"calls to `std::mem::drop` with a reference instead of an owned value"
32-
}
33-
34-
declare_clippy_lint! {
35-
/// ### What it does
36-
/// Checks for calls to `std::mem::forget` with a reference
37-
/// instead of an owned value.
38-
///
39-
/// ### Why is this bad?
40-
/// Calling `forget` on a reference will only forget the
41-
/// reference itself, which is a no-op. It will not forget the underlying
42-
/// referenced
43-
/// value, which is likely what was intended.
44-
///
45-
/// ### Example
46-
/// ```rust
47-
/// let x = Box::new(1);
48-
/// std::mem::forget(&x) // Should have been forget(x), x will still be dropped
49-
/// ```
50-
#[clippy::version = "pre 1.29.0"]
51-
pub FORGET_REF,
52-
correctness,
53-
"calls to `std::mem::forget` with a reference instead of an owned value"
54-
}
55-
56-
declare_clippy_lint! {
57-
/// ### What it does
58-
/// Checks for calls to `std::mem::drop` with a value
59-
/// that derives the Copy trait
60-
///
61-
/// ### Why is this bad?
62-
/// Calling `std::mem::drop` [does nothing for types that
63-
/// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the
64-
/// value will be copied and moved into the function on invocation.
65-
///
66-
/// ### Example
67-
/// ```rust
68-
/// let x: i32 = 42; // i32 implements Copy
69-
/// std::mem::drop(x) // A copy of x is passed to the function, leaving the
70-
/// // original unaffected
71-
/// ```
72-
#[clippy::version = "pre 1.29.0"]
73-
pub DROP_COPY,
74-
correctness,
75-
"calls to `std::mem::drop` with a value that implements Copy"
76-
}
77-
78-
declare_clippy_lint! {
79-
/// ### What it does
80-
/// Checks for calls to `std::mem::forget` with a value that
81-
/// derives the Copy trait
82-
///
83-
/// ### Why is this bad?
84-
/// Calling `std::mem::forget` [does nothing for types that
85-
/// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the
86-
/// value will be copied and moved into the function on invocation.
87-
///
88-
/// An alternative, but also valid, explanation is that Copy types do not
89-
/// implement
90-
/// the Drop trait, which means they have no destructors. Without a destructor,
91-
/// there
92-
/// is nothing for `std::mem::forget` to ignore.
93-
///
94-
/// ### Example
95-
/// ```rust
96-
/// let x: i32 = 42; // i32 implements Copy
97-
/// std::mem::forget(x) // A copy of x is passed to the function, leaving the
98-
/// // original unaffected
99-
/// ```
100-
#[clippy::version = "pre 1.29.0"]
101-
pub FORGET_COPY,
102-
correctness,
103-
"calls to `std::mem::forget` with a value that implements Copy"
104-
}
105-
10610
declare_clippy_lint! {
10711
/// ### What it does
10812
/// Checks for calls to `std::mem::drop` with a value that does not implement `Drop`.
@@ -172,24 +76,12 @@ declare_clippy_lint! {
17276
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
17377
}
17478

175-
const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference instead of an owned value. \
176-
Dropping a reference does nothing";
177-
const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \
178-
Forgetting a reference does nothing";
179-
const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \
180-
Dropping a copy leaves the original intact";
181-
const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \
182-
Forgetting a copy leaves the original intact";
18379
const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \
18480
Dropping such a type only extends its contained lifetimes";
18581
const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value that does not implement `Drop`. \
18682
Forgetting such a type is the same as dropping it";
18783

18884
declare_lint_pass!(DropForgetRef => [
189-
DROP_REF,
190-
FORGET_REF,
191-
DROP_COPY,
192-
FORGET_COPY,
19385
DROP_NON_DROP,
19486
FORGET_NON_DROP,
19587
UNDROPPED_MANUALLY_DROPS
@@ -206,10 +98,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
20698
let is_copy = is_copy(cx, arg_ty);
20799
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
208100
let (lint, msg) = match fn_name {
209-
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => (DROP_REF, DROP_REF_SUMMARY),
210-
sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY),
211-
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY),
212-
sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY),
101+
// early return for uplifted lints: drop_ref, drop_copy, forget_ref, forget_copy
102+
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return,
103+
sym::mem_forget if arg_ty.is_ref() => return,
104+
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return,
105+
sym::mem_forget if is_copy => return,
213106
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => {
214107
span_lint_and_help(
215108
cx,

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ pub fn read_conf(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>
392392
conf
393393
}
394394

395-
#[derive(Default)] //~ ERROR no such field
395+
#[derive(Default)]
396396
struct RegistrationGroups {
397397
all: Vec<LintId>,
398398
cargo: Vec<LintId>,

clippy_lints/src/matches/match_same_arms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'a> NormalizedPat<'a> {
282282
// TODO: Handle negative integers. They're currently treated as a wild match.
283283
ExprKind::Lit(lit) => match lit.node {
284284
LitKind::Str(sym, _) => Self::LitStr(sym),
285-
LitKind::ByteStr(ref bytes, _) => Self::LitBytes(bytes),
285+
LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes),
286286
LitKind::Byte(val) => Self::LitInt(val.into()),
287287
LitKind::Char(val) => Self::LitInt(val.into()),
288288
LitKind::Int(val, _) => Self::LitInt(val),

clippy_lints/src/matches/redundant_pattern_match.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,11 @@ fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expecte
344344
let Some(id) = cx.typeck_results().qpath_res(path, pat.hir_id).opt_def_id() else { return false };
345345

346346
match expected_item {
347-
Item::Lang(expected_lang_item) => {
348-
let expected_id = cx.tcx.lang_items().require(expected_lang_item).unwrap();
349-
cx.tcx.parent(id) == expected_id
350-
},
347+
Item::Lang(expected_lang_item) => cx
348+
.tcx
349+
.lang_items()
350+
.get(expected_lang_item)
351+
.map_or(false, |expected_id| cx.tcx.parent(id) == expected_id),
351352
Item::Diag(expected_ty, expected_variant) => {
352353
let ty = cx.typeck_results().pat_ty(pat);
353354

clippy_lints/src/methods/unnecessary_to_owned.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
385385
Node::Expr(parent_expr) => {
386386
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
387387
{
388+
// FIXME: the `subst_identity()` below seems incorrect, since we eventually
389+
// call `tcx.try_subst_and_normalize_erasing_regions` further down
390+
// (i.e., we are explicitly not in the identity context).
388391
let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder();
389392
if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id)
390393
&& let Some(param_ty) = fn_sig.inputs().get(arg_index)
@@ -435,7 +438,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
435438
let output_ty = fn_sig.output();
436439
if output_ty.contains(*param_ty) {
437440
if let Ok(new_ty) = cx.tcx.try_subst_and_normalize_erasing_regions(
438-
new_subst, cx.param_env, output_ty) {
441+
new_subst, cx.param_env, EarlyBinder(output_ty)) {
439442
expr = parent_expr;
440443
ty = new_ty;
441444
continue;

clippy_lints/src/renamed_lints.rs

+4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
3333
("clippy::zero_width_space", "clippy::invisible_characters"),
3434
("clippy::clone_double_ref", "suspicious_double_ref_op"),
3535
("clippy::drop_bounds", "drop_bounds"),
36+
("clippy::drop_copy", "drop_copy"),
37+
("clippy::drop_ref", "drop_ref"),
3638
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
3739
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
3840
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
41+
("clippy::forget_copy", "forget_copy"),
42+
("clippy::forget_ref", "forget_ref"),
3943
("clippy::into_iter_on_array", "array_into_iter"),
4044
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
4145
("clippy::invalid_ref", "invalid_value"),

clippy_lints/src/strlen_on_c_strings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_context;
3-
use clippy_utils::ty::is_type_diagnostic_item;
3+
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
44
use clippy_utils::visitors::is_expr_unsafe;
55
use clippy_utils::{get_parent_node, match_libc_symbol};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, Node, UnsafeSource};
8+
use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, LangItem, Node, UnsafeSource};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_session::{declare_lint_pass, declare_tool_lint};
1111
use rustc_span::symbol::sym;
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings {
6767
let val_name = snippet_with_context(cx, self_arg.span, ctxt, "..", &mut app).0;
6868
let method_name = if is_type_diagnostic_item(cx, ty, sym::cstring_type) {
6969
"as_bytes"
70-
} else if is_type_diagnostic_item(cx, ty, sym::CStr) {
70+
} else if is_type_lang_item(cx, ty, LangItem::CStr) {
7171
"to_bytes"
7272
} else {
7373
return;

clippy_lints/src/utils/author.rs

+5
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
304304
kind!("ByteStr(ref {vec})");
305305
chain!(self, "let [{:?}] = **{vec}", vec.value);
306306
},
307+
LitKind::CStr(ref vec, _) => {
308+
bind!(self, vec);
309+
kind!("CStr(ref {vec})");
310+
chain!(self, "let [{:?}] = **{vec}", vec.value);
311+
},
307312
LitKind::Str(s, _) => {
308313
bind!(self, s);
309314
kind!("Str({s}, _)");

clippy_utils/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
213213
match *lit {
214214
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
215215
LitKind::Byte(b) => Constant::Int(u128::from(b)),
216-
LitKind::ByteStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
216+
LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
217217
LitKind::Char(c) => Constant::Char(c),
218218
LitKind::Int(n, _) => Constant::Int(n),
219219
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-05-05"
2+
channel = "nightly-2023-05-20"
33
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

src/driver.rs

+9-61
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// FIXME: switch to something more ergonomic here, once available.
1212
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
1313
extern crate rustc_driver;
14-
extern crate rustc_errors;
1514
extern crate rustc_interface;
1615
extern crate rustc_session;
1716
extern crate rustc_span;
@@ -20,13 +19,10 @@ use rustc_interface::interface;
2019
use rustc_session::parse::ParseSess;
2120
use rustc_span::symbol::Symbol;
2221

23-
use std::borrow::Cow;
2422
use std::env;
2523
use std::ops::Deref;
26-
use std::panic;
2724
use std::path::Path;
2825
use std::process::exit;
29-
use std::sync::LazyLock;
3026

3127
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
3228
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
@@ -198,66 +194,18 @@ You can use tool lints to allow or deny lints from your code, eg.:
198194

199195
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new";
200196

201-
type PanicCallback = dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static;
202-
static ICE_HOOK: LazyLock<Box<PanicCallback>> = LazyLock::new(|| {
203-
let hook = panic::take_hook();
204-
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
205-
hook
206-
});
207-
208-
fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
209-
// Invoke our ICE handler, which prints the actual panic message and optionally a backtrace
210-
(*ICE_HOOK)(info);
211-
212-
// Separate the output with an empty line
213-
eprintln!();
214-
215-
let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
216-
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
217-
rustc_errors::ColorConfig::Auto,
218-
None,
219-
None,
220-
fallback_bundle,
221-
false,
222-
false,
223-
None,
224-
false,
225-
false,
226-
rustc_errors::TerminalUrl::No,
227-
));
228-
let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
229-
230-
// a .span_bug or .bug call has already printed what
231-
// it wants to print.
232-
if !info.payload().is::<rustc_errors::ExplicitBug>() {
233-
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
234-
handler.emit_diagnostic(&mut d);
235-
}
236-
237-
let version_info = rustc_tools_util::get_version_info!();
238-
239-
let xs: Vec<Cow<'static, str>> = vec![
240-
"the compiler unexpectedly panicked. this is a bug.".into(),
241-
format!("we would appreciate a bug report: {bug_report_url}").into(),
242-
format!("Clippy version: {version_info}").into(),
243-
];
244-
245-
for note in &xs {
246-
handler.note_without_error(note.as_ref());
247-
}
248-
249-
// If backtraces are enabled, also print the query stack
250-
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
251-
252-
let num_frames = if backtrace { None } else { Some(2) };
253-
254-
interface::try_print_query_stack(&handler, num_frames);
255-
}
256-
257197
#[allow(clippy::too_many_lines)]
258198
pub fn main() {
259199
rustc_driver::init_rustc_env_logger();
260-
LazyLock::force(&ICE_HOOK);
200+
201+
rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| {
202+
// FIXME: this macro calls unwrap internally but is called in a panicking context! It's not
203+
// as simple as moving the call from the hook to main, because `install_ice_hook` doesn't
204+
// accept a generic closure.
205+
let version_info = rustc_tools_util::get_version_info!();
206+
handler.note_without_error(format!("Clippy version: {version_info}"));
207+
});
208+
261209
exit(rustc_driver::catch_with_exit_code(move || {
262210
let mut orig_args: Vec<String> = env::args().collect();
263211
let has_sysroot_arg = arg_value(&orig_args, "--sysroot", |_| true).is_some();

tests/ui-internal/custom_ice_message.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//@normalize-stderr-test: "produce_ice.rs:\d*:\d*" -> "produce_ice.rs"
44
//@normalize-stderr-test: "', .*clippy_lints" -> "', clippy_lints"
55
//@normalize-stderr-test: "'rustc'" -> "'<unnamed>'"
6+
//@normalize-stderr-test: "running on .*" -> "running on <target>"
67
//@normalize-stderr-test: "(?ms)query stack during panic:\n.*end of query stack\n" -> ""
78

89
#![deny(clippy::internal)]

0 commit comments

Comments
 (0)