Skip to content

Commit 1480cea

Browse files
committed
Auto merge of #10242 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 54e929b + 6f9c70a commit 1480cea

29 files changed

+108
-90
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.68"
3+
version = "0.1.69"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.68"
3+
version = "0.1.69"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMe
472472

473473
fn check_lint_reason(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem], attr: &'_ Attribute) {
474474
// Check for the feature
475-
if !cx.tcx.sess.features_untracked().lint_reasons {
475+
if !cx.tcx.features().lint_reasons {
476476
return;
477477
}
478478

clippy_lints/src/derive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn check_hash_peq<'tcx>(
251251

252252
// Only care about `impl PartialEq<Foo> for Foo`
253253
// For `impl PartialEq<B> for A, input_types is [A, B]
254-
if trait_ref.substs.type_at(1) == ty {
254+
if trait_ref.subst_identity().substs.type_at(1) == ty {
255255
span_lint_and_then(
256256
cx,
257257
DERIVED_HASH_WITH_MANUAL_EQ,
@@ -299,7 +299,7 @@ fn check_ord_partial_ord<'tcx>(
299299

300300
// Only care about `impl PartialOrd<Foo> for Foo`
301301
// For `impl PartialOrd<B> for A, input_types is [A, B]
302-
if trait_ref.substs.type_at(1) == ty {
302+
if trait_ref.subst_identity().substs.type_at(1) == ty {
303303
let mess = if partial_ord_is_automatically_derived {
304304
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
305305
} else {

clippy_lints/src/fallible_impl_from.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
5656
if_chain! {
5757
if let hir::ItemKind::Impl(impl_) = &item.kind;
5858
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
59-
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id);
59+
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id);
6060
then {
6161
lint_impl_body(cx, item.span, impl_.items);
6262
}

clippy_lints/src/format_args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use clippy_utils::macros::{
77
};
88
use clippy_utils::msrvs::{self, Msrv};
99
use clippy_utils::source::snippet_opt;
10-
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
10+
use clippy_utils::ty::{implements_trait, is_type_lang_item};
1111
use if_chain::if_chain;
1212
use itertools::Itertools;
1313
use rustc_errors::{
1414
Applicability,
1515
SuggestionStyle::{CompletelyHidden, ShowCode},
1616
};
17-
use rustc_hir::{Expr, ExprKind, HirId, QPath};
17+
use rustc_hir::{Expr, ExprKind, HirId, LangItem, QPath};
1818
use rustc_lint::{LateContext, LateLintPass, LintContext};
1919
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
2020
use rustc_middle::ty::Ty;
@@ -237,7 +237,7 @@ fn check_unused_format_specifier(cx: &LateContext<'_>, arg: &FormatArg<'_>) {
237237
);
238238
}
239239

240-
if is_type_diagnostic_item(cx, param_ty, sym::Arguments) && !arg.format.is_default_for_trait() {
240+
if is_type_lang_item(cx, param_ty, LangItem::FormatArguments) && !arg.format.is_default_for_trait() {
241241
span_lint_and_then(
242242
cx,
243243
UNUSED_FORMAT_SPECS,

clippy_lints/src/from_over_into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
7676
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
7777
// `impl Into<target_ty> for self_ty`
7878
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
79-
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
79+
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity)
8080
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
8181
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
8282
{

clippy_lints/src/future_not_send.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
7878
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
7979
let span = decl.output.span();
8080
let infcx = cx.tcx.infer_ctxt().build();
81-
let cause = traits::ObligationCause::misc(span, hir_id);
81+
let def_id = cx.tcx.hir().local_def_id(hir_id);
82+
let cause = traits::ObligationCause::misc(span, def_id);
8283
let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait);
8384
if !send_errors.is_empty() {
8485
span_lint_and_then(

clippy_lints/src/inherent_impl.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,19 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5252
// List of spans to lint. (lint_span, first_span)
5353
let mut lint_spans = Vec::new();
5454

55-
for (_, impl_ids) in cx
55+
let inherent_impls = cx
5656
.tcx
57-
.crate_inherent_impls(())
58-
.inherent_impls
59-
.iter()
60-
.filter(|(&id, impls)| {
61-
impls.len() > 1
62-
// Check for `#[allow]` on the type definition
63-
&& !is_lint_allowed(
64-
cx,
65-
MULTIPLE_INHERENT_IMPL,
66-
cx.tcx.hir().local_def_id_to_hir_id(id),
67-
)
68-
})
69-
{
57+
.with_stable_hashing_context(|hcx| cx.tcx.crate_inherent_impls(()).inherent_impls.to_sorted(&hcx, true));
58+
59+
for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| {
60+
impls.len() > 1
61+
// Check for `#[allow]` on the type definition
62+
&& !is_lint_allowed(
63+
cx,
64+
MULTIPLE_INHERENT_IMPL,
65+
cx.tcx.hir().local_def_id_to_hir_id(id),
66+
)
67+
}) {
7068
for impl_id in impl_ids.iter().map(|id| id.expect_local()) {
7169
match type_map.entry(cx.tcx.type_of(impl_id)) {
7270
Entry::Vacant(e) => {

clippy_lints/src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
219219
let is_empty = sym!(is_empty);
220220

221221
let is_empty_method_found = current_and_super_traits
222-
.iter()
222+
.items()
223223
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
224224
.any(|i| {
225225
i.kind == ty::AssocKind::Fn

clippy_lints/src/loops/while_immutable_condition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'
3535
} else {
3636
return;
3737
};
38-
let mutable_static_in_cond = var_visitor.def_ids.iter().any(|(_, v)| *v);
38+
let mutable_static_in_cond = var_visitor.def_ids.items().any(|(_, v)| *v);
3939

4040
let mut has_break_or_return_visitor = HasBreakOrReturnVisitor {
4141
has_break_or_return: false,

clippy_lints/src/methods/unnecessary_to_owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
371371
&& let output_ty = return_ty(cx, item.hir_id())
372372
&& let local_def_id = cx.tcx.hir().local_def_id(item.hir_id())
373373
&& Inherited::build(cx.tcx, local_def_id).enter(|inherited| {
374-
let fn_ctxt = FnCtxt::new(inherited, cx.param_env, item.hir_id());
374+
let fn_ctxt = FnCtxt::new(inherited, cx.param_env, local_def_id);
375375
fn_ctxt.can_coerce(ty, output_ty)
376376
}) {
377377
if has_lifetime(output_ty) && has_lifetime(ty) {

clippy_lints/src/missing_inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
155155
let container_id = assoc_item.container_id(cx.tcx);
156156
let trait_def_id = match assoc_item.container {
157157
TraitContainer => Some(container_id),
158-
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id),
158+
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
159159
};
160160

161161
if let Some(trait_def_id) = trait_def_id {

clippy_lints/src/missing_trait_methods.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods {
8080
}
8181
}
8282

83-
for assoc in provided.values() {
84-
let source_map = cx.tcx.sess.source_map();
85-
let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id));
83+
cx.tcx.with_stable_hashing_context(|hcx| {
84+
for assoc in provided.values_sorted(&hcx, true) {
85+
let source_map = cx.tcx.sess.source_map();
86+
let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id));
8687

87-
span_lint_and_help(
88-
cx,
89-
MISSING_TRAIT_METHODS,
90-
source_map.guess_head_span(item.span),
91-
&format!("missing trait method provided by default: `{}`", assoc.name),
92-
Some(definition_span),
93-
"implement the method",
94-
);
95-
}
88+
span_lint_and_help(
89+
cx,
90+
MISSING_TRAIT_METHODS,
91+
source_map.guess_head_span(item.span),
92+
&format!("missing trait method provided by default: `{}`", assoc.name),
93+
Some(definition_span),
94+
"implement the method",
95+
);
96+
}
97+
});
9698
}
9799
}
98100
}

clippy_lints/src/needless_pass_by_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_span::symbol::kw;
2424
use rustc_span::{sym, Span};
2525
use rustc_target::spec::abi::Abi;
2626
use rustc_trait_selection::traits;
27-
use rustc_trait_selection::traits::misc::can_type_implement_copy;
27+
use rustc_trait_selection::traits::misc::type_allowed_to_implement_copy;
2828
use std::borrow::Cow;
2929

3030
declare_clippy_lint! {
@@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
200200
let sugg = |diag: &mut Diagnostic| {
201201
if let ty::Adt(def, ..) = ty.kind() {
202202
if let Some(span) = cx.tcx.hir().span_if_local(def.did()) {
203-
if can_type_implement_copy(
203+
if type_allowed_to_implement_copy(
204204
cx.tcx,
205205
cx.param_env,
206206
ty,

clippy_lints/src/non_send_fields_in_send_ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
9090
if send_trait == trait_id;
9191
if hir_impl.polarity == ImplPolarity::Positive;
9292
if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
93-
if let self_ty = ty_trait_ref.self_ty();
93+
if let self_ty = ty_trait_ref.subst_identity().self_ty();
9494
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
9595
then {
9696
let mut non_send_fields = Vec::new();

clippy_lints/src/only_used_in_recursion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
77
use rustc_hir::hir_id::HirIdMap;
88
use rustc_hir::{Body, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Node, PatKind, TraitItem, TraitItemKind};
99
use rustc_lint::{LateContext, LateLintPass};
10-
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
10+
use rustc_middle::ty::subst::{EarlyBinder, GenericArgKind, SubstsRef};
1111
use rustc_middle::ty::{self, ConstKind};
1212
use rustc_session::{declare_tool_lint, impl_lint_pass};
1313
use rustc_span::symbol::{kw, Ident};
@@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
244244
})) => {
245245
#[allow(trivial_casts)]
246246
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
247-
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
247+
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::subst_identity)
248248
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
249249
{
250250
(

clippy_lints/src/pass_by_ref_or_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ impl<'tcx> PassByRefOrValue {
190190
// Don't lint if an unsafe pointer is created.
191191
// TODO: Limit the check only to unsafe pointers to the argument (or part of the argument)
192192
// which escape the current function.
193-
if typeck.node_types().iter().any(|(_, &ty)| ty.is_unsafe_ptr())
193+
if typeck.node_types().items().any(|(_, &ty)| ty.is_unsafe_ptr())
194194
|| typeck
195195
.adjustments()
196-
.iter()
196+
.items()
197197
.flat_map(|(_, a)| a)
198198
.any(|a| matches!(a.kind, Adjust::Pointer(PointerCast::UnsafeFnPointer)))
199199
{

clippy_lints/src/transmute/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(super) fn check_cast<'tcx>(
3434
let local_def_id = hir_id.owner.def_id;
3535

3636
Inherited::build(cx.tcx, local_def_id).enter(|inherited| {
37-
let fn_ctxt = FnCtxt::new(inherited, cx.param_env, hir_id);
37+
let fn_ctxt = FnCtxt::new(inherited, cx.param_env, local_def_id);
3838

3939
// If we already have errors, we can't be sure we can pointer cast.
4040
assert!(

clippy_lints/src/use_self.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
137137
then {
138138
// `self_ty` is the semantic self type of `impl <trait> for <type>`. This cannot be
139139
// `Self`.
140-
let self_ty = impl_trait_ref.self_ty();
140+
let self_ty = impl_trait_ref.subst_identity().self_ty();
141141

142142
// `trait_method_sig` is the signature of the function, how it is declared in the
143143
// trait, not in the impl of the trait.

clippy_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_utils"
3-
version = "0.1.68"
3+
version = "0.1.69"
44
edition = "2021"
55
publish = false
66

clippy_utils/src/macros.rs

+32-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#![allow(clippy::similar_names)] // `expr` and `expn`
22

3-
use crate::is_path_diagnostic_item;
43
use crate::source::snippet_opt;
54
use crate::visitors::{for_each_expr, Descend};
65

76
use arrayvec::ArrayVec;
87
use itertools::{izip, Either, Itertools};
98
use rustc_ast::ast::LitKind;
109
use rustc_hir::intravisit::{walk_expr, Visitor};
11-
use rustc_hir::{self as hir, Expr, ExprField, ExprKind, HirId, Node, QPath};
10+
use rustc_hir::{self as hir, Expr, ExprField, ExprKind, HirId, LangItem, Node, QPath, TyKind};
1211
use rustc_lexer::unescape::unescape_literal;
1312
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
1413
use rustc_lint::LateContext;
@@ -439,8 +438,7 @@ impl<'tcx> FormatArgsValues<'tcx> {
439438
// ArgumentV1::from_usize(<val>)
440439
if let ExprKind::Call(callee, [val]) = expr.kind
441440
&& let ExprKind::Path(QPath::TypeRelative(ty, _)) = callee.kind
442-
&& let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind
443-
&& path.segments.last().unwrap().ident.name == sym::ArgumentV1
441+
&& let TyKind::Path(QPath::LangItem(LangItem::FormatArgument, _, _)) = ty.kind
444442
{
445443
let val_idx = if val.span.ctxt() == expr.span.ctxt()
446444
&& let ExprKind::Field(_, field) = val.kind
@@ -486,20 +484,6 @@ struct ParamPosition {
486484

487485
impl<'tcx> Visitor<'tcx> for ParamPosition {
488486
fn visit_expr_field(&mut self, field: &'tcx ExprField<'tcx>) {
489-
fn parse_count(expr: &Expr<'_>) -> Option<usize> {
490-
// ::core::fmt::rt::v1::Count::Param(1usize),
491-
if let ExprKind::Call(ctor, [val]) = expr.kind
492-
&& let ExprKind::Path(QPath::Resolved(_, path)) = ctor.kind
493-
&& path.segments.last()?.ident.name == sym::Param
494-
&& let ExprKind::Lit(lit) = &val.kind
495-
&& let LitKind::Int(pos, _) = lit.node
496-
{
497-
Some(pos as usize)
498-
} else {
499-
None
500-
}
501-
}
502-
503487
match field.ident.name {
504488
sym::position => {
505489
if let ExprKind::Lit(lit) = &field.expr.kind
@@ -519,15 +503,41 @@ impl<'tcx> Visitor<'tcx> for ParamPosition {
519503
}
520504
}
521505

506+
fn parse_count(expr: &Expr<'_>) -> Option<usize> {
507+
// <::core::fmt::rt::v1::Count>::Param(1usize),
508+
if let ExprKind::Call(ctor, [val]) = expr.kind
509+
&& let ExprKind::Path(QPath::TypeRelative(_, path)) = ctor.kind
510+
&& path.ident.name == sym::Param
511+
&& let ExprKind::Lit(lit) = &val.kind
512+
&& let LitKind::Int(pos, _) = lit.node
513+
{
514+
Some(pos as usize)
515+
} else {
516+
None
517+
}
518+
}
519+
522520
/// Parses the `fmt` arg of `Arguments::new_v1_formatted(pieces, args, fmt, _)`
523521
fn parse_rt_fmt<'tcx>(fmt_arg: &'tcx Expr<'tcx>) -> Option<impl Iterator<Item = ParamPosition> + 'tcx> {
524522
if let ExprKind::AddrOf(.., array) = fmt_arg.kind
525523
&& let ExprKind::Array(specs) = array.kind
526524
{
527525
Some(specs.iter().map(|spec| {
528-
let mut position = ParamPosition::default();
529-
position.visit_expr(spec);
530-
position
526+
if let ExprKind::Call(f, args) = spec.kind
527+
&& let ExprKind::Path(QPath::TypeRelative(ty, f)) = f.kind
528+
&& let TyKind::Path(QPath::LangItem(LangItem::FormatPlaceholder, _, _)) = ty.kind
529+
&& f.ident.name == sym::new
530+
&& let [position, _fill, _align, _flags, precision, width] = args
531+
&& let ExprKind::Lit(position) = &position.kind
532+
&& let LitKind::Int(position, _) = position.node {
533+
ParamPosition {
534+
value: position as usize,
535+
width: parse_count(width),
536+
precision: parse_count(precision),
537+
}
538+
} else {
539+
ParamPosition::default()
540+
}
531541
}))
532542
} else {
533543
None
@@ -890,7 +900,7 @@ impl<'tcx> FormatArgsExpn<'tcx> {
890900
// ::core::fmt::Arguments::new_v1_formatted(pieces, args, fmt, _unsafe_arg)
891901
if let ExprKind::Call(callee, [pieces, args, rest @ ..]) = expr.kind
892902
&& let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind
893-
&& is_path_diagnostic_item(cx, ty, sym::Arguments)
903+
&& let TyKind::Path(QPath::LangItem(LangItem::FormatArguments, _, _)) = ty.kind
894904
&& matches!(seg.ident.as_str(), "new_v1" | "new_v1_formatted")
895905
{
896906
let format_string = FormatString::new(cx, pieces)?;

clippy_utils/src/sugg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ impl<'a> Sugg<'a> {
219219
| ast::ExprKind::Repeat(..)
220220
| ast::ExprKind::Ret(..)
221221
| ast::ExprKind::Yeet(..)
222+
| ast::ExprKind::FormatArgs(..)
222223
| ast::ExprKind::Struct(..)
223224
| ast::ExprKind::Try(..)
224225
| ast::ExprKind::TryBlock(..)

0 commit comments

Comments
 (0)