Skip to content

Commit d9ddce8

Browse files
committed
Auto merge of #8942 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 8ef4908 + 36b1892 commit d9ddce8

25 files changed

+123
-80
lines changed

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use rustc_middle::ty::{self, FloatTy, InferTy, Ty};
1212

1313
use super::UNNECESSARY_CAST;
1414

15-
pub(super) fn check(
16-
cx: &LateContext<'_>,
17-
expr: &Expr<'_>,
18-
cast_expr: &Expr<'_>,
19-
cast_from: Ty<'_>,
20-
cast_to: Ty<'_>,
15+
pub(super) fn check<'tcx>(
16+
cx: &LateContext<'tcx>,
17+
expr: &Expr<'tcx>,
18+
cast_expr: &Expr<'tcx>,
19+
cast_from: Ty<'tcx>,
20+
cast_to: Ty<'tcx>,
2121
) -> bool {
2222
// skip non-primitive type cast
2323
if_chain! {

clippy_lints/src/crate_in_macro_def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option<Span> {
9090
while let Some(curr) = cursor.next() {
9191
if_chain! {
9292
if !prev_is_dollar;
93-
if let Some(span) = is_crate_keyword(&curr);
93+
if let Some(span) = is_crate_keyword(curr);
9494
if let Some(next) = cursor.look_ahead(0);
9595
if is_token(next, &TokenKind::ModSep);
9696
then {
@@ -103,7 +103,7 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option<Span> {
103103
return span;
104104
}
105105
}
106-
prev_is_dollar = is_token(&curr, &TokenKind::Dollar);
106+
prev_is_dollar = is_token(curr, &TokenKind::Dollar);
107107
}
108108
None
109109
}

clippy_lints/src/dereference.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ fn try_parse_ref_op<'tcx>(
446446

447447
// Checks whether the type for a deref call actually changed the type, not just the mutability of
448448
// the reference.
449-
fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool {
449+
fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {
450450
match (result_ty.kind(), arg_ty.kind()) {
451451
(ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty,
452452

@@ -541,8 +541,8 @@ fn is_auto_borrow_position(parent: Option<Node<'_>>, child_id: HirId) -> bool {
541541
/// Adjustments are sometimes made in the parent block rather than the expression itself.
542542
fn find_adjustments<'tcx>(
543543
tcx: TyCtxt<'tcx>,
544-
typeck: &'tcx TypeckResults<'_>,
545-
expr: &'tcx Expr<'_>,
544+
typeck: &'tcx TypeckResults<'tcx>,
545+
expr: &'tcx Expr<'tcx>,
546546
) -> &'tcx [Adjustment<'tcx>] {
547547
let map = tcx.hir();
548548
let mut iter = map.parent_iter(expr.hir_id);
@@ -581,7 +581,7 @@ fn find_adjustments<'tcx>(
581581
}
582582

583583
#[expect(clippy::needless_pass_by_value)]
584-
fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData) {
584+
fn report<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, state: State, data: StateData) {
585585
match state {
586586
State::DerefMethod {
587587
ty_changed_count,
@@ -656,7 +656,7 @@ fn report(cx: &LateContext<'_>, expr: &Expr<'_>, state: State, data: StateData)
656656
}
657657

658658
impl Dereferencing {
659-
fn check_local_usage(&mut self, cx: &LateContext<'_>, e: &Expr<'_>, local: HirId) {
659+
fn check_local_usage<'tcx>(&mut self, cx: &LateContext<'tcx>, e: &Expr<'tcx>, local: HirId) {
660660
if let Some(outer_pat) = self.ref_locals.get_mut(&local) {
661661
if let Some(pat) = outer_pat {
662662
// Check for auto-deref

clippy_lints/src/escape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
189189
}
190190
}
191191

192-
fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {}
192+
fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
193193
}
194194

195195
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

clippy_lints/src/explicit_write.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use clippy_utils::source::snippet_with_applicability;
44
use clippy_utils::{is_expn_of, match_function_call, paths};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Expr, ExprKind};
7+
use rustc_hir::def::Res;
8+
use rustc_hir::{BindingAnnotation, Block, BlockCheckMode, Expr, ExprKind, Node, PatKind, QPath, Stmt, StmtKind};
89
use rustc_lint::{LateContext, LateLintPass};
910
use rustc_session::{declare_lint_pass, declare_tool_lint};
1011
use rustc_span::sym;
@@ -47,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
4748
if let ExprKind::MethodCall(unwrap_fun, [write_call], _) = expr.kind;
4849
if unwrap_fun.ident.name == sym::unwrap;
4950
// match call to write_fmt
50-
if let ExprKind::MethodCall(write_fun, [write_recv, write_arg], _) = write_call.kind;
51+
if let ExprKind::MethodCall(write_fun, [write_recv, write_arg], _) = look_in_block(cx, &write_call.kind);
5152
if write_fun.ident.name == sym!(write_fmt);
5253
// match calls to std::io::stdout() / std::io::stderr ()
5354
if let Some(dest_name) = if match_function_call(cx, write_recv, &paths::STDOUT).is_some() {
@@ -108,3 +109,34 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
108109
}
109110
}
110111
}
112+
113+
/// If `kind` is a block that looks like `{ let result = $expr; result }` then
114+
/// returns $expr. Otherwise returns `kind`.
115+
fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) -> &'tcx ExprKind<'hir> {
116+
if_chain! {
117+
if let ExprKind::Block(block, _label @ None) = kind;
118+
if let Block {
119+
stmts: [Stmt { kind: StmtKind::Local(local), .. }],
120+
expr: Some(expr_end_of_block),
121+
rules: BlockCheckMode::DefaultBlock,
122+
..
123+
} = block;
124+
125+
// Find id of the local that expr_end_of_block resolves to
126+
if let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind;
127+
if let Res::Local(expr_res) = expr_path.res;
128+
if let Some(Node::Binding(res_pat)) = cx.tcx.hir().find(expr_res);
129+
130+
// Find id of the local we found in the block
131+
if let PatKind::Binding(BindingAnnotation::Unannotated, local_hir_id, _ident, None) = local.pat.kind;
132+
133+
// If those two are the same hir id
134+
if res_pat.hir_id == local_hir_id;
135+
136+
if let Some(init) = local.init;
137+
then {
138+
return &init.kind;
139+
}
140+
}
141+
kind
142+
}

clippy_lints/src/len_zero.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ fn parse_len_output<'tcx>(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenO
259259
}
260260
}
261261

262-
impl LenOutput<'_> {
263-
fn matches_is_empty_output(self, ty: Ty<'_>) -> bool {
262+
impl<'tcx> LenOutput<'tcx> {
263+
fn matches_is_empty_output(self, ty: Ty<'tcx>) -> bool {
264264
match (self, ty.kind()) {
265265
(_, &ty::Bool) => true,
266266
(Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(),
@@ -292,7 +292,7 @@ impl LenOutput<'_> {
292292
}
293293

294294
/// Checks if the given signature matches the expectations for `is_empty`
295-
fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: LenOutput<'_>) -> bool {
295+
fn check_is_empty_sig<'tcx>(sig: FnSig<'tcx>, self_kind: ImplicitSelfKind, len_output: LenOutput<'tcx>) -> bool {
296296
match &**sig.inputs_and_output {
297297
[arg, res] if len_output.matches_is_empty_output(*res) => {
298298
matches!(
@@ -306,11 +306,11 @@ fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: L
306306
}
307307

308308
/// Checks if the given type has an `is_empty` method with the appropriate signature.
309-
fn check_for_is_empty(
310-
cx: &LateContext<'_>,
309+
fn check_for_is_empty<'tcx>(
310+
cx: &LateContext<'tcx>,
311311
span: Span,
312312
self_kind: ImplicitSelfKind,
313-
output: LenOutput<'_>,
313+
output: LenOutput<'tcx>,
314314
impl_ty: DefId,
315315
item_name: Symbol,
316316
item_kind: &str,

clippy_lints/src/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> {
371371
if let Some(ref lt) = *lifetime {
372372
if lt.name == LifetimeName::Static {
373373
self.lts.push(RefLt::Static);
374-
} else if let LifetimeName::Param(ParamName::Fresh(_)) = lt.name {
374+
} else if let LifetimeName::Param(_, ParamName::Fresh) = lt.name {
375375
// Fresh lifetimes generated should be ignored.
376376
} else if lt.is_elided() {
377377
self.lts.push(RefLt::Unnamed);

clippy_lints/src/loops/mut_range_bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
114114
}
115115
}
116116

117-
fn fake_read(&mut self, _: rustc_typeck::expr_use_visitor::Place<'tcx>, _: FakeReadCause, _: HirId) {}
117+
fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
118118
}
119119

120120
impl MutatePairDelegate<'_, '_> {

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ pub(super) fn check<'tcx>(
117117
let take_expr = sugg::Sugg::hir(cx, take_expr, "<count>");
118118
format!(".take({})", take_expr + sugg::ONE)
119119
},
120-
ast::RangeLimits::HalfOpen => format!(".take({})", snippet(cx, take_expr.span, "..")),
120+
ast::RangeLimits::HalfOpen => {
121+
format!(".take({})", snippet(cx, take_expr.span, ".."))
122+
},
121123
}
122124
}
123125
} else {
@@ -262,7 +264,11 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
262264
match res {
263265
Res::Local(hir_id) => {
264266
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
265-
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id).unwrap();
267+
let extent = self.cx
268+
.tcx
269+
.region_scope_tree(parent_def_id)
270+
.var_scope(hir_id.local_id)
271+
.unwrap();
266272
if index_used_directly {
267273
self.indexed_directly.insert(
268274
seqvar.segments[0].ident.name,

clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl EarlyLintPass for ManualNonExhaustiveStruct {
113113
let mut iter = fields.iter().filter_map(|f| match f.vis.kind {
114114
VisibilityKind::Public => None,
115115
VisibilityKind::Inherited => Some(Ok(f)),
116-
_ => Some(Err(())),
116+
VisibilityKind::Restricted { .. } => Some(Err(())),
117117
});
118118
if let Some(Ok(field)) = iter.next()
119119
&& iter.next().is_none()

0 commit comments

Comments
 (0)