Skip to content

Commit 1a5e6ea

Browse files
Auto merge of #142791 - cuviper:beta-next, r=<try>
[beta] backports - Make the assertion in `Ident::new` debug-only. #140880 - Avoid creating an empty identifer in `Symbol::to_ident_string`. #141318 - Backport rust-lang/stdarch#1818 for 1.88 #142694 - [beta] Clippy backport #142725 - ICE: - rust-lang/rust-clippy#14776 - Lint contradictions: - rust-lang/rust-clippy#14703 - rust-lang/rust-clippy#14810 - Smaller (in LoC changes) fixes: - rust-lang/rust-clippy#14733 - rust-lang/rust-clippy#14730 r? cuviper try-job: x86_64-msvc-ext2
2 parents f5534da + 1a63214 commit 1a5e6ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+304
-1132
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ impl Ident {
23532353
#[inline]
23542354
/// Constructs a new identifier from a symbol and a span.
23552355
pub fn new(name: Symbol, span: Span) -> Ident {
2356-
assert_ne!(name, kw::Empty);
2356+
debug_assert_ne!(name, kw::Empty);
23572357
Ident { name, span }
23582358
}
23592359

@@ -2583,7 +2583,8 @@ impl Symbol {
25832583
/// (`token_to_string`, `Ident::to_string`), except that symbols don't keep the rawness flag
25842584
/// or edition, so we have to guess the rawness using the global edition.
25852585
pub fn to_ident_string(self) -> String {
2586-
Ident::with_dummy_span(self).to_string()
2586+
// Avoid creating an empty identifier, because that asserts in debug builds.
2587+
if self == kw::Empty { String::new() } else { Ident::with_dummy_span(self).to_string() }
25872588
}
25882589
}
25892590

src/ci/scripts/install-clang.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ IFS=$'\n\t'
1010
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
1111

1212
# Update both macOS's and Windows's tarballs when bumping the version here.
13-
# Try to keep this in sync with src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh
14-
LLVM_VERSION="18.1.4"
13+
# Try to keep this in sync with src/ci/docker/scripts/build-clang.sh
14+
LLVM_VERSION="20.1.3"
1515

1616
if isMacOS; then
1717
# FIXME: This is the latest pre-built version of LLVM that's available for

src/tools/clippy/clippy_config/src/types.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::PrimTy;
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::DefIdMap;
66
use rustc_middle::ty::TyCtxt;
7-
use rustc_span::Span;
7+
use rustc_span::{Span, Symbol};
88
use serde::de::{self, Deserializer, Visitor};
99
use serde::{Deserialize, Serialize, ser};
1010
use std::collections::HashMap;
@@ -145,7 +145,8 @@ pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
145145
FxHashMap::default();
146146
for disallowed_path in disallowed_paths {
147147
let path = disallowed_path.path();
148-
let mut resolutions = clippy_utils::def_path_res(tcx, &path.split("::").collect::<Vec<_>>());
148+
let path_split = path.split("::").collect::<Vec<_>>();
149+
let mut resolutions = clippy_utils::def_path_res(tcx, &path_split);
149150

150151
let mut found_def_id = None;
151152
let mut found_prim_ty = false;
@@ -160,8 +161,12 @@ pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
160161
},
161162
_ => false,
162163
});
163-
164-
if resolutions.is_empty() {
164+
if resolutions.is_empty()
165+
// Don't warn about unloaded crates:
166+
// https://github.com/rust-lang/rust-clippy/pull/14397#issuecomment-2848328221
167+
&& (path_split.len() < 2
168+
|| !clippy_utils::find_crates(tcx, Symbol::intern(path_split[0])).is_empty())
169+
{
165170
let span = disallowed_path.span();
166171

167172
if let Some(def_id) = found_def_id {

src/tools/clippy/clippy_lints/src/collapsible_if.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
33
use clippy_utils::source::{IntoSpan as _, SpanRangeExt, snippet, snippet_block, snippet_block_with_applicability};
44
use rustc_ast::BinOpKind;
55
use rustc_errors::Applicability;
6-
use rustc_hir::{Block, Expr, ExprKind, StmtKind};
6+
use rustc_hir::{Block, Expr, ExprKind, Stmt, StmtKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::ty::TyCtxt;
99
use rustc_session::impl_lint_pass;
@@ -202,13 +202,12 @@ fn block_starts_with_comment(cx: &LateContext<'_>, block: &Block<'_>) -> bool {
202202
fn expr_block<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> {
203203
match block.stmts {
204204
[] => block.expr,
205-
[stmt] => {
206-
if let StmtKind::Semi(expr) = stmt.kind {
207-
Some(expr)
208-
} else {
209-
None
210-
}
211-
},
205+
[
206+
Stmt {
207+
kind: StmtKind::Semi(expr),
208+
..
209+
},
210+
] if block.expr.is_none() => Some(expr),
212211
_ => None,
213212
}
214213
}

src/tools/clippy/clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,9 @@ pub static LINTS: &[&crate::LintInfo] = &[
705705
crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS_INFO,
706706
crate::transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS_INFO,
707707
crate::transmute::TRANSMUTE_BYTES_TO_STR_INFO,
708-
crate::transmute::TRANSMUTE_FLOAT_TO_INT_INFO,
709708
crate::transmute::TRANSMUTE_INT_TO_BOOL_INFO,
710-
crate::transmute::TRANSMUTE_INT_TO_CHAR_INFO,
711-
crate::transmute::TRANSMUTE_INT_TO_FLOAT_INFO,
712709
crate::transmute::TRANSMUTE_INT_TO_NON_ZERO_INFO,
713710
crate::transmute::TRANSMUTE_NULL_TO_FN_INFO,
714-
crate::transmute::TRANSMUTE_NUM_TO_BYTES_INFO,
715711
crate::transmute::TRANSMUTE_PTR_TO_PTR_INFO,
716712
crate::transmute::TRANSMUTE_PTR_TO_REF_INFO,
717713
crate::transmute::TRANSMUTE_UNDEFINED_REPR_INFO,

src/tools/clippy/clippy_lints/src/deprecated_lints.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,13 @@ declare_with_version! { RENAMED(RENAMED_VERSION): &[(&str, &str)] = &[
187187
("clippy::vtable_address_comparisons", "ambiguous_wide_pointer_comparisons"),
188188
#[clippy::version = ""]
189189
("clippy::reverse_range_loop", "clippy::reversed_empty_ranges"),
190+
#[clippy::version = "1.88.0"]
191+
("clippy::transmute_int_to_float", "unnecessary_transmutes"),
192+
#[clippy::version = "1.88.0"]
193+
("clippy::transmute_int_to_char", "unnecessary_transmutes"),
194+
#[clippy::version = "1.88.0"]
195+
("clippy::transmute_float_to_int", "unnecessary_transmutes"),
196+
#[clippy::version = "1.88.0"]
197+
("clippy::transmute_num_to_bytes", "unnecessary_transmutes"),
190198
// end renamed lints. used by `cargo dev rename_lint`
191199
]}

src/tools/clippy/clippy_lints/src/dereference.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,15 @@ fn report<'tcx>(
997997
);
998998
},
999999
State::DerefedBorrow(state) => {
1000+
// Do not suggest removing a non-mandatory `&` in `&*rawptr` in an `unsafe` context,
1001+
// as this may make rustc trigger its `dangerous_implicit_autorefs` lint.
1002+
if let ExprKind::AddrOf(BorrowKind::Ref, _, subexpr) = data.first_expr.kind
1003+
&& let ExprKind::Unary(UnOp::Deref, subsubexpr) = subexpr.kind
1004+
&& cx.typeck_results().expr_ty_adjusted(subsubexpr).is_raw_ptr()
1005+
{
1006+
return;
1007+
}
1008+
10001009
let mut app = Applicability::MachineApplicable;
10011010
let (snip, snip_is_macro) =
10021011
snippet_with_context(cx, expr.span, data.first_expr.span.ctxt(), "..", &mut app);

src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
155155
return;
156156
}
157157

158-
let mir = cx.tcx.mir_drops_elaborated_and_const_checked(def_id);
158+
let mir = cx.tcx.optimized_mir(def_id);
159159

160-
if let Ok(()) = is_min_const_fn(cx, &mir.borrow(), self.msrv)
160+
if let Ok(()) = is_min_const_fn(cx, mir, self.msrv)
161161
&& let hir::Node::Item(hir::Item { vis_span, .. }) | hir::Node::ImplItem(hir::ImplItem { vis_span, .. }) =
162162
cx.tcx.hir_node_by_def_id(def_id)
163163
{

src/tools/clippy/clippy_lints/src/transmute/mod.rs

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
mod crosspointer_transmute;
22
mod eager_transmute;
33
mod missing_transmute_annotations;
4-
mod transmute_float_to_int;
54
mod transmute_int_to_bool;
6-
mod transmute_int_to_char;
7-
mod transmute_int_to_float;
85
mod transmute_int_to_non_zero;
96
mod transmute_null_to_fn;
10-
mod transmute_num_to_bytes;
117
mod transmute_ptr_to_ptr;
128
mod transmute_ptr_to_ref;
139
mod transmute_ref_to_ref;
@@ -141,40 +137,6 @@ declare_clippy_lint! {
141137
"transmutes from a pointer to a reference type"
142138
}
143139

144-
declare_clippy_lint! {
145-
/// ### What it does
146-
/// Checks for transmutes from an integer to a `char`.
147-
///
148-
/// ### Why is this bad?
149-
/// Not every integer is a Unicode scalar value.
150-
///
151-
/// ### Known problems
152-
/// - [`from_u32`] which this lint suggests using is slower than `transmute`
153-
/// as it needs to validate the input.
154-
/// If you are certain that the input is always a valid Unicode scalar value,
155-
/// use [`from_u32_unchecked`] which is as fast as `transmute`
156-
/// but has a semantically meaningful name.
157-
/// - You might want to handle `None` returned from [`from_u32`] instead of calling `unwrap`.
158-
///
159-
/// [`from_u32`]: https://doc.rust-lang.org/std/char/fn.from_u32.html
160-
/// [`from_u32_unchecked`]: https://doc.rust-lang.org/std/char/fn.from_u32_unchecked.html
161-
///
162-
/// ### Example
163-
/// ```no_run
164-
/// let x = 1_u32;
165-
/// unsafe {
166-
/// let _: char = std::mem::transmute(x); // where x: u32
167-
/// }
168-
///
169-
/// // should be:
170-
/// let _ = std::char::from_u32(x).unwrap();
171-
/// ```
172-
#[clippy::version = "pre 1.29.0"]
173-
pub TRANSMUTE_INT_TO_CHAR,
174-
complexity,
175-
"transmutes from an integer to a `char`"
176-
}
177-
178140
declare_clippy_lint! {
179141
/// ### What it does
180142
/// Checks for transmutes from a `&[u8]` to a `&str`.
@@ -232,29 +194,6 @@ declare_clippy_lint! {
232194
"transmutes from an integer to a `bool`"
233195
}
234196

235-
declare_clippy_lint! {
236-
/// ### What it does
237-
/// Checks for transmutes from an integer to a float.
238-
///
239-
/// ### Why is this bad?
240-
/// Transmutes are dangerous and error-prone, whereas `from_bits` is intuitive
241-
/// and safe.
242-
///
243-
/// ### Example
244-
/// ```no_run
245-
/// unsafe {
246-
/// let _: f32 = std::mem::transmute(1_u32); // where x: u32
247-
/// }
248-
///
249-
/// // should be:
250-
/// let _: f32 = f32::from_bits(1_u32);
251-
/// ```
252-
#[clippy::version = "pre 1.29.0"]
253-
pub TRANSMUTE_INT_TO_FLOAT,
254-
complexity,
255-
"transmutes from an integer to a float"
256-
}
257-
258197
declare_clippy_lint! {
259198
/// ### What it does
260199
/// Checks for transmutes from `T` to `NonZero<T>`, and suggests the `new_unchecked`
@@ -280,52 +219,6 @@ declare_clippy_lint! {
280219
"transmutes from an integer to a non-zero wrapper"
281220
}
282221

283-
declare_clippy_lint! {
284-
/// ### What it does
285-
/// Checks for transmutes from a float to an integer.
286-
///
287-
/// ### Why is this bad?
288-
/// Transmutes are dangerous and error-prone, whereas `to_bits` is intuitive
289-
/// and safe.
290-
///
291-
/// ### Example
292-
/// ```no_run
293-
/// unsafe {
294-
/// let _: u32 = std::mem::transmute(1f32);
295-
/// }
296-
///
297-
/// // should be:
298-
/// let _: u32 = 1f32.to_bits();
299-
/// ```
300-
#[clippy::version = "1.41.0"]
301-
pub TRANSMUTE_FLOAT_TO_INT,
302-
complexity,
303-
"transmutes from a float to an integer"
304-
}
305-
306-
declare_clippy_lint! {
307-
/// ### What it does
308-
/// Checks for transmutes from a number to an array of `u8`
309-
///
310-
/// ### Why this is bad?
311-
/// Transmutes are dangerous and error-prone, whereas `to_ne_bytes`
312-
/// is intuitive and safe.
313-
///
314-
/// ### Example
315-
/// ```no_run
316-
/// unsafe {
317-
/// let x: [u8; 8] = std::mem::transmute(1i64);
318-
/// }
319-
///
320-
/// // should be
321-
/// let x: [u8; 8] = 0i64.to_ne_bytes();
322-
/// ```
323-
#[clippy::version = "1.58.0"]
324-
pub TRANSMUTE_NUM_TO_BYTES,
325-
complexity,
326-
"transmutes from a number to an array of `u8`"
327-
}
328-
329222
declare_clippy_lint! {
330223
/// ### What it does
331224
/// Checks for transmutes from a pointer to a pointer, or
@@ -581,13 +474,9 @@ impl_lint_pass!(Transmute => [
581474
TRANSMUTE_PTR_TO_PTR,
582475
USELESS_TRANSMUTE,
583476
WRONG_TRANSMUTE,
584-
TRANSMUTE_INT_TO_CHAR,
585477
TRANSMUTE_BYTES_TO_STR,
586478
TRANSMUTE_INT_TO_BOOL,
587-
TRANSMUTE_INT_TO_FLOAT,
588479
TRANSMUTE_INT_TO_NON_ZERO,
589-
TRANSMUTE_FLOAT_TO_INT,
590-
TRANSMUTE_NUM_TO_BYTES,
591480
UNSOUND_COLLECTION_TRANSMUTE,
592481
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
593482
TRANSMUTE_UNDEFINED_REPR,
@@ -632,14 +521,10 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
632521
| transmute_null_to_fn::check(cx, e, arg, to_ty)
633522
| transmute_ptr_to_ref::check(cx, e, from_ty, to_ty, arg, path, self.msrv)
634523
| missing_transmute_annotations::check(cx, path, from_ty, to_ty, e.hir_id)
635-
| transmute_int_to_char::check(cx, e, from_ty, to_ty, arg, const_context)
636524
| transmute_ref_to_ref::check(cx, e, from_ty, to_ty, arg, const_context)
637525
| transmute_ptr_to_ptr::check(cx, e, from_ty, to_ty, arg, self.msrv)
638526
| transmute_int_to_bool::check(cx, e, from_ty, to_ty, arg)
639-
| transmute_int_to_float::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv)
640527
| transmute_int_to_non_zero::check(cx, e, from_ty, to_ty, arg)
641-
| transmute_float_to_int::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv)
642-
| transmute_num_to_bytes::check(cx, e, from_ty, to_ty, arg, const_context, self.msrv)
643528
| (unsound_collection_transmute::check(cx, e, from_ty, to_ty)
644529
|| transmute_undefined_repr::check(cx, e, from_ty, to_ty))
645530
| (eager_transmute::check(cx, e, arg, from_ty, to_ty));

src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)