1
Fork 0

get_parent and find_parent

This commit is contained in:
Michael Goulet 2023-01-03 17:30:35 +00:00
parent 6af339dbfa
commit b1b19bd851
29 changed files with 88 additions and 95 deletions

View file

@ -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.parent_id(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);

View file

@ -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.parent_id(ty.hir_id)) {
let span = match hir.find_parent(ty.hir_id) {
Some(Node::Pat(Pat {
kind:
PatKind::Path(qpath)

View file

@ -444,7 +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().parent_id(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.

View file

@ -129,8 +129,7 @@ fn lint_overflowing_range_endpoint<'tcx>(
// which are represented as `ExprKind::Struct`.
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().parent_id(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;
};