Skip to content

Commit d822110

Browse files
committed
Auto merge of #10010 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 641ced4 + 4063712 commit d822110

39 files changed

+230
-219
lines changed

clippy_dev/src/setup/git_hook.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::verify_inside_clippy_dir;
66
/// Rusts setup uses `git rev-parse --git-common-dir` to get the root directory of the repo.
77
/// I've decided against this for the sake of simplicity and to make sure that it doesn't install
88
/// the hook if `clippy_dev` would be used in the rust tree. The hook also references this tool
9-
/// for formatting and should therefor only be used in a normal clone of clippy
9+
/// for formatting and should therefore only be used in a normal clone of clippy
1010
const REPO_GIT_DIR: &str = ".git";
1111
const HOOK_SOURCE_FILE: &str = "util/etc/pre-commit.sh";
1212
const HOOK_TARGET_FILE: &str = ".git/hooks/pre-commit";

clippy_lints/src/attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::macros::{is_panic, macro_backtrace};
55
use clippy_utils::msrvs::{self, Msrv};
66
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
77
use if_chain::if_chain;
8-
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
8+
use rustc_ast::{AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem};
99
use rustc_errors::Applicability;
1010
use rustc_hir::{
1111
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
@@ -574,7 +574,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut
574574
}
575575
}
576576

577-
fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) {
577+
fn check_semver(cx: &LateContext<'_>, span: Span, lit: &MetaItemLit) {
578578
if let LitKind::Str(is, _) = lit.kind {
579579
if Version::parse(is.as_str()).is_ok() {
580580
return;

clippy_lints/src/bool_assert_comparison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn is_impl_not_trait_with_bool_out(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
5959
)
6060
})
6161
.map_or(false, |assoc_item| {
62-
let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, &[]));
62+
let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, []));
6363
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
6464

6565
nty.is_bool()

clippy_lints/src/casts/cast_possible_truncation.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ use clippy_utils::consts::{constant, Constant};
22
use clippy_utils::diagnostics::span_lint;
33
use clippy_utils::expr_or_init;
44
use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize};
5-
use rustc_ast::ast;
6-
use rustc_attr::IntType;
75
use rustc_hir::def::{DefKind, Res};
86
use rustc_hir::{BinOpKind, Expr, ExprKind};
97
use rustc_lint::LateContext;
108
use rustc_middle::ty::{self, FloatTy, Ty};
9+
use rustc_target::abi::IntegerType;
1110

1211
use super::{utils, CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION};
1312

@@ -119,12 +118,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
119118
};
120119
let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx);
121120

