Skip to content

Commit f04acdd

Browse files
committed
Document match_path, improve match_qpath docs
1 parent 00baf7a commit f04acdd

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ pub fn single_segment_path(path: &QPath) -> Option<&PathSegment> {
190190
}
191191
}
192192

193-
/// Match a `Path` against a slice of segment string literals.
193+
/// Match a `QPath` against a slice of segment string literals.
194+
///
195+
/// There is also `match_path` if you are dealing with a `rustc::hir::Path` instead of a
196+
/// `rustc::hir::QPath`.
194197
///
195198
/// # Examples
196199
/// ```rust,ignore
@@ -210,6 +213,22 @@ pub fn match_qpath(path: &QPath, segments: &[&str]) -> bool {
210213
}
211214
}
212215

216+
/// Match a `Path` against a slice of segment string literals.
217+
///
218+
/// There is also `match_qpath` if you are dealing with a `rustc::hir::QPath` instead of a
219+
/// `rustc::hir::Path`.
220+
///
221+
/// # Examples
222+
///
223+
/// ```rust,ignore
224+
/// if match_path(&trait_ref.path, &paths::HASH) {
225+
/// // This is the `std::hash::Hash` trait.
226+
/// }
227+
///
228+
/// if match_path(ty_path, &["rustc", "lint", "Lint"]) {
229+
/// // This is a `rustc::lint::Lint`.
230+
/// }
231+
/// ```
213232
pub fn match_path(path: &Path, segments: &[&str]) -> bool {
214233
path.segments
215234
.iter()

0 commit comments

Comments
 (0)