Skip to content

Commit 32fa80d

Browse files
committed
Auto merge of #9447 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 1f92c9d + df536c9 commit 32fa80d

File tree

162 files changed

+897
-791
lines changed

Some content is hidden

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

162 files changed

+897
-791
lines changed

book/src/development/common_tools_writing_lints.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Starting with an `expr`, you can check whether it is calling a specific method
6666
impl<'tcx> LateLintPass<'tcx> for MyStructLint {
6767
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
6868
// Check our expr is calling a method
69-
if let hir::ExprKind::MethodCall(path, _, [_self_arg, ..]) = &expr.kind
69+
if let hir::ExprKind::MethodCall(path, _, _self_arg, ..) = &expr.kind
7070
// Check the name of this method is `some_method`
7171
&& path.ident.name == sym!(some_method)
7272
// Optionally, check the type of the self argument.

clippy_dev/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(let_chains)]
12
#![feature(let_else)]
23
#![feature(once_cell)]
34
#![feature(rustc_private)]

clippy_lints/src/assertions_on_result_states.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
4343
&& matches!(cx.tcx.get_diagnostic_name(macro_call.def_id), Some(sym::assert_macro))
4444
&& let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn)
4545
&& matches!(panic_expn, PanicExpn::Empty)
46-
&& let ExprKind::MethodCall(method_segment, [recv], _) = condition.kind
46+
&& let ExprKind::MethodCall(method_segment, recv, [], _) = condition.kind
4747
&& let result_type_with_refs = cx.typeck_results().expr_ty(recv)
4848
&& let result_type = result_type_with_refs.peel_refs()
4949
&& is_type_diagnostic_item(cx, result_type, sym::Result)

clippy_lints/src/async_yields_async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
5454
hir_id: body.value.hir_id,
5555
};
5656
let typeck_results = cx.tcx.typeck_body(body_id);
57-
let expr_ty = typeck_results.expr_ty(&body.value);
57+
let expr_ty = typeck_results.expr_ty(body.value);
5858

5959
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {
6060
let return_expr_span = match &body.value.kind {

clippy_lints/src/attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,15 @@ fn check_lint_reason(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem
475475

476476
fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
477477
if let ItemKind::Fn(_, _, eid) = item.kind {
478-
is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
478+
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value)
479479
} else {
480480
true
481481
}
482482
}
483483

484484
fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool {
485485
match item.kind {
486-
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value),
486+
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value),
487487
_ => false,
488488
}
489489
}
@@ -492,7 +492,7 @@ fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool {
492492
match item.kind {
493493
TraitItemKind::Fn(_, TraitFn::Required(_)) => true,
494494
TraitItemKind::Fn(_, TraitFn::Provided(eid)) => {
495-
is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
495+
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value)
496496
},
497497
_ => false,
498498
}

clippy_lints/src/blocks_in_if_conditions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
5555
// do not lint if the closure is called using an iterator (see #1141)
5656
if_chain! {
5757
if let Some(parent) = get_parent_expr(self.cx, expr);
58-
if let ExprKind::MethodCall(_, [self_arg, ..], _) = &parent.kind;
58+
if let ExprKind::MethodCall(_, self_arg, ..) = &parent.kind;
5959
let caller = self.cx.typeck_results().expr_ty(self_arg);
6060
if let Some(iter_id) = self.cx.tcx.get_diagnostic_item(sym::Iterator);
6161
if implements_trait(self.cx, caller, iter_id, &[]);

clippy_lints/src/booleans.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
270270
))
271271
})
272272
},
273-
ExprKind::MethodCall(path, args, _) if args.len() == 1 => {
274-
let type_of_receiver = cx.typeck_results().expr_ty(&args[0]);
273+
ExprKind::MethodCall(path, receiver, [], _) => {
274+
let type_of_receiver = cx.typeck_results().expr_ty(receiver);
275275
if !is_type_diagnostic_item(cx, type_of_receiver, sym::Option)
276276
&& !is_type_diagnostic_item(cx, type_of_receiver, sym::Result)
277277
{
@@ -285,7 +285,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
285285
let path: &str = path.ident.name.as_str();
286286
a == path
287287
})
288-
.and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, args[0].span)?, neg_method)))
288+
.and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, receiver.span)?, neg_method)))
289289
},
290290
_ => None,
291291
}

