add is_trait(DefId)
helper to TyCtxt
Co-authored-by: Tyler Mandry <tmandry@gmail.com>
This commit is contained in:
parent
7bbbed9046
commit
327093007a
@ -518,10 +518,25 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
result
|
||||
}
|
||||
|
||||
/// True if `def_id` refers to a closure (e.g., `|x| x * 2`). Note
|
||||
/// that closures have a def-id, but the closure *expression* also
|
||||
/// has a `HirId` that is located within the context where the
|
||||
/// closure appears (and, sadly, a corresponding `NodeId`, since
|
||||
/// those are not yet phased out). The parent of the closure's
|
||||
/// def-id will also be the context where it appears.
|
||||
pub fn is_closure(self, def_id: DefId) -> bool {
|
||||
self.def_key(def_id).disambiguated_data.data == DefPathData::ClosureExpr
|
||||
}
|
||||
|
||||
/// True if `def_id` refers to a trait (e.g., `trait Foo { ... }`).
|
||||
pub fn is_trait(self, def_id: DefId) -> bool {
|
||||
if let DefPathData::Trait(_) = self.def_key(def_id).disambiguated_data.data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// True if this def-id refers to the implicit constructor for
|
||||
/// a tuple struct like `struct Foo(u32)`.
|
||||
pub fn is_struct_constructor(self, def_id: DefId) -> bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user