Skip to content

Commit 498c075

Browse files
committed
Auto merge of #124910 - matthiaskrgr:rollup-lo1uvdn, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #123344 (Remove braces when fixing a nested use tree into a single item) - #124587 (Generic `NonZero` post-stabilization changes.) - #124775 (crashes: add lastest batch of crash tests) - #124869 (Make sure we don't deny macro vars w keyword names) - #124876 (Simplify `use crate::rustc_foo::bar` occurrences.) - #124892 (Update cc crate to v1.0.97) - #124903 (Ignore empty RUSTC_WRAPPER in bootstrap) - #124909 (Reapply the part of #124548 that bors forgot) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ebcfd55 + 123755d commit 498c075

19 files changed

+162
-188
lines changed

clippy_lints/src/manual_assert.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use crate::rustc_lint::LintContext;
21
use clippy_utils::diagnostics::span_lint_and_then;
32
use clippy_utils::macros::{is_panic, root_macro_call};
43
use clippy_utils::{is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg};
54
use rustc_errors::Applicability;
65
use rustc_hir::{Expr, ExprKind, UnOp};
7-
use rustc_lint::{LateContext, LateLintPass};
6+
use rustc_lint::{LateContext, LateLintPass, LintContext};
87
use rustc_session::declare_lint_pass;
98

109
declare_clippy_lint! {

clippy_lints/src/methods/iter_overeager_cloned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use rustc_lint::LateContext;
99
use rustc_middle::mir::{FakeReadCause, Mutability};
1010
use rustc_middle::ty::{self, BorrowKind};
1111
use rustc_span::sym;
12+
use rustc_trait_selection::infer::TyCtxtInferExt;
1213

1314
use super::ITER_OVEREAGER_CLONED;
1415
use crate::redundant_clone::REDUNDANT_CLONE;
15-
use crate::rustc_trait_selection::infer::TyCtxtInferExt;
1616

1717
#[derive(Clone, Copy)]
1818
pub(super) enum Op<'a> {

clippy_lints/src/redundant_closure_call.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::rustc_lint::LintContext;
21
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir};
32
use clippy_utils::get_parent_expr;
43
use clippy_utils::sugg::Sugg;
@@ -9,7 +8,7 @@ use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor};
98
use rustc_hir::{
109
intravisit as hir_visit, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, ExprKind, Node,
1110
};
12-
use rustc_lint::{LateContext, LateLintPass};
11+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1312
use rustc_middle::hir::nested_filter;
1413
use rustc_middle::lint::in_external_macro;
1514
use rustc_middle::ty;

clippy_lints/src/semicolon_if_nothing_returned.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use crate::rustc_lint::LintContext;
21
use clippy_utils::diagnostics::span_lint_and_sugg;
32
use clippy_utils::source::snippet_with_context;
43
use rustc_errors::Applicability;
54
use rustc_hir::{Block, ExprKind};
6-
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_lint::{LateContext, LateLintPass, LintContext};
76
use rustc_session::declare_lint_pass;
87
use rustc_span::{ExpnKind, MacroKind, Span};
98

