Skip to content

Commit 909f1f6

Browse files
committed
the clipper :3c
1 parent d953374 commit 909f1f6

35 files changed

+149
-148
lines changed

src/tools/clippy/clippy_lints/src/box_default.rs

+12-7
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_ambig_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,10 +92,15 @@ 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_shared_ty_const(&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 {
98-
walk_ty(self, t);
103+
walk_ambig_ty(self, t);
99104
}
100105
}
101106
}
@@ -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_unambig_ty(ty);
108113
!v.0
109114
},
110115
Node::Expr(Expr {

src/tools/clippy/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,

src/tools/clippy/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() {

src/tools/clippy/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",

src/tools/clippy/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);

src/tools/clippy/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!(

src/tools/clippy/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!(

src/tools/clippy/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

src/tools/clippy/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}>()")

src/tools/clippy/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_ambig_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_shared_ty_const(&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_ambig_ty(self, ty);
910904
}
911905
}
912906
}
913907
let mut v = V(false);
914-
v.visit_ty(ty);
908+
v.visit_unambig_ty(ty);
915909
v.0
916910
}
917911

src/tools/clippy/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
{

src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs

+6-6
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_ambig_ty, walk_impl_item, walk_item, walk_param_bound, walk_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,11 +196,11 @@ 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>) {
200-
if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
199+
fn visit_ty(&mut self, t: &'tcx Ty<'tcx, AmbigArg>) {
200+
if let Some((def_id, _)) = t.as_unambig_ty().peel_refs().as_generic_param() {
201201
self.ty_params.remove(&def_id);
202202
} else {
203-
walk_ty(self, t);
203+
walk_ambig_ty(self, t);
204204
}
205205
}
206206

src/tools/clippy/clippy_lints/src/from_over_into.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
9292
|diag| {
9393
// If the target type is likely foreign mention the orphan rules as it's a common source of
9494
// confusion
95-
if path_def_id(cx, target_ty.peel_refs()).is_none_or(|id| !id.is_local()) {
95+
if path_def_id(cx, target_ty.as_unambig_ty().peel_refs()).is_none_or(|id| !id.is_local()) {
9696
diag.help(
9797
"`impl From<Local> for Foreign` is allowed by the orphan rules, for more information see\n\
9898
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence"
@@ -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);

src/tools/clippy/clippy_lints/src/implicit_hasher.rs

+7-16
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_ambig_ty, walk_body, walk_expr};
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_unambig_ty(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_unambig_ty(ty);
163162

164163
for target in &vis.found {
165164
if generics.span.from_expansion() {
@@ -287,20 +286,12 @@ 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

295-
walk_ty(self, t);
296-
}
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);
294+
walk_ambig_ty(self, t);
304295
}
305296
}
306297

src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -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
}

src/tools/clippy/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)