Skip to content

Commit ff4a26d

Browse files
authored
r? @ghost changelog: none
2 parents 5dc5842 + 5fb924f commit ff4a26d

Some content is hidden

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

63 files changed

+265
-237
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy"
33
# begin autogenerated version
4-
version = "0.1.84"
4+
version = "0.1.85"
55
# end autogenerated version
66
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
77
repository = "https://github.com/rust-lang/rust-clippy"
@@ -29,7 +29,7 @@ rustc_tools_util = "0.4.0"
2929
tempfile = { version = "3.3", optional = true }
3030
termize = "0.1"
3131
color-print = "0.3.4"
32-
anstream = "0.6.0"
32+
anstream = "0.6.18"
3333

3434
[dev-dependencies]
3535
cargo_metadata = "0.18.1"

clippy_config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_config"
33
# begin autogenerated version
4-
version = "0.1.84"
4+
version = "0.1.85"
55
# end autogenerated version
66
edition = "2021"
77
publish = false

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin autogenerated version
4-
version = "0.1.84"
4+
version = "0.1.85"
55
# end autogenerated version
66
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
77
repository = "https://github.com/rust-lang/rust-clippy"

clippy_lints/src/assigning_clones.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
9696
},
9797
_ => return,
9898
}
99-
&& let Ok(Some(resolved_fn)) = Instance::try_resolve(cx.tcx, cx.param_env, fn_id, fn_gen_args)
99+
&& let Ok(Some(resolved_fn)) = Instance::try_resolve(cx.tcx, cx.typing_env(), fn_id, fn_gen_args)
100100
// TODO: This check currently bails if the local variable has no initializer.
101101
// That is overly conservative - the lint should fire even if there was no initializer,
102102
// but the variable has been initialized before `lhs` was evaluated.

clippy_lints/src/bool_assert_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
6262
})
6363
.is_some_and(|assoc_item| {
6464
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
65-
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
65+
let nty = cx.tcx.normalize_erasing_regions(cx.typing_env(), proj);
6666

6767
nty.is_bool()
6868
})

