1
Fork 0

Add generic arg infer

This commit is contained in:
kadmin 2021-04-24 21:41:57 +00:00
parent 71a6c7c803
commit 417b098cfc
28 changed files with 265 additions and 89 deletions

View file

@ -253,11 +253,24 @@ pub struct ConstArg {
pub span: Span,
}
#[derive(Encodable, Debug, HashStable_Generic)]
pub struct InferArg {
pub hir_id: HirId,
pub span: Span,
}
impl InferArg {
pub fn to_ty(&self) -> Ty<'_> {
Ty { kind: TyKind::Infer, span: self.span, hir_id: self.hir_id }
}
}
#[derive(Debug, HashStable_Generic)]
pub enum GenericArg<'hir> {
Lifetime(Lifetime),
Type(Ty<'hir>),
Const(ConstArg),
Infer(InferArg),
}
impl GenericArg<'_> {
@ -266,6 +279,7 @@ impl GenericArg<'_> {
GenericArg::Lifetime(l) => l.span,
GenericArg::Type(t) => t.span,
GenericArg::Const(c) => c.span,
GenericArg::Infer(i) => i.span,
}
}
@ -274,6 +288,7 @@ impl GenericArg<'_> {
GenericArg::Lifetime(l) => l.hir_id,
GenericArg::Type(t) => t.hir_id,
GenericArg::Const(c) => c.value.hir_id,
GenericArg::Infer(i) => i.hir_id,
}
}
@ -290,6 +305,7 @@ impl GenericArg<'_> {
GenericArg::Lifetime(_) => "lifetime",
GenericArg::Type(_) => "type",
GenericArg::Const(_) => "constant",
GenericArg::Infer(_) => "inferred",
}
}
@ -300,6 +316,7 @@ impl GenericArg<'_> {
GenericArg::Const(_) => {
ast::ParamKindOrd::Const { unordered: feats.unordered_const_ty_params() }
}
GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
}
}
}
@ -341,6 +358,7 @@ impl GenericArgs<'_> {
break;
}
GenericArg::Const(_) => {}
GenericArg::Infer(_) => {}
}
}
}
@ -358,6 +376,7 @@ impl GenericArgs<'_> {
GenericArg::Lifetime(_) => own_counts.lifetimes += 1,
GenericArg::Type(_) => own_counts.types += 1,
GenericArg::Const(_) => own_counts.consts += 1,
GenericArg::Infer(_) => own_counts.infer += 1,
};
}
@ -484,6 +503,7 @@ pub struct GenericParamCount {
pub lifetimes: usize,
pub types: usize,
pub consts: usize,
pub infer: usize,
}
/// Represents lifetimes and type parameters attached to a declaration
@ -2987,6 +3007,8 @@ pub enum Node<'hir> {
Visibility(&'hir Visibility<'hir>),
Crate(&'hir Mod<'hir>),
Infer(&'hir InferArg),
}
impl<'hir> Node<'hir> {
@ -3055,6 +3077,7 @@ impl<'hir> Node<'hir> {
| Node::Local(Local { hir_id, .. })
| Node::Lifetime(Lifetime { hir_id, .. })
| Node::Param(Param { hir_id, .. })
| Node::Infer(InferArg { hir_id, .. })
| Node::GenericParam(GenericParam { hir_id, .. }) => Some(*hir_id),
Node::TraitRef(TraitRef { hir_ref_id, .. }) => Some(*hir_ref_id),
Node::PathSegment(PathSegment { hir_id, .. }) => *hir_id,

View file

@ -436,13 +436,22 @@ pub trait Visitor<'v>: Sized {
fn visit_label(&mut self, label: &'v Label) {
walk_label(self, label)
}
fn visit_infer(&mut self, inf: &'v InferArg) {
self.visit_id(inf.hir_id);
}
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) {
match generic_arg {
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
GenericArg::Type(ty) => self.visit_ty(ty),
GenericArg::Const(ct) => self.visit_anon_const(&ct.value),
GenericArg::Infer(inf) => self.visit_infer(inf),
}
}
/*
fn tcx(&self) -> Option<&TyCtxt<'tcx>> {
None
}
*/
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
walk_lifetime(self, lifetime)
}
@ -746,6 +755,10 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
}
}
pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) {
visitor.visit_id(inf.hir_id);
}
pub fn walk_qpath<'v, V: Visitor<'v>>(
visitor: &mut V,
qpath: &'v QPath<'v>,