Skip to content

Commit f3ee53d

Browse files
author
Michael Wright
committed
Document get_def_path
1 parent b6c3a6a commit f3ee53d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ pub fn match_def_path(tcx: TyCtxt<'_, '_, '_>, def_id: DefId, path: &[&str]) ->
130130
apb.names.len() == path.len() && apb.names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
131131
}
132132

133+
/// Get the absolute path of `def_id` as a vector of `&str`.
134+
///
135+
/// # Examples
136+
/// ```rust,ignore
137+
/// let def_path = get_def_path(tcx, def_id);
138+
/// if let &["core", "option", "Option"] = &def_path[..] {
139+
/// // The given `def_id` is that of an `Option` type
140+
/// };
141+
/// ```
133142
pub fn get_def_path(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Vec<&'static str> {
134143
let mut apb = AbsolutePathBuffer { names: vec![] };
135144
tcx.push_item_path(&mut apb, def_id, false);

0 commit comments

Comments
 (0)