plugins - How to find out what type a rustc::middle::ty::Ty represents? -
for writing yet lint in rust, need make sure type of expr option<_>
(or pointer one). have walked ptr
s , rptr
s conclusion , left rustc::middle::ty
in test case debugs (manually formatted better readability):
tys { sty: ty_enum( defid { krate: 2, node: 117199 }, substs { types: vecperparamspace { typespace: [ tys { sty: ty_int(i32), flags: 0, region_depth: 0 } ], selfspace: [], fnspace: [], }, regions: nonerasedregions( vecperparamspace { typespace: [], selfspace: [], fnspace: [], } ) } ), flags: 0, region_depth: 0 }
however, i'm bit lost – how find out if tys option<_> type?
you need use with_path
on defid. provided iterator on pathelem
s must consume.
the following rough sketch, should give array of name
s if tweak bit.
if let ty_enum(did, ..) = ty.sty { tcx.with_path(did, |iter| iter.map(|elem| elem.name())).collect::<vec<name>>; }
Comments
Post a Comment