Skip to content

Commit ea988af

Browse files
committed
Auto merge of rust-lang#83484 - JulianKnodt:infer, r=oli-obk,lcnr
Add hir::GenericArg::Infer In order to extend inference to consts, make an Infer type on hir::GenericArg.
2 parents 1270ed0 + 74379d4 commit ea988af

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

clippy_lints/src/implicit_hasher.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::BTreeMap;
55

66
use rustc_errors::DiagnosticBuilder;
77
use rustc_hir as hir;
8-
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, NestedVisitorMap, Visitor};
8+
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, walk_inf, NestedVisitorMap, Visitor};
99
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::hir::map::Map;
@@ -295,6 +295,14 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> {
295295
walk_ty(self, t);
296296
}
297297

298+
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
299+
if let Some(target) = ImplicitHasherType::new(self.cx, &inf.to_ty()) {
300+
self.found.push(target);
301+
}
302+
303+
walk_inf(self, inf);
304+
}
305+
298306
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
299307
NestedVisitorMap::None
300308
}

clippy_lints/src/types/type_complexity.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint;
22
use rustc_hir as hir;
3-
use rustc_hir::intravisit::{walk_ty, NestedVisitorMap, Visitor};
3+
use rustc_hir::intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor};
44
use rustc_hir::{GenericParamKind, TyKind};
55
use rustc_lint::LateContext;
66
use rustc_middle::hir::map::Map;
@@ -39,6 +39,11 @@ struct TypeComplexityVisitor {
3939
impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
4040
type Map = Map<'tcx>;
4141

42+
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
43+
self.score += 1;
44+
walk_inf(self, inf);
45+
}
46+
4247
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
4348
let (add_score, sub_nest) = match ty.kind {
4449
// _, &x and *x have only small overhead; don't mess with nesting level

clippy_lints/src/use_self.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use rustc_hir::{
88
self as hir,
99
def::{CtorOf, DefKind, Res},
1010
def_id::LocalDefId,
11-
intravisit::{walk_ty, NestedVisitorMap, Visitor},
12-
Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind,
11+
intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor},
12+
Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path,
13+
QPath, TyKind,
1314
};
1415
use rustc_lint::{LateContext, LateLintPass, LintContext};
1516
use rustc_middle::hir::map::Map;
@@ -263,6 +264,11 @@ struct SkipTyCollector {
263264
impl<'tcx> Visitor<'tcx> for SkipTyCollector {
264265
type Map = Map<'tcx>;
265266

267+
fn visit_infer(&mut self, inf: &hir::InferArg) {
268+
self.types_to_skip.push(inf.hir_id);
269+
270+
walk_inf(self, inf)
271+
}
266272
fn visit_ty(&mut self, hir_ty: &hir::Ty<'_>) {
267273
self.types_to_skip.push(hir_ty.hir_id);
268274

clippy_utils/src/hir_utils.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ impl HirEqInterExpr<'_, '_, '_> {
288288
(GenericArg::Const(l), GenericArg::Const(r)) => self.eq_body(l.value.body, r.value.body),
289289
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt),
290290
(GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
291+
(GenericArg::Infer(l_inf), GenericArg::Infer(r_inf)) =>
292+
self.eq_ty(&l_inf.to_ty(), &r_inf.to_ty()),
291293
_ => false,
292294
}
293295
}
@@ -885,7 +887,11 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
885887

886888
pub fn hash_ty(&mut self, ty: &Ty<'_>) {
887889
std::mem::discriminant(&ty.kind).hash(&mut self.s);
888-
match ty.kind {
890+
self.hash_tykind(&ty.kind);
891+
}
892+
893+
pub fn hash_tykind(&mut self, ty: &TyKind<'_>) {
894+
match ty {
889895
TyKind::Slice(ty) => {
890896
self.hash_ty(ty);
891897
},
@@ -898,7 +904,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
898904
mut_ty.mutbl.hash(&mut self.s);
899905
},
900906
TyKind::Rptr(lifetime, ref mut_ty) => {
901-
self.hash_lifetime(lifetime);
907+
self.hash_lifetime(*lifetime);
902908
self.hash_ty(mut_ty.ty);
903909
mut_ty.mutbl.hash(&mut self.s);
904910
},
@@ -918,7 +924,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
918924
bfn.decl.c_variadic.hash(&mut self.s);
919925
},
920926
TyKind::Tup(ty_list) => {
921-
for ty in ty_list {
927+
for ty in *ty_list {
922928
self.hash_ty(ty);
923929
}
924930
},
@@ -927,7 +933,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
927933
self.hash_generic_args(arg_list);
928934
},
929935
TyKind::TraitObject(_, lifetime, _) => {
930-
self.hash_lifetime(lifetime);
936+
self.hash_lifetime(*lifetime);
931937
},
932938
TyKind::Typeof(anon_const) => {
933939
self.hash_body(anon_const.body);
@@ -949,6 +955,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
949955
GenericArg::Lifetime(l) => self.hash_lifetime(l),
950956
GenericArg::Type(ref ty) => self.hash_ty(ty),
951957
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
958+
GenericArg::Infer(ref inf) => self.hash_ty(&inf.to_ty()),
952959
}
953960
}
954961
}

clippy_utils/src/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
180180
}
181181

182182
// FIXME: Per https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/infer/at/struct.At.html#method.normalize
183-
// this function can be removed once the `normalizie` method does not panic when normalization does
183+
// this function can be removed once the `normalize` method does not panic when normalization does
184184
// not succeed
185185
/// Checks if `Ty` is normalizable. This function is useful
186186
/// to avoid crashes on `layout_of`.

0 commit comments

Comments
 (0)