Auto merge of #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.
This commit is contained in:
commit
ea988afcda
@ -5,7 +5,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::DiagnosticBuilder;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, walk_inf, NestedVisitorMap, Visitor};
|
||||||
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
|
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
@ -295,6 +295,14 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> {
|
|||||||
walk_ty(self, t);
|
walk_ty(self, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
|
||||||
|
if let Some(target) = ImplicitHasherType::new(self.cx, &inf.to_ty()) {
|
||||||
|
self.found.push(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
walk_inf(self, inf);
|
||||||
|
}
|
||||||
|
|
||||||
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
|
||||||
NestedVisitorMap::None
|
NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use clippy_utils::diagnostics::span_lint;
|
use clippy_utils::diagnostics::span_lint;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{walk_ty, NestedVisitorMap, Visitor};
|
use rustc_hir::intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor};
|
||||||
use rustc_hir::{GenericParamKind, TyKind};
|
use rustc_hir::{GenericParamKind, TyKind};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
@ -39,6 +39,11 @@ struct TypeComplexityVisitor {
|
|||||||
impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
|
impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
|
||||||
type Map = Map<'tcx>;
|
type Map = Map<'tcx>;
|
||||||
|
|
||||||
|
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
|
||||||
|
self.score += 1;
|
||||||
|
walk_inf(self, inf);
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
|
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
|
||||||
let (add_score, sub_nest) = match ty.kind {
|
let (add_score, sub_nest) = match ty.kind {
|
||||||
// _, &x and *x have only small overhead; don't mess with nesting level
|
// _, &x and *x have only small overhead; don't mess with nesting level
|
||||||
|
@ -8,8 +8,9 @@ use rustc_hir::{
|
|||||||
self as hir,
|
self as hir,
|
||||||
def::{CtorOf, DefKind, Res},
|
def::{CtorOf, DefKind, Res},
|
||||||
def_id::LocalDefId,
|
def_id::LocalDefId,
|
||||||
intravisit::{walk_ty, NestedVisitorMap, Visitor},
|
intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor},
|
||||||
Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind,
|
Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path,
|
||||||
|
QPath, TyKind,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
@ -263,6 +264,11 @@ struct SkipTyCollector {
|
|||||||
impl<'tcx> Visitor<'tcx> for SkipTyCollector {
|
impl<'tcx> Visitor<'tcx> for SkipTyCollector {
|
||||||
type Map = Map<'tcx>;
|
type Map = Map<'tcx>;
|
||||||
|
|
||||||
|
fn visit_infer(&mut self, inf: &hir::InferArg) {
|
||||||
|
self.types_to_skip.push(inf.hir_id);
|
||||||
|
|
||||||
|
walk_inf(self, inf)
|
||||||
|
}
|
||||||
fn visit_ty(&mut self, hir_ty: &hir::Ty<'_>) {
|
fn visit_ty(&mut self, hir_ty: &hir::Ty<'_>) {
|
||||||
self.types_to_skip.push(hir_ty.hir_id);
|
self.types_to_skip.push(hir_ty.hir_id);
|
||||||
|
|
||||||
|
@ -288,6 +288,8 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||||||
(GenericArg::Const(l), GenericArg::Const(r)) => self.eq_body(l.value.body, r.value.body),
|
(GenericArg::Const(l), GenericArg::Const(r)) => self.eq_body(l.value.body, r.value.body),
|
||||||
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt),
|
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt),
|
||||||
(GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
|
(GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
|
||||||
|
(GenericArg::Infer(l_inf), GenericArg::Infer(r_inf)) =>
|
||||||
|
self.eq_ty(&l_inf.to_ty(), &r_inf.to_ty()),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -885,7 +887,11 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||||||
|
|
||||||
pub fn hash_ty(&mut self, ty: &Ty<'_>) {
|
pub fn hash_ty(&mut self, ty: &Ty<'_>) {
|
||||||
std::mem::discriminant(&ty.kind).hash(&mut self.s);
|
std::mem::discriminant(&ty.kind).hash(&mut self.s);
|
||||||
match ty.kind {
|
self.hash_tykind(&ty.kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hash_tykind(&mut self, ty: &TyKind<'_>) {
|
||||||
|
match ty {
|
||||||
TyKind::Slice(ty) => {
|
TyKind::Slice(ty) => {
|
||||||
self.hash_ty(ty);
|
self.hash_ty(ty);
|
||||||
},
|
},
|
||||||
@ -898,7 +904,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||||||
mut_ty.mutbl.hash(&mut self.s);
|
mut_ty.mutbl.hash(&mut self.s);
|
||||||
},
|
},
|
||||||
TyKind::Rptr(lifetime, ref mut_ty) => {
|
TyKind::Rptr(lifetime, ref mut_ty) => {
|
||||||
self.hash_lifetime(lifetime);
|
self.hash_lifetime(*lifetime);
|
||||||
self.hash_ty(mut_ty.ty);
|
self.hash_ty(mut_ty.ty);
|
||||||
mut_ty.mutbl.hash(&mut self.s);
|
mut_ty.mutbl.hash(&mut self.s);
|
||||||
},
|
},
|
||||||
@ -918,7 +924,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||||||
bfn.decl.c_variadic.hash(&mut self.s);
|
bfn.decl.c_variadic.hash(&mut self.s);
|
||||||
},
|
},
|
||||||
TyKind::Tup(ty_list) => {
|
TyKind::Tup(ty_list) => {
|
||||||
for ty in ty_list {
|
for ty in *ty_list {
|
||||||
self.hash_ty(ty);
|
self.hash_ty(ty);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -927,7 +933,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||||||
self.hash_generic_args(arg_list);
|
self.hash_generic_args(arg_list);
|
||||||
},
|
},
|
||||||
TyKind::TraitObject(_, lifetime, _) => {
|
TyKind::TraitObject(_, lifetime, _) => {
|
||||||
self.hash_lifetime(lifetime);
|
self.hash_lifetime(*lifetime);
|
||||||
},
|
},
|
||||||
TyKind::Typeof(anon_const) => {
|
TyKind::Typeof(anon_const) => {
|
||||||
self.hash_body(anon_const.body);
|
self.hash_body(anon_const.body);
|
||||||
@ -949,6 +955,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||||||
GenericArg::Lifetime(l) => self.hash_lifetime(l),
|
GenericArg::Lifetime(l) => self.hash_lifetime(l),
|
||||||
GenericArg::Type(ref ty) => self.hash_ty(ty),
|
GenericArg::Type(ref ty) => self.hash_ty(ty),
|
||||||
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
|
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
|
||||||
|
GenericArg::Infer(ref inf) => self.hash_ty(&inf.to_ty()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Per https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/infer/at/struct.At.html#method.normalize
|
// FIXME: Per https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/infer/at/struct.At.html#method.normalize
|
||||||
// this function can be removed once the `normalizie` method does not panic when normalization does
|
// this function can be removed once the `normalize` method does not panic when normalization does
|
||||||
// not succeed
|
// not succeed
|
||||||
/// Checks if `Ty` is normalizable. This function is useful
|
/// Checks if `Ty` is normalizable. This function is useful
|
||||||
/// to avoid crashes on `layout_of`.
|
/// to avoid crashes on `layout_of`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user