clippy_lints/src/single_component_path_imports.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ impl SingleComponentPathImports {
201201

202202
if segments.is_empty() {
203203
// keep track of `use {some_module, some_other_module};` usages
204-
if let UseTreeKind::Nested(trees) = &use_tree.kind {
205-
for tree in trees {
204+
if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
205+
for tree in items {
206206
let segments = &tree.0.prefix.segments;
207207
if segments.len() == 1 {
208208
if let UseTreeKind::Simple(None) = tree.0.kind {
@@ -229,8 +229,8 @@ impl SingleComponentPathImports {
229229
}
230230

231231
// nested case such as `use self::{module1::Struct1, module2::Struct2}`
232-
if let UseTreeKind::Nested(trees) = &use_tree.kind {
233-
for tree in trees {
232+
if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
233+
for tree in items {
234234
let segments = &tree.0.prefix.segments;
235235
if !segments.is_empty() {
236236
imports_reused_with_self.push(segments[0].ident.name);

clippy_lints/src/transmute/eager_transmute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(super) fn check<'tcx>(
8787
&& is_normalizable(cx, cx.param_env, from_ty)
8888
&& is_normalizable(cx, cx.param_env, to_ty)
8989
// we only want to lint if the target type has a niche that is larger than the one of the source type
90-
// e.g. `u8` to `NonZeroU8` should lint, but `NonZeroU8` to `u8` should not
90+
// e.g. `u8` to `NonZero<u8>` should lint, but `NonZero<u8>` to `u8` should not
9191
&& let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from_ty))
9292
&& let Ok(to_layout) = cx.tcx.layout_of(cx.param_env.and(to_ty))
9393
&& match (from_layout.largest_niche, to_layout.largest_niche) {

clippy_lints/src/transmute/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ declare_clippy_lint! {
257257

258258
declare_clippy_lint! {
259259
/// ### What it does
260-
/// Checks for transmutes from integers to `NonZero*` types, and suggests their `new_unchecked`
260+
/// Checks for transmutes from `T` to `NonZero<T>`, and suggests the `new_unchecked`
261261
/// method instead.
262262
///
263263
/// ### Why is this bad?
@@ -266,13 +266,13 @@ declare_clippy_lint! {
266266
///
267267
/// ### Example
268268
/// ```no_run
269-
/// # use core::num::NonZeroU32;
270-
/// let _non_zero: NonZeroU32 = unsafe { std::mem::transmute(123) };
269+
/// # use core::num::NonZero;
270+
/// let _: NonZero<u32> = unsafe { std::mem::transmute(123) };
271271
/// ```
272272
/// Use instead:
273273
/// ```no_run
274-
/// # use core::num::NonZeroU32;
275-
/// let _non_zero = unsafe { NonZeroU32::new_unchecked(123) };
274+
/// # use core::num::NonZero;
275+
/// let _: NonZero<u32> = unsafe { NonZero::new_unchecked(123) };
276276
/// ```
277277
#[clippy::version = "1.69.0"]
278278
pub TRANSMUTE_INT_TO_NON_ZERO,

clippy_lints/src/transmute/transmute_int_to_non_zero.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,22 @@ pub(super) fn check<'tcx>(
2626
return false;
2727
};
2828

29-
// FIXME: This can be simplified once `NonZero<T>` is stable.
30-
let coercible_types = [
31-
("NonZeroU8", tcx.types.u8),
32-
("NonZeroU16", tcx.types.u16),
33-
("NonZeroU32", tcx.types.u32),
34-
("NonZeroU64", tcx.types.u64),
35-
("NonZeroU128", tcx.types.u128),
36-
("NonZeroUsize", tcx.types.usize),
37-
("NonZeroI8", tcx.types.i8),
38-
("NonZeroI16", tcx.types.i16),
39-
("NonZeroI32", tcx.types.i32),
40-
("NonZeroI64", tcx.types.i64),
41-
("NonZeroI128", tcx.types.i128),
42-
("NonZeroIsize", tcx.types.isize),
43-
];
44-
45-
let int_type = substs.type_at(0);
46-
47-
let Some(nonzero_alias) = coercible_types.iter().find_map(|(nonzero_alias, t)| {
48-
if *t == int_type && *t == from_ty {
49-
Some(nonzero_alias)
50-
} else {
51-
None
52-
}
53-
}) else {
54-
return false;
55-
};
29+
let int_ty = substs.type_at(0);
30+
if from_ty != int_ty {
31+
return false;
32+
}
5633

5734
span_lint_and_then(
5835
cx,
5936
TRANSMUTE_INT_TO_NON_ZERO,
6037
e.span,
61-
format!("transmute from a `{from_ty}` to a `{nonzero_alias}`"),
38+
format!("transmute from a `{from_ty}` to a `{}<{int_ty}>`", sym::NonZero),
6239
|diag| {
6340
let arg = sugg::Sugg::hir(cx, arg, "..");
6441
diag.span_suggestion(
6542
e.span,
6643
"consider using",
67-
format!("{nonzero_alias}::{}({arg})", sym::new_unchecked),
44+
format!("{}::{}({arg})", sym::NonZero, sym::new_unchecked),
6845
Applicability::Unspecified,
6946
);
7047
},

clippy_lints/src/unnecessary_self_imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ declare_lint_pass!(UnnecessarySelfImports => [UNNECESSARY_SELF_IMPORTS]);
3636
impl EarlyLintPass for UnnecessarySelfImports {
3737
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
3838
if let ItemKind::Use(use_tree) = &item.kind
39-
&& let UseTreeKind::Nested(nodes) = &use_tree.kind
40-
&& let [(self_tree, _)] = &**nodes
39+
&& let UseTreeKind::Nested { items, .. } = &use_tree.kind
40+
&& let [(self_tree, _)] = &**items
4141
&& let [self_seg] = &*self_tree.prefix.segments
4242
&& self_seg.ident.name == kw::SelfLower
4343
&& let Some(last_segment) = use_tree.prefix.segments.last()

clippy_lints/src/unsafe_removed_from_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
4949
unsafe_to_safe_check(old_name, new_name, cx, span);
5050
},
5151
UseTreeKind::Simple(None) | UseTreeKind::Glob => {},
52-
UseTreeKind::Nested(ref nested_use_tree) => {
53-
for (use_tree, _) in nested_use_tree {
52+
UseTreeKind::Nested { ref items, .. } => {
53+
for (use_tree, _) in items {
5454
check_use_tree(use_tree, cx, span);
5555
}
5656
},

0 commit comments

Comments
 (0)