mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 09:53:26 +00:00
Document get_def_path
This commit is contained in:
parent
b6c3a6a09f
commit
f3ee53d225
@ -130,6 +130,15 @@ pub fn match_def_path(tcx: TyCtxt<'_, '_, '_>, def_id: DefId, path: &[&str]) ->
|
||||
apb.names.len() == path.len() && apb.names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
|
||||
}
|
||||
|
||||
/// Get the absolute path of `def_id` as a vector of `&str`.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rust,ignore
|
||||
/// let def_path = get_def_path(tcx, def_id);
|
||||
/// if let &["core", "option", "Option"] = &def_path[..] {
|
||||
/// // The given `def_id` is that of an `Option` type
|
||||
/// };
|
||||
/// ```
|
||||
pub fn get_def_path(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Vec<&'static str> {
|
||||
let mut apb = AbsolutePathBuffer { names: vec![] };
|
||||
tcx.push_item_path(&mut apb, def_id, false);
|
||||
|
Loading…
Reference in New Issue
Block a user