122-
let cast_from_ptr_size = def.repr().int.map_or(true, |ty| {
123-
matches!(
124-
ty,
125-
IntType::SignedInt(ast::IntTy::Isize) | IntType::UnsignedInt(ast::UintTy::Usize)
126-
)
127-
});
121+
let cast_from_ptr_size = def.repr().int.map_or(true, |ty| matches!(ty, IntegerType::Pointer(_),));
128122
let suffix = match (cast_from_ptr_size, is_isize_or_usize(cast_to)) {
129123
(false, false) if from_nbits > to_nbits => "",
130124
(true, false) if from_nbits > to_nbits => "",

clippy_lints/src/crate_in_macro_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl EarlyLintPass for CrateInMacroDef {
5555
if_chain! {
5656
if item.attrs.iter().any(is_macro_export);
5757
if let ItemKind::MacroDef(macro_def) = &item.kind;
58-
let tts = macro_def.body.inner_tokens();
58+
let tts = macro_def.body.tokens.clone();
5959
if let Some(span) = contains_unhygienic_crate_reference(&tts);
6060
then {
6161
span_lint_and_sugg(

clippy_lints/src/dereference.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_lint::{LateContext, LateLintPass};
2626
use rustc_middle::mir::{Rvalue, StatementKind};
2727
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
2828
use rustc_middle::ty::{
29-
self, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
29+
self, Binder, BoundVariableKind, Clause, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
3030
ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults,
3131
};
3232
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -855,14 +855,10 @@ fn walk_parents<'tcx>(
855855
} else if let Some(trait_id) = cx.tcx.trait_of_item(id)
856856
&& let arg_ty = cx.tcx.erase_regions(cx.typeck_results().expr_ty_adjusted(e))
857857
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
858-
&& let subs = match cx
858+
&& let subs = cx
859859
.typeck_results()
860-
.node_substs_opt(parent.hir_id)
861-
.and_then(|subs| subs.get(1..))
862-
{
863-
Some(subs) => cx.tcx.mk_substs(subs.iter().copied()),
864-
None => cx.tcx.mk_substs(std::iter::empty::<ty::subst::GenericArg<'_>>()),
865-
} && let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() {
860+
.node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default()
861+
&& let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() {
866862
// Trait methods taking `&self`
867863
sub_ty
868864
} else {
@@ -871,7 +867,11 @@ fn walk_parents<'tcx>(
871867
} && impl_ty.is_ref()
872868
&& let infcx = cx.tcx.infer_ctxt().build()
873869
&& infcx
874-
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
870+
.type_implements_trait(
871+
trait_id,
872+
[impl_ty.into()].into_iter().chain(subs.iter().copied()),
873+
cx.param_env,
874+
)
875875
.must_apply_modulo_regions()
876876
{
877877
return Some(Position::MethodReceiverRefImpl)
@@ -1106,7 +1106,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11061106
let projection_predicates = predicates
11071107
.iter()
11081108
.filter_map(|predicate| {
1109-
if let PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
1109+
if let PredicateKind::Clause(Clause::Projection(projection_predicate)) = predicate.kind().skip_binder() {
11101110
Some(projection_predicate)
11111111
} else {
11121112
None
@@ -1120,7 +1120,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11201120
if predicates
11211121
.iter()
11221122
.filter_map(|predicate| {
1123-
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
1123+
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
11241124
&& trait_predicate.trait_ref.self_ty() == param_ty.to_ty(cx.tcx)
11251125
{
11261126
Some(trait_predicate.trait_ref.def_id)
@@ -1182,7 +1182,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11821182
}
11831183

11841184
predicates.iter().all(|predicate| {
1185-
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
1185+
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
11861186
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
11871187
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
11881188
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()
@@ -1333,7 +1333,7 @@ fn replace_types<'tcx>(
13331333
let item_def_id = projection_predicate.projection_ty.item_def_id;
13341334
let assoc_item = cx.tcx.associated_item(item_def_id);
13351335
let projection = cx.tcx
1336-
.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, &[]));
1336+
.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, []));
13371337

13381338
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
13391339
&& substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)

clippy_lints/src/derive.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::hir::nested_filter;
1515
use rustc_middle::traits::Reveal;
1616
use rustc_middle::ty::{
17-
self, Binder, BoundConstness, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef,
18-
Ty, TyCtxt,
17+
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate,
18+
TraitRef, Ty, TyCtxt,
1919
};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
2121
use rustc_span::source_map::Span;
@@ -466,12 +466,12 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
466466
if let Some(def_id) = trait_ref.trait_def_id();
467467
if cx.tcx.is_diagnostic_item(sym::PartialEq, def_id);
468468
let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id);
469-
if !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, &[]);
469+
if !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, []);
470470
// If all of our fields implement `Eq`, we can implement `Eq` too
471471
if adt
472472
.all_fields()
473473
.map(|f| f.ty(cx.tcx, substs))
474-
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, &[]));
474+
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, []));
475475
then {
476476
span_lint_and_sugg(
477477
cx,
@@ -499,7 +499,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
499499

500500
let ty_predicates = tcx.predicates_of(did).predicates;
501501
for (p, _) in ty_predicates {
502-
if let PredicateKind::Trait(p) = p.kind().skip_binder()
502+
if let PredicateKind::Clause(Clause::Trait(p)) = p.kind().skip_binder()
503503
&& p.trait_ref.def_id == eq_trait_id
504504
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
505505
&& p.constness == BoundConstness::NotConst
@@ -512,14 +512,14 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
512512
ParamEnv::new(
513513
tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
514514
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
515-
tcx.mk_predicate(Binder::dummy(PredicateKind::Trait(TraitPredicate {
515+
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
516516
trait_ref: TraitRef::new(
517517
eq_trait_id,
518518
tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))),
519519
),
520520
constness: BoundConstness::NotConst,
521521
polarity: ImplPolarity::Positive,
522-
})))
522+
}))))
523523
}),
524524
)),
525525
Reveal::UserFacing,

