Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LateContext::match_def_path() #136242

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! overview of how lints are implemented.

use std::cell::Cell;
use std::{iter, slice};
use std::slice;

use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync;
Expand Down Expand Up @@ -718,30 +718,6 @@ impl<'tcx> LateContext<'tcx> {
}
}

/// Check if a `DefId`'s path matches the given absolute type path usage.
///
/// Anonymous scopes such as `extern` imports are matched with `kw::Empty`;
/// inherent `impl` blocks are matched with the name of the type.
///
/// Instead of using this method, it is often preferable to instead use
/// `rustc_diagnostic_item` or a `lang_item`. This is less prone to errors
/// as paths get invalidated if the target definition moves.
///
/// # Examples
///
/// ```rust,ignore (no context or def id available)
/// if cx.match_def_path(def_id, &[sym::core, sym::option, sym::Option]) {
/// // The given `def_id` is that of an `Option` type
/// }
/// ```
///
/// Used by clippy, but should be replaced by diagnostic items eventually.
pub fn match_def_path(&self, def_id: DefId, path: &[Symbol]) -> bool {
let names = self.get_def_path(def_id);

names.len() == path.len() && iter::zip(names, path).all(|(a, &b)| a == b)
}

/// Gets the absolute path of `def_id` as a vector of `Symbol`.
///
/// # Examples
Expand Down
Loading