clippy_lints/src/casts/ptr_as_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {
3939
(Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut))
4040
// The `U` in `pointer::cast` have to be `Sized`
4141
// as explained here: https://github.com/rust-lang/rust/issues/60602.
42-
&& to_pointee_ty.is_sized(cx.tcx, cx.param_env)
42+
&& to_pointee_ty.is_sized(cx.tcx, cx.typing_env())
4343
{
4444
let mut app = Applicability::MachineApplicable;
4545
let turbofish = match &cast_to_hir_ty.kind {

clippy_lints/src/dereference.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ use core::mem;
1010
use rustc_ast::util::parser::{PREC_PREFIX, PREC_UNAMBIGUOUS};
1111
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_errors::Applicability;
13+
use rustc_hir::def_id::DefId;
1314
use rustc_hir::intravisit::{Visitor, walk_ty};
1415
use rustc_hir::{
1516
self as hir, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, Pat,
1617
PatKind, Path, QPath, TyKind, UnOp,
1718
};
1819
use rustc_lint::{LateContext, LateLintPass};
1920
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
20-
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeVisitableExt, TypeckResults};
21+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypeckResults};
2122
use rustc_session::impl_lint_pass;
2223
use rustc_span::symbol::sym;
2324
use rustc_span::{Span, Symbol};
@@ -753,10 +754,10 @@ impl TyCoercionStability {
753754
fn for_defined_ty<'tcx>(cx: &LateContext<'tcx>, ty: DefinedTy<'tcx>, for_return: bool) -> Self {
754755
match ty {
755756
DefinedTy::Hir(ty) => Self::for_hir_ty(ty),
756-
DefinedTy::Mir(ty) => Self::for_mir_ty(
757+
DefinedTy::Mir { def_site_def_id, ty } => Self::for_mir_ty(
757758
cx.tcx,
758-
ty.param_env,
759-
cx.tcx.instantiate_bound_regions_with_erased(ty.value),
759+
def_site_def_id,
760+
cx.tcx.instantiate_bound_regions_with_erased(ty),
760761
for_return,
761762
),
762763
}
@@ -823,12 +824,15 @@ impl TyCoercionStability {
823824
}
824825
}
825826

826-
fn for_mir_ty<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, for_return: bool) -> Self {
827+
fn for_mir_ty<'tcx>(tcx: TyCtxt<'tcx>, def_site_def_id: Option<DefId>, ty: Ty<'tcx>, for_return: bool) -> Self {
827828
let ty::Ref(_, mut ty, _) = *ty.kind() else {
828829
return Self::None;
829830
};
830831

831-
ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty);
832+
if let Some(def_id) = def_site_def_id {
833+
let typing_env = ty::TypingEnv::non_body_analysis(tcx, def_id);
834+
ty = tcx.try_normalize_erasing_regions(typing_env, ty).unwrap_or(ty);
835+
}
832836
loop {
833837
break match *ty.kind() {
834838
ty::Ref(_, ref_ty, _) => {
@@ -959,7 +963,7 @@ fn report<'tcx>(
959963
// expr_str (the suggestion) is never shown if is_final_ufcs is true, since it's
960964
// `expr.kind == ExprKind::Call`. Therefore, this is, afaik, always unnecessary.
961965
/*
962-
expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence().order() < PREC_PREFIX {
966+
expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence() < PREC_PREFIX {
963967
Cow::Owned(format!("({expr_str})"))
964968
} else {
965969
expr_str
@@ -999,7 +1003,7 @@ fn report<'tcx>(
9991003
Node::Expr(e) => match e.kind {
10001004
ExprKind::Call(callee, _) if callee.hir_id != data.first_expr.hir_id => (0, false),
10011005
ExprKind::Call(..) => (PREC_UNAMBIGUOUS, matches!(expr.kind, ExprKind::Field(..))),
1002-
_ => (e.precedence().order(), false),
1006+
_ => (e.precedence(), false),
10031007
},
10041008
_ => (0, false),
10051009
};
@@ -1012,7 +1016,7 @@ fn report<'tcx>(
10121016
);
10131017

10141018
let sugg = if !snip_is_macro
1015-
&& (calls_field || expr.precedence().order() < precedence)
1019+
&& (calls_field || expr.precedence() < precedence)
10161020
&& !has_enclosing_paren(&snip)
10171021
&& !is_in_tuple
10181022
{
@@ -1027,7 +1031,7 @@ fn report<'tcx>(
10271031
State::ExplicitDeref { mutability } => {
10281032
if is_block_like(expr)
10291033
&& let ty::Ref(_, ty, _) = data.adjusted_ty.kind()
1030-
&& ty.is_sized(cx.tcx, cx.param_env)
1034+
&& ty.is_sized(cx.tcx, cx.typing_env())
10311035
{
10321036
// Rustc bug: auto deref doesn't work on block expression when targeting sized types.
10331037
return;
@@ -1066,12 +1070,11 @@ fn report<'tcx>(
10661070
let mut app = Applicability::MachineApplicable;
10671071
let (snip, snip_is_macro) =
10681072
snippet_with_context(cx, expr.span, data.first_expr.span.ctxt(), "..", &mut app);
1069-
let sugg =
1070-
if !snip_is_macro && expr.precedence().order() < precedence && !has_enclosing_paren(&snip) {
1071-
format!("{prefix}({snip})")
1072-
} else {
1073-
format!("{prefix}{snip}")
1074-
};
1073+
let sugg = if !snip_is_macro && expr.precedence() < precedence && !has_enclosing_paren(&snip) {
1074+
format!("{prefix}({snip})")
1075+
} else {
1076+
format!("{prefix}{snip}")
1077+
};
10751078
diag.span_suggestion(data.first_expr.span, "try", sugg, app);
10761079
},
10771080
);
@@ -1154,7 +1157,7 @@ impl<'tcx> Dereferencing<'tcx> {
11541157
},
11551158
Some(parent) if !parent.span.from_expansion() => {
11561159
// Double reference might be needed at this point.
1157-
if parent.precedence().order() == PREC_UNAMBIGUOUS {
1160+
if parent.precedence() == PREC_UNAMBIGUOUS {
11581161
// Parentheses would be needed here, don't lint.
11591162
*outer_pat = None;
11601163
} else {

clippy_lints/src/derive.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::{
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_middle::hir::nested_filter;
14-
use rustc_middle::traits::Reveal;
1514
use rustc_middle::ty::{
1615
self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, TraitPredicate, Ty, TyCtxt, Upcast,
1716
};
@@ -454,13 +453,13 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
454453
&& cx.tcx.is_diagnostic_item(sym::PartialEq, def_id)
455454
&& !has_non_exhaustive_attr(cx.tcx, *adt)
456455
&& !ty_implements_eq_trait(cx.tcx, ty, eq_trait_def_id)
457-
&& let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id)
456+
&& let typing_env = typing_env_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id)
458457
&& let Some(local_def_id) = adt.did().as_local()
459458
// If all of our fields implement `Eq`, we can implement `Eq` too
460459
&& adt
461460
.all_fields()
462461
.map(|f| f.ty(cx.tcx, args))
463-
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[]))
462+
.all(|ty| implements_trait_with_env(cx.tcx, typing_env, ty, eq_trait_def_id, None, &[]))
464463
{
465464
span_lint_hir_and_then(
466465
cx,
@@ -485,7 +484,7 @@ fn ty_implements_eq_trait<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, eq_trait_id: De
485484
}
486485

487486
/// Creates the `ParamEnv` used for the give type's derived `Eq` impl.
488-
fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ParamEnv<'_> {
487+
fn typing_env_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ty::TypingEnv<'_> {
489488
// Initial map from generic index to param def.
490489
// Vec<(param_def, needs_eq)>
491490
let mut params = tcx
@@ -506,16 +505,17 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
506505
}
507506
}
508507

509-
ParamEnv::new(
510-
tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
511-
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
512-
ClauseKind::Trait(TraitPredicate {
513-
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
514-
polarity: ty::PredicatePolarity::Positive,
515-
})
516-
.upcast(tcx)
517-
}),
518-
)),
519-
Reveal::UserFacing,
520-
)
508+
let param_env = ParamEnv::new(tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
509+
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
510+
ClauseKind::Trait(TraitPredicate {
511+
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
512+
polarity: ty::PredicatePolarity::Positive,
513+
})
514+
.upcast(tcx)
515+
}),
516+
)));
517+
ty::TypingEnv {
518+
typing_mode: ty::TypingMode::non_body_analysis(),
519+
param_env,
520+
}
521521
}

clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
9999
sym::mem_forget if is_copy => return,
100100
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => return,
101101
sym::mem_drop
102-
if !(arg_ty.needs_drop(cx.tcx, cx.param_env)
102+
if !(arg_ty.needs_drop(cx.tcx, cx.typing_env())
103103
|| is_must_use_func_call(cx, arg)
104104
|| is_must_use_ty(cx, arg_ty)
105105
|| drop_is_single_call_in_arm) =>
106106
{
107107
(DROP_NON_DROP, DROP_NON_DROP_SUMMARY.into(), Some(arg.span))
108108
},
109109
sym::mem_forget => {
110-
if arg_ty.needs_drop(cx.tcx, cx.param_env) {
110+
if arg_ty.needs_drop(cx.tcx, cx.typing_env()) {
111111
(
112112
MEM_FORGET,
113113
Cow::Owned(format!(

clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::intravisit::{Visitor, walk_impl_item, walk_item, walk_param_bound, walk_ty};
77
use rustc_hir::{
88
BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind,
9-
PredicateOrigin, Ty, WherePredicate,
9+
PredicateOrigin, Ty, WherePredicate, WherePredicateKind,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::hir::nested_filter;
@@ -205,12 +205,13 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
205205
}
206206

207207
fn visit_where_predicate(&mut self, predicate: &'tcx WherePredicate<'tcx>) {
208-
if let WherePredicate::BoundPredicate(predicate) = predicate {
208+
let span = predicate.span;
209+
if let WherePredicateKind::BoundPredicate(predicate) = predicate.kind {
209210
// Collect spans for any bounds on type parameters.
210211
if let Some((def_id, _)) = predicate.bounded_ty.peel_refs().as_generic_param() {
211212
match predicate.origin {
212213
PredicateOrigin::GenericParam => {
213-
self.inline_bounds.insert(def_id, predicate.span);
214+
self.inline_bounds.insert(def_id, span);
214215
},
215216
PredicateOrigin::WhereClause => {
216217
self.where_bounds.insert(def_id);

0 commit comments

Comments
 (0)