clippy_lints/src/doc.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,7 @@ fn lint_for_missing_headers(
427427
let body = cx.tcx.hir().body(body_id);
428428
let ret_ty = typeck.expr_ty(body.value);
429429
if implements_trait(cx, ret_ty, future, &[]);
430-
if let ty::Opaque(_, subs) = ret_ty.kind();
431-
if let Some(gen) = subs.types().next();
432-
if let ty::Generator(_, subs, _) = gen.kind();
430+
if let ty::Generator(_, subs, _) = ret_ty.kind();
433431
if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result);
434432
then {
435433
span_lint(

clippy_lints/src/eta_reduction.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,18 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
119119
let callee_ty_unadjusted = cx.typeck_results().expr_ty(callee).peel_refs();
120120
if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Arc);
121121
if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Rc);
122+
if let ty::Closure(_, substs) = *closure_ty.kind();
122123
then {
123124
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
124125
if let Some(mut snippet) = snippet_opt(cx, callee.span) {
125126
if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait()
126-
&& implements_trait(cx, callee_ty.peel_refs(), fn_mut_id, &[])
127+
&& let args = cx.tcx.erase_late_bound_regions(substs.as_closure().sig()).inputs()
128+
&& implements_trait(
129+
cx,
130+
callee_ty.peel_refs(),
131+
fn_mut_id,
132+
&args.iter().copied().map(Into::into).collect::<Vec<_>>(),
133+
)
127134
&& path_to_local(callee).map_or(false, |l| local_used_after_expr(cx, l, expr))
128135
{
129136
// Mutable closure is used after current expr; we cannot consume it.

clippy_lints/src/future_not_send.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
44
use rustc_hir::{Body, FnDecl, HirId};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
7+
use rustc_middle::ty::{Clause, EarlyBinder, Opaque, PredicateKind};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::{sym, Span};
1010
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
@@ -91,7 +91,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9191
infcx
9292
.err_ctxt()
9393
.maybe_note_obligation_cause_for_async_await(db, &obligation);
94-
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
94+
if let PredicateKind::Clause(Clause::Trait(trait_pred)) =
95+
obligation.predicate.kind().skip_binder()
96+
{
9597
db.note(&format!(
9698
"`{}` doesn't implement `{}`",
9799
trait_pred.self_ty(),

clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
extern crate rustc_arena;
2727
extern crate rustc_ast;
2828
extern crate rustc_ast_pretty;
29-
extern crate rustc_attr;
3029
extern crate rustc_data_structures;
3130
extern crate rustc_driver;
3231
extern crate rustc_errors;

clippy_lints/src/lifetimes.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_hir::lang_items;
1010
use rustc_hir::FnRetTy::Return;
1111
use rustc_hir::{
1212
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
13-
ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, TraitFn, TraitItem,
14-
TraitItemKind, Ty, TyKind, WherePredicate,
13+
ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, LifetimeParamKind, PolyTraitRef, PredicateOrigin, TraitFn,
14+
TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
1515
};
1616
use rustc_lint::{LateContext, LateLintPass};
1717
use rustc_middle::hir::nested_filter as middle_nested_filter;
@@ -180,7 +180,7 @@ fn check_fn_inner<'tcx>(
180180
_ => None,
181181
});
182182
for bound in lifetimes {
183-
if bound.name != LifetimeName::Static && !bound.is_elided() {
183+
if !bound.is_static() && !bound.is_elided() {
184184
return;
185185
}
186186
}
@@ -414,17 +414,13 @@ impl<'a, 'tcx> RefVisitor<'a, 'tcx> {
414414

415415
fn record(&mut self, lifetime: &Option<Lifetime>) {
416416
if let Some(ref lt) = *lifetime {
417-
if lt.name == LifetimeName::Static {
417+
if lt.is_static() {
418418
self.lts.push(RefLt::Static);
419-
} else if let LifetimeName::Param(_, ParamName::Fresh) = lt.name {
419+
} else if lt.is_anonymous() {
420420
// Fresh lifetimes generated should be ignored.
421421
self.lts.push(RefLt::Unnamed);
422-
} else if lt.is_elided() {
423-
self.lts.push(RefLt::Unnamed);
424-
} else if let LifetimeName::Param(def_id, _) = lt.name {
422+
} else if let LifetimeName::Param(def_id) = lt.res {
425423
self.lts.push(RefLt::Named(def_id));
426-
} else {
427-
self.lts.push(RefLt::Unnamed);
428424
}
429425
} else {
430426
self.lts.push(RefLt::Unnamed);
@@ -472,7 +468,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
472468
walk_item(self, item);
473469
self.lts.truncate(len);
474470
self.lts.extend(bounds.iter().filter_map(|bound| match bound {
475-
GenericArg::Lifetime(l) => Some(if let LifetimeName::Param(def_id, _) = l.name {
471+
GenericArg::Lifetime(l) => Some(if let LifetimeName::Param(def_id) = l.res {
476472
RefLt::Named(def_id)
477473
} else {
478474
RefLt::Unnamed
@@ -498,10 +494,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
498494
}
499495

500496
fn visit_generic_arg(&mut self, generic_arg: &'tcx GenericArg<'tcx>) {
501-
if let GenericArg::Lifetime(l) = generic_arg
502-
&& let LifetimeName::Param(def_id, _) = l.name
503-
{
504-
self.lifetime_generic_arg_spans.entry(def_id).or_insert(l.span);
497+
if let GenericArg::Lifetime(l) = generic_arg && let LifetimeName::Param(def_id) = l.res {
498+
self.lifetime_generic_arg_spans.entry(def_id).or_insert(l.ident.span);
505499
}
506500
walk_generic_arg(self, generic_arg);
507501
}
@@ -570,7 +564,7 @@ where
570564

571565
// for lifetimes as parameters of generics
572566
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
573-
self.map.remove(&lifetime.name.ident().name);
567+
self.map.remove(&lifetime.ident.name);
574568
}
575569

576570
fn visit_generic_param(&mut self, param: &'tcx GenericParam<'_>) {
@@ -594,7 +588,9 @@ fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>,
594588
.params
595589
.iter()
596590
.filter_map(|par| match par.kind {
597-
GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)),
591+
GenericParamKind::Lifetime {
592+
kind: LifetimeParamKind::Explicit,
593+
} => Some((par.name.ident().name, par.span)),
598594
_ => None,
599595
})
600596
.collect();
@@ -619,7 +615,9 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'
619615
.params
620616
.iter()
621617
.filter_map(|par| match par.kind {
622-
GenericParamKind::Lifetime { .. } => Some((par.name.ident().name, par.span)),
618+
GenericParamKind::Lifetime {
619+
kind: LifetimeParamKind::Explicit,
620+
} => Some((par.name.ident().name, par.span)),
623621
_ => None,
624622
})
625623
.collect();
@@ -646,7 +644,7 @@ struct BodyLifetimeChecker {
646644
impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker {
647645
// for lifetimes as parameters of generics
648646
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
649-
if lifetime.name.ident().name != kw::UnderscoreLifetime && lifetime.name.ident().name != kw::StaticLifetime {
647+
if !lifetime.is_anonymous() && lifetime.ident.name != kw::StaticLifetime {
650648
self.lifetimes_used_in_body = true;
651649
}
652650
}

0 commit comments

Comments
 (0)