clippy_lints/src/casts/cast_abs_to_unsigned.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(super) fn check(
2020
if meets_msrv(msrv, msrvs::UNSIGNED_ABS)
2121
&& let ty::Int(from) = cast_from.kind()
2222
&& let ty::Uint(to) = cast_to.kind()
23-
&& let ExprKind::MethodCall(method_path, args, _) = cast_expr.kind
23+
&& let ExprKind::MethodCall(method_path, receiver, ..) = cast_expr.kind
2424
&& method_path.ident.name.as_str() == "abs"
2525
{
2626
let span = if from.bit_width() == to.bit_width() {
@@ -37,7 +37,7 @@ pub(super) fn check(
3737
span,
3838
&format!("casting the result of `{cast_from}::abs()` to {cast_to}"),
3939
"replace with",
40-
format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..").maybe_par()),
40+
format!("{}.unsigned_abs()", Sugg::hir(cx, receiver, "..").maybe_par()),
4141
Applicability::MachineApplicable,
4242
);
4343
}

clippy_lints/src/casts/cast_possible_truncation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b
4444
.saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).expect("shift too high"))),
4545
_ => nbits,
4646
},
47-
ExprKind::MethodCall(method, [left, right], _) => {
47+
ExprKind::MethodCall(method, left, [right], _) => {
4848
if signed {
4949
return nbits;
5050
}
@@ -55,7 +55,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b
5555
};
5656
apply_reductions(cx, nbits, left, signed).min(max_bits.unwrap_or(u64::max_value()))
5757
},
58-
ExprKind::MethodCall(method, [_, lo, hi], _) => {
58+
ExprKind::MethodCall(method, _, [lo, hi], _) => {
5959
if method.ident.as_str() == "clamp" {
6060
//FIXME: make this a diagnostic item
6161
if let (Some(lo_bits), Some(hi_bits)) = (get_constant_bits(cx, lo), get_constant_bits(cx, hi)) {
@@ -64,7 +64,7 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b
6464
}
6565
nbits
6666
},
67-
ExprKind::MethodCall(method, [_value], _) => {
67+
ExprKind::MethodCall(method, _value, [], _) => {
6868
if method.ident.name.as_str() == "signum" {
6969
0 // do not lint if cast comes from a `signum` function
7070
} else {

clippy_lints/src/casts/cast_ptr_alignment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
1818
cx.typeck_results().expr_ty(expr),
1919
);
2020
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
21-
} else if let ExprKind::MethodCall(method_path, [self_arg, ..], _) = &expr.kind {
21+
} else if let ExprKind::MethodCall(method_path, self_arg, ..) = &expr.kind {
2222
if method_path.ident.name == sym!(cast)
2323
&& let Some(generic_args) = method_path.args
2424
&& let [GenericArg::Type(cast_to)] = generic_args.args
@@ -64,7 +64,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
6464
return false;
6565
};
6666
match parent.kind {
67-
ExprKind::MethodCall(name, [self_arg, ..], _) if self_arg.hir_id == e.hir_id => {
67+
ExprKind::MethodCall(name, self_arg, ..) if self_arg.hir_id == e.hir_id => {
6868
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
6969
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
7070
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)

clippy_lints/src/casts/cast_sign_loss.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
4141
}
4242

4343
// Don't lint for the result of methods that always return non-negative values.
44-
if let ExprKind::MethodCall(path, _, _) = cast_op.kind {
44+
if let ExprKind::MethodCall(path, ..) = cast_op.kind {
4545
let mut method_name = path.ident.name.as_str();
4646
let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"];
4747

4848
if_chain! {
4949
if method_name == "unwrap";
5050
if let Some(arglist) = method_chain_args(cast_op, &["unwrap"]);
51-
if let ExprKind::MethodCall(inner_path, _, _) = &arglist[0][0].kind;
51+
if let ExprKind::MethodCall(inner_path, ..) = &arglist[0].0.kind;
5252
then {
5353
method_name = inner_path.ident.name.as_str();
5454
}

clippy_lints/src/default_numeric_fallback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
131131
}
132132
},
133133

134-
ExprKind::MethodCall(_, args, _) => {
134+
ExprKind::MethodCall(_, receiver, args, _) => {
135135
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
136136
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
137-
for (expr, bound) in iter::zip(*args, fn_sig.inputs()) {
137+
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
138138
self.ty_bounds.push(TyBound::Ty(*bound));
139139
self.visit_expr(expr);
140140
self.ty_bounds.pop();

clippy_lints/src/dereference.rs

+47-49
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
503503
}
504504

505505
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
506-
if let PatKind::Binding(BindingAnnotation::Ref, id, name, _) = pat.kind {
506+
if let PatKind::Binding(BindingAnnotation::REF, id, name, _) = pat.kind {
507507
if let Some(opt_prev_pat) = self.ref_locals.get_mut(&id) {
508508
// This binding id has been seen before. Add this pattern to the list of changes.
509509
if let Some(prev_pat) = opt_prev_pat {
@@ -581,7 +581,7 @@ fn try_parse_ref_op<'tcx>(
581581
expr: &'tcx Expr<'_>,
582582
) -> Option<(RefOp, &'tcx Expr<'tcx>)> {
583583
let (def_id, arg) = match expr.kind {
584-
ExprKind::MethodCall(_, [arg], _) => (typeck.type_dependent_def_id(expr.hir_id)?, arg),
584+
ExprKind::MethodCall(_, arg, [], _) => (typeck.type_dependent_def_id(expr.hir_id)?, arg),
585585
ExprKind::Call(
586586
Expr {
587587
kind: ExprKind::Path(path),
@@ -796,56 +796,54 @@ fn walk_parents<'tcx>(
796796
},
797797
})
798798
}),
799-
ExprKind::MethodCall(_, args, _) => {
799+
ExprKind::MethodCall(_, receiver, args, _) => {
800800
let id = cx.typeck_results().type_dependent_def_id(parent.hir_id).unwrap();
801-
args.iter().position(|arg| arg.hir_id == child_id).map(|i| {
802-
if i == 0 {
803-
// Check for calls to trait methods where the trait is implemented on a reference.
804-
// Two cases need to be handled:
805-
// * `self` methods on `&T` will never have auto-borrow
806-
// * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take
807-
// priority.
808-
if e.hir_id != child_id {
809-
Position::ReborrowStable(precedence)
810-
} else if let Some(trait_id) = cx.tcx.trait_of_item(id)
811-
&& let arg_ty = cx.tcx.erase_regions(cx.typeck_results().expr_ty_adjusted(e))
812-
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
813-
&& let subs = match cx
814-
.typeck_results()
815-
.node_substs_opt(parent.hir_id)
816-
.and_then(|subs| subs.get(1..))
817-
{
818-
Some(subs) => cx.tcx.mk_substs(subs.iter().copied()),
819-
None => cx.tcx.mk_substs(std::iter::empty::<ty::subst::GenericArg<'_>>()),
820-
} && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() {
821-
// Trait methods taking `&self`
822-
sub_ty
823-
} else {
824-
// Trait methods taking `self`
825-
arg_ty
826-
} && impl_ty.is_ref()
827-
&& cx.tcx.infer_ctxt().enter(|infcx|
828-
infcx
829-
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
830-
.must_apply_modulo_regions()
831-
)
801+
if receiver.hir_id == child_id {
802+
// Check for calls to trait methods where the trait is implemented on a reference.
803+
// Two cases need to be handled:
804+
// * `self` methods on `&T` will never have auto-borrow
805+
// * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take
806+
// priority.
807+
if e.hir_id != child_id {
808+
return Some(Position::ReborrowStable(precedence))
809+
} else if let Some(trait_id) = cx.tcx.trait_of_item(id)
810+
&& let arg_ty = cx.tcx.erase_regions(cx.typeck_results().expr_ty_adjusted(e))
811+
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
812+
&& let subs = match cx
813+
.typeck_results()
814+
.node_substs_opt(parent.hir_id)
815+
.and_then(|subs| subs.get(1..))
832816
{
833-
Position::MethodReceiverRefImpl
817+
Some(subs) => cx.tcx.mk_substs(subs.iter().copied()),
818+
None => cx.tcx.mk_substs(std::iter::empty::<ty::subst::GenericArg<'_>>()),
819+
} && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() {
820+
// Trait methods taking `&self`
821+
sub_ty
834822
} else {
835-
Position::MethodReceiver
836-
}
823+
// Trait methods taking `self`
824+
arg_ty
825+
} && impl_ty.is_ref()
826+
&& cx.tcx.infer_ctxt().enter(|infcx|
827+
infcx
828+
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
829+
.must_apply_modulo_regions()
830+
)
831+
{
832+
return Some(Position::MethodReceiverRefImpl)
833+
}
834+
return Some(Position::MethodReceiver);
835+
}
836+
args.iter().position(|arg| arg.hir_id == child_id).map(|i| {
837+
let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i + 1];
838+
if let ty::Param(param_ty) = ty.kind() {
839+
needless_borrow_impl_arg_position(cx, parent, i + 1, *param_ty, e, precedence, msrv)
837840
} else {
838-
let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i];
839-
if let ty::Param(param_ty) = ty.kind() {
840-
needless_borrow_impl_arg_position(cx, parent, i, *param_ty, e, precedence, msrv)
841-
} else {
842-
ty_auto_deref_stability(
843-
cx,
844-
cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i)),
845-
precedence,
846-
)
847-
.position_for_arg()
848-
}
841+
ty_auto_deref_stability(
842+
cx,
843+
cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i + 1)),
844+
precedence,
845+
)
846+
.position_for_arg()
849847
}
850848
})
851849
},
@@ -1174,7 +1172,7 @@ fn replace_types<'tcx>(
11741172
if replaced.insert(param_ty.index) {
11751173
for projection_predicate in projection_predicates {
11761174
if projection_predicate.projection_ty.self_ty() == param_ty.to_ty(cx.tcx)
1177-
&& let ty::Term::Ty(term_ty) = projection_predicate.term
1175+
&& let Some(term_ty) = projection_predicate.term.ty()
11781176
&& let ty::Param(term_param_ty) = term_ty.kind()
11791177
{
11801178
let item_def_id = projection_predicate.projection_ty.item_def_id;

clippy_lints/src/doc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
236236
typeck_results: cx.tcx.typeck(item.def_id),
237237
panic_span: None,
238238
};
239-
fpu.visit_expr(&body.value);
239+
fpu.visit_expr(body.value);
240240
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
241241
}
242242
},
@@ -286,7 +286,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
286286
typeck_results: cx.tcx.typeck(item.def_id),
287287
panic_span: None,
288288
};
289-
fpu.visit_expr(&body.value);
289+
fpu.visit_expr(body.value);
290290
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
291291
}
292292
}
@@ -348,7 +348,7 @@ fn lint_for_missing_headers<'tcx>(
348348
if let Some(future) = cx.tcx.lang_items().future_trait();
349349
let typeck = cx.tcx.typeck_body(body_id);
350350
let body = cx.tcx.hir().body(body_id);
351-
let ret_ty = typeck.expr_ty(&body.value);
351+
let ret_ty = typeck.expr_ty(body.value);
352352
if implements_trait(cx, ret_ty, future, &[]);
353353
if let ty::Opaque(_, subs) = ret_ty.kind();
354354
if let Some(gen) = subs.types().next();
@@ -828,7 +828,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
828828

829829
// check for `unwrap`
830830
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
831-
let receiver_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
831+
let receiver_ty = self.typeck_results.expr_ty(arglists[0].0).peel_refs();
832832
if is_type_diagnostic_item(self.cx, receiver_ty, sym::Option)
833833
|| is_type_diagnostic_item(self.cx, receiver_ty, sym::Result)
834834
{

0 commit comments

Comments
 (0)