Rollup merge of #106403 - compiler-errors:rename-hir-methods, r=cjgillot
Rename `hir::Map::{get_,find_}parent_node` to `hir::Map::{,opt_}parent_id`, and add `hir::Map::{get,find}_parent` The `hir::Map::get_parent_node` function doesn't return a `Node`, and I think that's quite confusing. Let's rename it to something that sounds more like something that gets the parent hir id => `hir::Map::parent_id`. Same with `find_parent_node` => `opt_parent_id`. Also, combine `hir.get(hir.parent_id(hir_id))` and similar `hir.find(hir.parent_id(hir_id))` function into new functions that actually retrieve the parent node in one call. This last commit is the only one that might need to be looked at closely.
This commit is contained in:
commit
5ce6311f34
54 changed files with 170 additions and 179 deletions
|
@ -1526,7 +1526,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
|
|||
|
||||
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
|
||||
let map = cx.tcx.hir();
|
||||
if matches!(map.get(map.get_parent_node(field.hir_id)), Node::Variant(_)) {
|
||||
if matches!(map.get_parent(field.hir_id), Node::Variant(_)) {
|
||||
return;
|
||||
}
|
||||
self.perform_lint(cx, "field", field.def_id, field.vis_span, false);
|
||||
|
|
|
@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
|
|||
TyKind::Path(QPath::Resolved(_, path)) => {
|
||||
if lint_ty_kind_usage(cx, &path.res) {
|
||||
let hir = cx.tcx.hir();
|
||||
let span = match hir.find(hir.get_parent_node(ty.hir_id)) {
|
||||
let span = match hir.find_parent(ty.hir_id) {
|
||||
Some(Node::Pat(Pat {
|
||||
kind:
|
||||
PatKind::Path(qpath)
|
||||
|
|
|
@ -444,8 +444,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
|||
|
||||
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
||||
if let PatKind::Binding(_, hid, ident, _) = p.kind {
|
||||
if let hir::Node::PatField(field) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
|
||||
{
|
||||
if let hir::Node::PatField(field) = cx.tcx.hir().get_parent(hid) {
|
||||
if !field.is_shorthand {
|
||||
// Only check if a new name has been introduced, to avoid warning
|
||||
// on both the struct definition and this pattern.
|
||||
|
|
|
@ -127,10 +127,9 @@ fn lint_overflowing_range_endpoint<'tcx>(
|
|||
) -> bool {
|
||||
// We only want to handle exclusive (`..`) ranges,
|
||||
// which are represented as `ExprKind::Struct`.
|
||||
let par_id = cx.tcx.hir().get_parent_node(expr.hir_id);
|
||||
let par_id = cx.tcx.hir().parent_id(expr.hir_id);
|
||||
let Node::ExprField(field) = cx.tcx.hir().get(par_id) else { return false };
|
||||
let field_par_id = cx.tcx.hir().get_parent_node(field.hir_id);
|
||||
let Node::Expr(struct_expr) = cx.tcx.hir().get(field_par_id) else { return false };
|
||||
let Node::Expr(struct_expr) = cx.tcx.hir().get_parent(field.hir_id) else { return false };
|
||||
if !is_range_literal(struct_expr) {
|
||||
return false;
|
||||
};
|
||||
|
@ -404,7 +403,7 @@ fn lint_uint_literal<'tcx>(
|
|||
_ => bug!(),
|
||||
};
|
||||
if lit_val < min || lit_val > max {
|
||||
let parent_id = cx.tcx.hir().get_parent_node(e.hir_id);
|
||||
let parent_id = cx.tcx.hir().parent_id(e.hir_id);
|
||||
if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) {
|
||||
match par_e.kind {
|
||||
hir::ExprKind::Cast(..) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue