Skip to content

Commit 6180622

Browse files
committed
Auto merge of #135272 - BoxyUwU:generic_arg_infer_reliability_2, r=compiler-errors
Forbid usage of `hir` `Infer` const/ty variants in ambiguous contexts The feature `generic_arg_infer` allows providing `_` as an argument to const generics in order to infer them. This introduces a syntactic ambiguity as to whether generic arguments are type or const arguments. In order to get around this we introduced a fourth `GenericArg` variant, `Infer` used to represent `_` as an argument to generic parameters when we don't know if its a type or a const argument. This made hir visitors that care about `TyKind::Infer` or `ConstArgKind::Infer` very error prone as checking for `TyKind::Infer`s in `visit_ty` would find *some* type infer arguments but not *all* of them as they would sometimes be lowered to `GenericArg::Infer` instead. Additionally the `visit_infer` method would previously only visit `GenericArg::Infer` not *all* infers (e.g. `TyKind::Infer`), this made it very easy to override `visit_infer` and expect it to visit all infers when in reality it would only visit *some* infers. --- This PR aims to fix those issues by making the `TyKind` and `ConstArgKind` types generic over whether the infer types/consts are represented by `Ty/ConstArgKind::Infer` or out of line (e.g. by a `GenericArg::Infer` or accessible by overiding `visit_infer`). We then make HIR Visitors convert all const args and types to the versions where infer vars are stored out of line and call `visit_infer` in cases where a `Ty`/`Const` would previously have had a `Ty/ConstArgKind::Infer` variant: API Summary ```rust enum AmbigArg {} enum Ty/ConstArgKind<Unambig = ()> { ... Infer(Unambig), } impl Ty/ConstArg { fn try_as_ambig_ty/ct(self) -> Option<Ty/ConstArg<AmbigArg>>; } impl Ty/ConstArg<AmbigArg> { fn as_unambig_ty/ct(self) -> Ty/ConstArg; } enum InferKind { Ty(Ty), Const(ConstArg), Ambig(InferArg), } trait Visitor { ... fn visit_ty/const_arg(&mut self, Ty/ConstArg<AmbigArg>) -> Self::Result; fn visit_infer(&mut self, id: HirId, sp: Span, kind: InferKind) -> Self::Result; } // blanket impl'd, not meant to be overriden trait VisitorExt { fn visit_ty/const_arg_unambig(&mut self, Ty/ConstArg) -> Self::Result; } fn walk_unambig_ty/const_arg(&mut V, Ty/ConstArg) -> Self::Result; fn walk_ty/const_arg(&mut V, Ty/ConstArg<AmbigArg>) -> Self::Result; ``` The end result is that `visit_infer` visits *all* infer args and is also the *only* way to visit an infer arg, `visit_ty` and `visit_const_arg` can now no longer encounter a `Ty/ConstArgKind::Infer`. Representing this in the type system means that it is now very difficult to mess things up, either accessing `TyKind::Infer` "just works" and you won't miss *some* type infers- or it doesn't work and you have to look at `visit_infer` or some `GenericArg::Infer` which forces you to think about the full complexity involved. Unfortunately there is no lint right now about explicitly matching on uninhabited variants, I can't find the context for why this is the case 🤷‍♀️ I'm not convinced the framing of un/ambig ty/consts is necessarily the right one but I'm not sure what would be better. I somewhat like calling them full/partial types based on the fact that `Ty<Partial>`/`Ty<Full>` directly specifies how many of the type kinds are actually represented compared to `Ty<Ambig>` which which leaves that to the reader to figure out based on the logical consequences of it the type being in an ambiguous position. --- tool changes have been modified in their own commits for easier reviewing by anyone getting cc'd from subtree changes. I also attempted to split out "bug fixes arising from the refactoring" into their own commit so they arent lumped in with a big general refactor commit Fixes #112110
2 parents d7b3940 + 3309f02 commit 6180622

Some content is hidden

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

42 files changed

+168
-171
lines changed

clippy_lints/src/box_default.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use clippy_utils::ty::expr_sig;
44
use clippy_utils::{is_default_equivalent, path_def_id};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::Res;
7-
use rustc_hir::intravisit::{Visitor, walk_ty};
8-
use rustc_hir::{Block, Expr, ExprKind, LetStmt, Node, QPath, Ty, TyKind};
7+
use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty};
8+
use rustc_hir::{AmbigArg, Block, Expr, ExprKind, HirId, LetStmt, Node, QPath, Ty, TyKind};
99
use rustc_lint::{LateContext, LateLintPass, LintContext};
1010
use rustc_middle::lint::in_external_macro;
1111
use rustc_session::declare_lint_pass;
12-
use rustc_span::sym;
12+
use rustc_span::{Span, sym};
1313

1414
declare_clippy_lint! {
1515
/// ### What it does
@@ -92,8 +92,13 @@ fn is_local_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>, ref_expr: &Expr<'_>)
9292
struct InferVisitor(bool);
9393

9494
impl Visitor<'_> for InferVisitor {
95-
fn visit_ty(&mut self, t: &Ty<'_>) {
96-
self.0 |= matches!(t.kind, TyKind::Infer | TyKind::OpaqueDef(..) | TyKind::TraitObject(..));
95+
fn visit_infer(&mut self, inf_id: HirId, _inf_span: Span, _kind: InferKind<'_>) -> Self::Result {
96+
self.0 = true;
97+
self.visit_id(inf_id);
98+
}
99+
100+
fn visit_ty(&mut self, t: &Ty<'_, AmbigArg>) {
101+
self.0 |= matches!(t.kind, TyKind::OpaqueDef(..) | TyKind::TraitObject(..));
97102
if !self.0 {
98103
walk_ty(self, t);
99104
}
@@ -104,7 +109,7 @@ fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
104109
match cx.tcx.parent_hir_node(expr.hir_id) {
105110
Node::LetStmt(LetStmt { ty: Some(ty), .. }) => {
106111
let mut v = InferVisitor::default();
107-
v.visit_ty(ty);
112+
v.visit_ty_unambig(ty);
108113
!v.0
109114
},
110115
Node::Expr(Expr {

clippy_lints/src/casts/as_pointer_underscore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::ty::Ty;
44

55
pub fn check<'tcx>(cx: &LateContext<'tcx>, ty_into: Ty<'_>, cast_to_hir: &'tcx rustc_hir::Ty<'tcx>) {
66
if let rustc_hir::TyKind::Ptr(rustc_hir::MutTy { ty, .. }) = cast_to_hir.kind
7-
&& matches!(ty.kind, rustc_hir::TyKind::Infer)
7+
&& matches!(ty.kind, rustc_hir::TyKind::Infer(()))
88
{
99
clippy_utils::diagnostics::span_lint_and_sugg(
1010
cx,

clippy_lints/src/casts/as_underscore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty;
77
use super::AS_UNDERSCORE;
88

99
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ty: &'tcx Ty<'_>) {
10-
if matches!(ty.kind, TyKind::Infer) {
10+
if matches!(ty.kind, TyKind::Infer(())) {
1111
span_lint_and_then(cx, AS_UNDERSCORE, expr.span, "using `as _` conversion", |diag| {
1212
let ty_resolved = cx.typeck_results().expr_ty(expr);
1313
if let ty::Error(_) = ty_resolved.kind() {

clippy_lints/src/casts/cast_lossless.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(super) fn check(
3838
return;
3939
};
4040
match cast_to_hir.kind {
41-
TyKind::Infer => {
41+
TyKind::Infer(()) => {
4242
diag.span_suggestion_verbose(
4343
expr.span,
4444
"use `Into::into` instead",

clippy_lints/src/casts/cast_ptr_alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
2424
&& let Some(generic_args) = method_path.args
2525
&& let [GenericArg::Type(cast_to)] = generic_args.args
2626
// There probably is no obvious reason to do this, just to be consistent with `as` cases.
27-
&& !is_hir_ty_cfg_dependant(cx, cast_to)
27+
&& !is_hir_ty_cfg_dependant(cx, cast_to.as_unambig_ty())
2828
{
2929
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(self_arg), cx.typeck_results().expr_ty(expr));
3030
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);

clippy_lints/src/casts/ptr_as_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {
4343
{
4444
let mut app = Applicability::MachineApplicable;
4545
let turbofish = match &cast_to_hir_ty.kind {
46-
TyKind::Infer => String::new(),
46+
TyKind::Infer(()) => String::new(),
4747
TyKind::Ptr(mut_ty) => {
48-
if matches!(mut_ty.ty.kind, TyKind::Infer) {
48+
if matches!(mut_ty.ty.kind, TyKind::Infer(())) {
4949
String::new()
5050
} else {
5151
format!(

clippy_lints/src/casts/ref_as_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ pub(super) fn check<'tcx>(
3434

3535
let mut app = Applicability::MachineApplicable;
3636
let turbofish = match &cast_to_hir_ty.kind {
37-
TyKind::Infer => String::new(),
37+
TyKind::Infer(()) => String::new(),
3838
TyKind::Ptr(mut_ty) => {
39-
if matches!(mut_ty.ty.kind, TyKind::Infer) {
39+
if matches!(mut_ty.ty.kind, TyKind::Infer(())) {
4040
String::new()
4141
} else {
4242
format!(

clippy_lints/src/casts/unnecessary_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(super) fn check<'tcx>(
4343
}
4444
},
4545
// Ignore `p as *const _`
46-
TyKind::Infer => return false,
46+
TyKind::Infer(()) => return false,
4747
_ => {},
4848
}
4949

clippy_lints/src/casts/zero_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, from: &Expr<'_>, to: &Ty<'_>
1818
Mutability::Not => ("`0 as *const _` detected", "ptr::null"),
1919
};
2020

21-
let sugg = if let TyKind::Infer = mut_ty.ty.kind {
21+
let sugg = if let TyKind::Infer(()) = mut_ty.ty.kind {
2222
format!("{std_or_core}::{sugg_fn}()")
2323
} else if let Some(mut_ty_snip) = mut_ty.ty.span.get_source_text(cx) {
2424
format!("{std_or_core}::{sugg_fn}::<{mut_ty_snip}>()")

clippy_lints/src/dereference.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use rustc_ast::util::parser::ExprPrecedence;
1111
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_errors::Applicability;
1313
use rustc_hir::def_id::DefId;
14-
use rustc_hir::intravisit::{Visitor, walk_ty};
14+
use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty};
1515
use rustc_hir::{
16-
self as hir, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, Pat,
17-
PatKind, Path, QPath, TyKind, UnOp,
16+
self as hir, AmbigArg, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node,
17+
Pat, PatKind, Path, QPath, TyKind, UnOp,
1818
};
1919
use rustc_lint::{LateContext, LateLintPass};
2020
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
@@ -796,7 +796,7 @@ impl TyCoercionStability {
796796
if let Some(args) = path.args
797797
&& args.args.iter().any(|arg| match arg {
798798
hir::GenericArg::Infer(_) => true,
799-
hir::GenericArg::Type(ty) => ty_contains_infer(ty),
799+
hir::GenericArg::Type(ty) => ty_contains_infer(ty.as_unambig_ty()),
800800
_ => false,
801801
})
802802
{
@@ -815,7 +815,7 @@ impl TyCoercionStability {
815815
| TyKind::Path(_) => Self::Deref,
816816
TyKind::OpaqueDef(..)
817817
| TyKind::TraitAscription(..)
818-
| TyKind::Infer
818+
| TyKind::Infer(())
819819
| TyKind::Typeof(..)
820820
| TyKind::TraitObject(..)
821821
| TyKind::InferDelegation(..)
@@ -889,29 +889,23 @@ impl TyCoercionStability {
889889
fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool {
890890
struct V(bool);
891891
impl Visitor<'_> for V {
892-
fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
893-
if self.0
894-
|| matches!(
895-
ty.kind,
896-
TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(_) | TyKind::Err(_)
897-
)
898-
{
892+
fn visit_infer(&mut self, inf_id: HirId, _inf_span: Span, kind: InferKind<'_>) -> Self::Result {
893+
if let InferKind::Ty(_) | InferKind::Ambig(_) = kind {
899894
self.0 = true;
900-
} else {
901-
walk_ty(self, ty);
902895
}
896+
self.visit_id(inf_id);
903897
}
904898

905-
fn visit_generic_arg(&mut self, arg: &hir::GenericArg<'_>) {
906-
if self.0 || matches!(arg, hir::GenericArg::Infer(_)) {
899+
fn visit_ty(&mut self, ty: &hir::Ty<'_, AmbigArg>) {
900+
if self.0 || matches!(ty.kind, TyKind::OpaqueDef(..) | TyKind::Typeof(_) | TyKind::Err(_)) {
907901
self.0 = true;
908-
} else if let hir::GenericArg::Type(ty) = arg {
909-
self.visit_ty(ty);
902+
} else {
903+
walk_ty(self, ty);
910904
}
911905
}
912906
}
913907
let mut v = V(false);
914-
v.visit_ty(ty);
908+
v.visit_ty_unambig(ty);
915909
v.0
916910
}
917911

clippy_lints/src/disallowed_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashSet;
66
use rustc_errors::Diag;
77
use rustc_hir::def_id::DefIdMap;
88
use rustc_hir::{
9-
Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty,
9+
AmbigArg, Expr, ExprKind, ForeignItem, HirId, ImplItem, Item, ItemKind, OwnerId, Pat, Path, Stmt, TraitItem, Ty,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::ty::TyCtxt;
@@ -140,7 +140,7 @@ impl LateLintPass<'_> for DisallowedMacros {
140140
self.check(cx, stmt.span, None);
141141
}
142142

143-
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &Ty<'_>) {
143+
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &Ty<'_, AmbigArg>) {
144144
self.check(cx, ty.span, None);
145145
}
146146

clippy_lints/src/disallowed_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::def::Res;
55
use rustc_hir::def_id::DefIdMap;
6-
use rustc_hir::{Item, ItemKind, PolyTraitRef, PrimTy, Ty, TyKind, UseKind};
6+
use rustc_hir::{AmbigArg, Item, ItemKind, PolyTraitRef, PrimTy, Ty, TyKind, UseKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::ty::TyCtxt;
99
use rustc_session::impl_lint_pass;
@@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
108108
}
109109
}
110110

111-
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) {
111+
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx, AmbigArg>) {
112112
if let TyKind::Path(path) = &ty.kind {
113113
self.check_res_emit(cx, &cx.qpath_res(path, ty.hir_id), ty.span);
114114
}

clippy_lints/src/eta_reduction.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
7676
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
7777
if let ExprKind::MethodCall(_method, receiver, args, _) = expr.kind {
7878
for arg in args {
79-
check_clousure(cx, Some(receiver), arg);
79+
check_closure(cx, Some(receiver), arg);
8080
}
8181
}
8282
if let ExprKind::Call(func, args) = expr.kind {
83-
check_clousure(cx, None, func);
83+
check_closure(cx, None, func);
8484
for arg in args {
85-
check_clousure(cx, None, arg);
85+
check_closure(cx, None, arg);
8686
}
8787
}
8888
}
8989
}
9090

9191
#[allow(clippy::too_many_lines)]
92-
fn check_clousure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx>>, expr: &Expr<'tcx>) {
92+
fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx>>, expr: &Expr<'tcx>) {
9393
let body = if let ExprKind::Closure(c) = expr.kind
94-
&& c.fn_decl.inputs.iter().all(|ty| matches!(ty.kind, TyKind::Infer))
94+
&& c.fn_decl.inputs.iter().all(|ty| matches!(ty.kind, TyKind::Infer(())))
9595
&& matches!(c.fn_decl.output, FnRetTy::DefaultReturn(_))
9696
&& !expr.span.from_expansion()
9797
{

clippy_lints/src/extra_unused_type_parameters.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
33
use clippy_utils::{is_from_proc_macro, trait_ref_of_method};
44
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
55
use rustc_errors::Applicability;
6-
use rustc_hir::intravisit::{Visitor, walk_impl_item, walk_item, walk_param_bound, walk_ty};
6+
use rustc_hir::intravisit::{Visitor, walk_impl_item, walk_item, walk_param_bound, walk_ty, walk_unambig_ty};
77
use rustc_hir::{
8-
BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind,
9-
PredicateOrigin, Ty, WherePredicate, WherePredicateKind,
8+
AmbigArg, BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item,
9+
ItemKind, PredicateOrigin, Ty, WherePredicate, WherePredicateKind,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::hir::nested_filter;
@@ -196,7 +196,7 @@ fn bound_to_trait_def_id(bound: &GenericBound<'_>) -> Option<LocalDefId> {
196196
impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
197197
type NestedFilter = nested_filter::OnlyBodies;
198198

199-
fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
199+
fn visit_ty(&mut self, t: &'tcx Ty<'tcx, AmbigArg>) {
200200
if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
201201
self.ty_params.remove(&def_id);
202202
} else {
@@ -234,7 +234,7 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
234234
// type, any params we find nested inside of it are being used as concrete types,
235235
// and can therefore can be considered used. So, we're fine to walk the left-hand
236236
// side of the where bound.
237-
walk_ty(self, predicate.bounded_ty);
237+
walk_unambig_ty(self, predicate.bounded_ty);
238238
}
239239
for bound in predicate.bounds {
240240
walk_param_bound(self, bound);

clippy_lints/src/from_over_into.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
103103
"replace the `Into` implementation with `From<{}>`",
104104
middle_trait_ref.self_ty()
105105
);
106-
if let Some(suggestions) = convert_to_from(cx, into_trait_seg, target_ty, self_ty, impl_item_ref) {
106+
if let Some(suggestions) =
107+
convert_to_from(cx, into_trait_seg, target_ty.as_unambig_ty(), self_ty, impl_item_ref)
108+
{
107109
diag.multipart_suggestion(message, suggestions, Applicability::MachineApplicable);
108110
} else {
109111
diag.help(message);

clippy_lints/src/implicit_hasher.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use std::borrow::Cow;
22
use std::collections::BTreeMap;
33

44
use rustc_errors::{Applicability, Diag};
5-
use rustc_hir as hir;
6-
use rustc_hir::intravisit::{Visitor, walk_body, walk_expr, walk_inf, walk_ty};
7-
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
5+
use rustc_hir::intravisit::{Visitor, VisitorExt, walk_body, walk_expr, walk_ty};
6+
use rustc_hir::{self as hir, AmbigArg, Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
87
use rustc_hir_analysis::lower_ty;
98
use rustc_lint::{LateContext, LateLintPass};
109
use rustc_middle::hir::nested_filter;
@@ -112,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
112111
match item.kind {
113112
ItemKind::Impl(impl_) => {
114113
let mut vis = ImplicitHasherTypeVisitor::new(cx);
115-
vis.visit_ty(impl_.self_ty);
114+
vis.visit_ty_unambig(impl_.self_ty);
116115

117116
for target in &vis.found {
118117
if !item.span.eq_ctxt(target.span()) {
@@ -159,7 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
159158

160159
for ty in sig.decl.inputs {
161160
let mut vis = ImplicitHasherTypeVisitor::new(cx);
162-
vis.visit_ty(ty);
161+
vis.visit_ty_unambig(ty);
163162

164163
for target in &vis.found {
165164
if generics.span.from_expansion() {
@@ -287,21 +286,13 @@ impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> {
287286
}
288287

289288
impl<'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'_, 'tcx> {
290-
fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) {
291-
if let Some(target) = ImplicitHasherType::new(self.cx, t) {
289+
fn visit_ty(&mut self, t: &'tcx hir::Ty<'_, AmbigArg>) {
290+
if let Some(target) = ImplicitHasherType::new(self.cx, t.as_unambig_ty()) {
292291
self.found.push(target);
293292
}
294293

295294
walk_ty(self, t);
296295
}
297-
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-
}
305296
}
306297

307298
/// Looks for default-hasher-dependent constructors like `HashMap::new`.

clippy_lints/src/implied_bounds_in_impls.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use clippy_utils::source::snippet;
33
use rustc_errors::{Applicability, SuggestionStyle};
44
use rustc_hir::def_id::DefId;
55
use rustc_hir::{
6-
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, PredicateOrigin, TraitBoundModifiers, TyKind,
7-
WherePredicateKind,
6+
AmbigArg, AssocItemConstraint, GenericArg, GenericBound, GenericBounds, PredicateOrigin, TraitBoundModifiers,
7+
TyKind, WherePredicateKind,
88
};
99
use rustc_hir_analysis::lower_ty;
1010
use rustc_lint::{LateContext, LateLintPass};
@@ -146,7 +146,9 @@ fn try_resolve_type<'tcx>(
146146
index: usize,
147147
) -> Option<Ty<'tcx>> {
148148
match args.get(index - 1) {
149-
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)),
149+
// I don't think we care about `GenericArg::Infer` since this is all for stuff in type signatures
150+
// which do not permit inference variables.
151+
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty.as_unambig_ty())),
150152
Some(_) => None,
151153
None => Some(tcx.type_of(generics.own_params[index].def_id).skip_binder()),
152154
}
@@ -335,7 +337,7 @@ impl<'tcx> LateLintPass<'tcx> for ImpliedBoundsInImpls {
335337
}
336338
}
337339

338-
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &rustc_hir::Ty<'tcx>) {
340+
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &rustc_hir::Ty<'tcx, AmbigArg>) {
339341
if let TyKind::OpaqueDef(opaque_ty, ..) = ty.kind {
340342
check(cx, opaque_ty.bounds);
341343
}

clippy_lints/src/let_with_type_underscore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
2828
impl<'tcx> LateLintPass<'tcx> for UnderscoreTyped {
2929
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
3030
if let Some(ty) = local.ty // Ensure that it has a type defined
31-
&& let TyKind::Infer = &ty.kind // that type is '_'
31+
&& let TyKind::Infer(()) = &ty.kind // that type is '_'
3232
&& local.span.eq_ctxt(ty.span)
3333
&& !in_external_macro(cx.tcx.sess, local.span)
3434
&& !is_from_proc_macro(cx, ty)

0 commit comments

Comments
 (0)