diff --git a/Cargo.lock b/Cargo.lock index c31fed86bc8ce..6bc88fb7a6dc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2751,9 +2751,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "200b9ff220857e53e184257720a14553b2f4aa02577d2ed9842d45d4b9654810" +checksum = "f58e5423e24c18cc840e1c98370b3993c6649cd1678b4d24318bcf0a083cbe88" dependencies = [ "cc", ] @@ -4947,9 +4947,9 @@ dependencies = [ [[package]] name = "stacker" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799c883d55abdb5e98af1a7b3f23b9b6de8ecada0ecac058672d7635eb48ca7b" +checksum = "1d08feb8f695b465baed819b03c128dc23f57a694510ab1f06c77f763975685e" dependencies = [ "cc", "cfg-if", diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index b2cc58fbe1160..5a526da0087ed 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -386,7 +386,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } } let tcx = self.infcx.tcx; - let hir = self.infcx.tcx.hir(); if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) { let expr = body.value; let place = &self.move_data.move_paths[mpi].place; @@ -402,7 +401,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { if let Some(span) = span && let Some(expr) = finder.expr { - for (_, expr) in hir.parent_iter(expr.hir_id) { + for (_, expr) in tcx.hir_parent_iter(expr.hir_id) { if let hir::Node::Expr(expr) = expr { if expr.span.contains(span) { // If the let binding occurs within the same loop, then that @@ -969,7 +968,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let mut parent = None; // The top-most loop where the moved expression could be moved to a new binding. let mut outer_most_loop: Option<&hir::Expr<'_>> = None; - for (_, node) in tcx.hir().parent_iter(expr.hir_id) { + for (_, node) in tcx.hir_parent_iter(expr.hir_id) { let e = match node { hir::Node::Expr(e) => e, hir::Node::LetStmt(hir::LetStmt { els: Some(els), .. }) => { @@ -1021,8 +1020,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } } let loop_count: usize = tcx - .hir() - .parent_iter(expr.hir_id) + .hir_parent_iter(expr.hir_id) .map(|(_, node)| match node { hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Loop(..), .. }) => 1, _ => 0, @@ -1048,8 +1046,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { .collect::>(); // All of the spans for the loops above the expression with the move error. let loop_spans: Vec<_> = tcx - .hir() - .parent_iter(expr.hir_id) + .hir_parent_iter(expr.hir_id) .filter_map(|(_, node)| match node { hir::Node::Expr(hir::Expr { span, kind: hir::ExprKind::Loop(..), .. }) => { Some(*span) @@ -1334,7 +1331,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } fn in_move_closure(&self, expr: &hir::Expr<'_>) -> bool { - for (_, node) in self.infcx.tcx.hir().parent_iter(expr.hir_id) { + for (_, node) in self.infcx.tcx.hir_parent_iter(expr.hir_id) { if let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) = node && let hir::CaptureBy::Value { .. } = closure.capture_clause { @@ -2118,7 +2115,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { issued_span: Span, ) { let tcx = self.infcx.tcx; - let hir = tcx.hir(); let has_split_at_mut = |ty: Ty<'tcx>| { let ty = ty.peel_refs(); @@ -2171,7 +2167,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { return; }; - let Some(object) = hir.parent_id_iter(index1.hir_id).find_map(|id| { + let Some(object) = tcx.hir_parent_id_iter(index1.hir_id).find_map(|id| { if let hir::Node::Expr(expr) = tcx.hir_node(id) && let hir::ExprKind::Index(obj, ..) = expr.kind { @@ -2189,7 +2185,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { return; }; - let Some(swap_call) = hir.parent_id_iter(object.hir_id).find_map(|id| { + let Some(swap_call) = tcx.hir_parent_id_iter(object.hir_id).find_map(|id| { if let hir::Node::Expr(call) = tcx.hir_node(id) && let hir::ExprKind::Call(callee, ..) = call.kind && let hir::ExprKind::Path(qpath) = callee.kind diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index a88b27f24767e..b2b66eabb38b8 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -117,7 +117,7 @@ impl<'tcx> BorrowExplanation<'tcx> { let local_decl = &body.local_decls[dropped_local]; if let &LocalInfo::IfThenRescopeTemp { if_then } = local_decl.local_info() - && let Some((_, hir::Node::Expr(expr))) = tcx.hir().parent_iter(if_then).next() + && let Some((_, hir::Node::Expr(expr))) = tcx.hir_parent_iter(if_then).next() && let hir::ExprKind::If(cond, conseq, alt) = expr.kind && let hir::ExprKind::Let(&hir::LetExpr { span: _, @@ -522,7 +522,7 @@ fn suggest_rewrite_if_let( ); if expr.span.can_be_used_for_suggestions() && conseq.span.can_be_used_for_suggestions() { let needs_block = if let Some(hir::Node::Expr(expr)) = - alt.and_then(|alt| tcx.hir().parent_iter(alt.hir_id).next()).map(|(_, node)| node) + alt.and_then(|alt| tcx.hir_parent_iter(alt.hir_id).next()).map(|(_, node)| node) { matches!(expr.kind, hir::ExprKind::If(..)) } else { diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index ddf6187a662e5..5e83d2ffa97a1 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -388,7 +388,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // Search for an appropriate place for the structured `.clone()` suggestion to be applied. // If we encounter a statement before the borrow error, we insert a statement there. - for (_, node) in tcx.hir().parent_iter(closure_expr.hir_id) { + for (_, node) in tcx.hir_parent_iter(closure_expr.hir_id) { if let Node::Stmt(stmt) = node { let padding = tcx .sess diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index be83e61f75d8b..be4a7736b1c20 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -404,7 +404,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { pat.kind { if upvar_ident.name == kw::SelfLower { - for (_, node) in self.infcx.tcx.hir().parent_iter(upvar_hir_id) { + for (_, node) in self.infcx.tcx.hir_parent_iter(upvar_hir_id) { if let Some(fn_decl) = node.fn_decl() { if !matches!( fn_decl.implicit_self, @@ -934,7 +934,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { err.span_label(sp, format!("cannot {act}")); let tcx = self.infcx.tcx; - let hir = tcx.hir(); let closure_id = self.mir_hir_id(); let closure_span = tcx.def_span(self.mir_def_id()); let fn_call_id = tcx.parent_hir_id(closure_id); @@ -1017,10 +1016,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } } - if look_at_return && hir.get_fn_id_for_return_block(closure_id).is_some() { + if look_at_return && tcx.hir_get_fn_id_for_return_block(closure_id).is_some() { // ...otherwise we are probably in the tail expression of the function, point at the // return type. - match tcx.hir_node_by_def_id(hir.get_parent_item(fn_call_id).def_id) { + match tcx.hir_node_by_def_id(tcx.hir_get_parent_item(fn_call_id).def_id) { hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn { sig, .. }, .. }) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index b036e6e950b9b..88804560f28e2 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -671,7 +671,6 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { #[instrument(level = "trace", skip(self))] fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Option { let tcx = self.infcx.tcx; - let hir = tcx.hir(); let return_ty = self.regioncx.universal_regions().unnormalized_output_ty; debug!("give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty); @@ -711,7 +710,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { hir::CoroutineSource::Fn, )) => { let parent_item = - tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id); + tcx.hir_node_by_def_id(tcx.hir_get_parent_item(mir_hir_id).def_id); let output = &parent_item .fn_decl() .expect("coroutine lowered from async fn should be in fn") @@ -741,7 +740,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { hir::CoroutineSource::Fn, )) => { let parent_item = - tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id); + tcx.hir_node_by_def_id(tcx.hir_get_parent_item(mir_hir_id).def_id); let output = &parent_item .fn_decl() .expect("coroutine lowered from gen fn should be in fn") @@ -768,7 +767,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { hir::CoroutineSource::Fn, )) => { let parent_item = - tcx.hir_node_by_def_id(hir.get_parent_item(mir_hir_id).def_id); + tcx.hir_node_by_def_id(tcx.hir_get_parent_item(mir_hir_id).def_id); let output = &parent_item .fn_decl() .expect("coroutine lowered from async gen fn should be in fn") diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index faf1300e4731e..e7e4dfa05d0c0 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -358,19 +358,33 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { let field = self.layout.field(bx.cx(), i); let offset = self.layout.fields.offset(i); - let val = if field.is_zst() { - OperandValue::ZeroSized - } else if field.size == self.layout.size { - assert_eq!(offset.bytes(), 0); - if let Some(field_val) = fx.codegen_transmute_operand(bx, *self, field) { - field_val - } else { - // we have to go through memory for things like + if !bx.is_backend_ref(self.layout) && bx.is_backend_ref(field) { + if let BackendRepr::Vector { count, .. } = self.layout.backend_repr + && let BackendRepr::Memory { sized: true } = field.backend_repr + && count.is_power_of_two() + { + assert_eq!(field.size, self.layout.size); + // This is being deprecated, but for now stdarch still needs it for // Newtype vector of array, e.g. #[repr(simd)] struct S([i32; 4]); let place = PlaceRef::alloca(bx, field); self.val.store(bx, place.val.with_type(self.layout)); - bx.load_operand(place).val + return bx.load_operand(place); + } else { + // Part of https://github.com/rust-lang/compiler-team/issues/838 + bug!("Non-ref type {self:?} cannot project to ref field type {field:?}"); } + } + + let val = if field.is_zst() { + OperandValue::ZeroSized + } else if field.size == self.layout.size { + assert_eq!(offset.bytes(), 0); + fx.codegen_transmute_operand(bx, *self, field).unwrap_or_else(|| { + bug!( + "Expected `codegen_transmute_operand` to handle equal-size \ + field {i:?} projection from {self:?} to {field:?}" + ) + }) } else { let (in_scalar, imm) = match (self.val, self.layout.backend_repr) { // Extract a scalar component from a pair. @@ -385,11 +399,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { } } - // `#[repr(simd)]` types are also immediate. - (OperandValue::Immediate(llval), BackendRepr::Vector { .. }) => { - (None, bx.extract_element(llval, bx.cx().const_usize(i as u64))) - } - _ => { span_bug!(fx.mir.span, "OperandRef::extract_field({:?}): not applicable", self) } @@ -415,14 +424,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { imm } } - BackendRepr::Memory { sized: true } => { - span_bug!( - fx.mir.span, - "Projecting into a simd type with padding doesn't work; \ - See ", - ); - } - BackendRepr::ScalarPair(_, _) | BackendRepr::Memory { sized: false } => bug!(), + BackendRepr::ScalarPair(_, _) | BackendRepr::Memory { .. } => bug!(), }) }; diff --git a/compiler/rustc_data_structures/src/stack.rs b/compiler/rustc_data_structures/src/stack.rs index 102b364091154..3d6d000348324 100644 --- a/compiler/rustc_data_structures/src/stack.rs +++ b/compiler/rustc_data_structures/src/stack.rs @@ -17,18 +17,6 @@ const STACK_PER_RECURSION: usize = 16 * 1024 * 1024; // 16MB /// /// Should not be sprinkled around carelessly, as it causes a little bit of overhead. #[inline] -#[cfg(not(miri))] pub fn ensure_sufficient_stack(f: impl FnOnce() -> R) -> R { stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f) } - -/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations -/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit -/// from this. -/// -/// Should not be sprinkled around carelessly, as it causes a little bit of overhead. -#[cfg(miri)] -#[inline] -pub fn ensure_sufficient_stack(f: impl FnOnce() -> R) -> R { - f() -} diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 516ecbcfe0ef9..b1b046d71752b 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -482,7 +482,7 @@ fn best_definition_site_of_opaque<'tcx>( None } hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: false, .. } => { - let scope = tcx.hir().get_defining_scope(tcx.local_def_id_to_hir_id(opaque_def_id)); + let scope = tcx.hir_get_defining_scope(tcx.local_def_id_to_hir_id(opaque_def_id)); let found = if scope == hir::CRATE_HIR_ID { tcx.hir_walk_toplevel_module(&mut locator) } else { diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 7b3c3ea2bb46b..1c5455710db8a 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -127,7 +127,7 @@ fn get_owner_return_paths( def_id: LocalDefId, ) -> Option<(LocalDefId, ReturnsVisitor<'_>)> { let hir_id = tcx.local_def_id_to_hir_id(def_id); - let parent_id = tcx.hir().get_parent_item(hir_id).def_id; + let parent_id = tcx.hir_get_parent_item(hir_id).def_id; tcx.hir_node_by_def_id(parent_id).body_id().map(|body_id| { let body = tcx.hir_body(body_id); let mut visitor = ReturnsVisitor::default(); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f98504e19decb..e6ea6eddcaaf3 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -853,7 +853,7 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool { /// In such cases, suggest using `Self` instead. fn check_dyn_incompatible_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) { let (trait_name, trait_def_id) = - match tcx.hir_node_by_def_id(tcx.hir().get_parent_item(item.hir_id()).def_id) { + match tcx.hir_node_by_def_id(tcx.hir_get_parent_item(item.hir_id()).def_id) { hir::Node::Item(item) => match item.kind { hir::ItemKind::Trait(..) => (item.ident, item.owner_id), _ => return, diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 75ea207a06bb1..5bb77c096dcf8 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -469,7 +469,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { let item = self .tcx .hir() - .expect_item(self.tcx.hir().get_parent_item(self.hir_id()).def_id); + .expect_item(self.tcx.hir_get_parent_item(self.hir_id()).def_id); match &item.kind { hir::ItemKind::Enum(_, generics) | hir::ItemKind::Struct(_, generics) @@ -1349,7 +1349,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn } Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => { - let adt_def_id = tcx.hir().get_parent_item(hir_id).def_id.to_def_id(); + let adt_def_id = tcx.hir_get_parent_item(hir_id).def_id.to_def_id(); let ty = tcx.type_of(adt_def_id).instantiate_identity(); let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id).instantiate_identity()); // constructors for structs with `layout_scalar_valid_range` are unsafe to call diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index c0902398a54ae..a363076b75ac1 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -71,7 +71,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { | Node::Variant(_) | Node::Ctor(..) | Node::Field(_) => { - let parent_id = tcx.hir().get_parent_item(hir_id); + let parent_id = tcx.hir_get_parent_item(hir_id); Some(parent_id.to_def_id()) } // FIXME(#43408) always enable this once `lazy_normalization` is @@ -90,12 +90,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { let parent_did = if let DefKind::AnonConst = tcx.def_kind(parent_did) { parent_did } else { - tcx.hir().get_parent_item(hir_id).to_def_id() + tcx.hir_get_parent_item(hir_id).to_def_id() }; debug!(?parent_did); let mut in_param_ty = false; - for (_parent, node) in tcx.hir().parent_iter(hir_id) { + for (_parent, node) in tcx.hir_parent_iter(hir_id) { if let Some(generics) = node.generics() { let mut visitor = AnonConstInParamTyDetector { in_param_ty: false, ct: hir_id }; diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 7b1fff157b54e..5b511d270743b 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -382,8 +382,7 @@ fn const_evaluatable_predicates_of<'tcx>( fn is_const_param_default(tcx: TyCtxt<'_>, def: LocalDefId) -> bool { let hir_id = tcx.local_def_id_to_hir_id(def); let (_, parent_node) = tcx - .hir() - .parent_iter(hir_id) + .hir_parent_iter(hir_id) .skip_while(|(_, n)| matches!(n, Node::ConstArg(..))) .next() .unwrap(); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 293a095b41d0c..717713d93399d 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -107,7 +107,7 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx } } Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => { - tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx) + tcx.adt_def(tcx.hir_get_parent_item(hir_id)).repr().discr_type().to_ty(tcx) } // Sort of affects the type system, but only for the purpose of diagnostics // so no need for ConstArg. @@ -257,7 +257,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ } } ImplItemKind::Type(ty) => { - if tcx.impl_trait_ref(tcx.hir().get_parent_item(hir_id)).is_none() { + if tcx.impl_trait_ref(tcx.hir_get_parent_item(hir_id)).is_none() { check_feature_inherent_assoc_ty(tcx, item.span); } @@ -341,7 +341,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def { VariantData::Unit(..) | VariantData::Struct { .. } => { - tcx.type_of(tcx.hir().get_parent_item(hir_id)).instantiate_identity() + tcx.type_of(tcx.hir_get_parent_item(hir_id)).instantiate_identity() } VariantData::Tuple(_, _, ctor) => { let args = ty::GenericArgs::identity_for_item(tcx, def_id); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index 0c36888f36394..399c4fbe55a9c 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -83,7 +83,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type( #[instrument(skip(tcx), level = "debug")] pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> { let hir_id = tcx.local_def_id_to_hir_id(def_id); - let scope = tcx.hir().get_defining_scope(hir_id); + let scope = tcx.hir_get_defining_scope(hir_id); let mut locator = TaitConstraintLocator { def_id, tcx, found: None, typeck_types: vec![] }; debug!(?scope); diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index 681e8e36d589a..610b293a114e6 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -134,9 +134,9 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { // is from the 'of_trait' field of the enclosing impl let parent = self.tcx.parent_hir_node(self.path_segment.hir_id); - let parent_item = self.tcx.hir_node_by_def_id( - self.tcx.hir().get_parent_item(self.path_segment.hir_id).def_id, - ); + let parent_item = self + .tcx + .hir_node_by_def_id(self.tcx.hir_get_parent_item(self.path_segment.hir_id).def_id); // Get the HIR id of the trait ref let hir::Node::TraitRef(hir::TraitRef { hir_ref_id: trait_ref_id, .. }) = parent else { @@ -343,7 +343,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let mut ret = Vec::new(); let mut ty_id = None; - for (id, node) in self.tcx.hir().parent_iter(path_hir_id) { + for (id, node) in self.tcx.hir_parent_iter(path_hir_id) { debug!(?id); if let hir::Node::Ty(_) = node { ty_id = Some(id); @@ -437,8 +437,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { ) -> String { let is_in_a_method_call = self .tcx - .hir() - .parent_iter(self.path_segment.hir_id) + .hir_parent_iter(self.path_segment.hir_id) .skip(1) .find_map(|(_, node)| match node { hir::Node::Expr(expr) => Some(expr), diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 75c97001c3277..dd346ed1f97a5 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -736,8 +736,7 @@ fn check_assoc_const_binding_type<'tcx>( .map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty }); let enclosing_item_owner_id = tcx - .hir() - .parent_owner_iter(hir_id) + .hir_parent_owner_iter(hir_id) .find_map(|(owner_id, parent)| parent.generics().map(|_| owner_id)) .unwrap(); let generics = tcx.generics_of(enclosing_item_owner_id); diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index d2789cc0fd627..d644a1f224c7e 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -223,7 +223,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // inside an opaque type while we're interested in the overarching type alias (TAIT). // FIXME: However, for trait aliases, this incorrectly returns the enclosing module... && let item_def_id = - tcx.hir().get_parent_item(tcx.local_def_id_to_hir_id(ty_param_def_id)) + tcx.hir_get_parent_item(tcx.local_def_id_to_hir_id(ty_param_def_id)) // FIXME: ...which obviously won't have any generics. && let Some(generics) = tcx.hir_get_generics(item_def_id.def_id) { @@ -979,7 +979,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { qself: &hir::Ty<'_>, ) -> Result<(), ErrorGuaranteed> { let tcx = self.tcx(); - if let Some((_, node)) = tcx.hir().parent_iter(qself.hir_id).skip(1).next() + if let Some((_, node)) = tcx.hir_parent_iter(qself.hir_id).skip(1).next() && let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Path(hir::QPath::TypeRelative( @@ -1278,8 +1278,7 @@ pub fn prohibit_assoc_item_constraint( // Get the parent impl block based on the binding we have // and the trait DefId let impl_block = tcx - .hir() - .parent_iter(constraint.hir_id) + .hir_parent_iter(constraint.hir_id) .find_map(|(_, node)| node.impl_block_of_trait(def_id)); let type_with_constraints = diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index 17de64db6290c..8d58a3bfbd3c5 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -542,8 +542,7 @@ pub(crate) fn check_generic_arg_count( // ``` let parent_is_impl_block = cx .tcx() - .hir() - .parent_owner_iter(seg.hir_id) + .hir_parent_owner_iter(seg.hir_id) .next() .is_some_and(|(_, owner_node)| owner_node.is_impl_block()); if parent_is_impl_block { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs index 44f7a035a10fc..f5e075367f336 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs @@ -130,7 +130,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { diag: &mut Diag<'_, G>, ) { let tcx = self.tcx(); - let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id; + let parent_id = tcx.hir_get_parent_item(self_ty.hir_id).def_id; if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(hir::Impl { self_ty: impl_self_ty, of_trait, generics, .. }), .. @@ -191,7 +191,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// Make sure that we are in the condition to suggest `impl Trait`. fn maybe_suggest_impl_trait(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) -> bool { let tcx = self.tcx(); - let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id; + let parent_id = tcx.hir_get_parent_item(self_ty.hir_id).def_id; // FIXME: If `type_alias_impl_trait` is enabled, also look for `Trait0` // and suggest `Trait0`. // Functions are found in three different contexts. @@ -321,7 +321,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { } fn maybe_suggest_assoc_ty_bound(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) { - let mut parents = self.tcx().hir().parent_iter(self_ty.hir_id); + let mut parents = self.tcx().hir_parent_iter(self_ty.hir_id); if let Some((_, hir::Node::AssocItemConstraint(constraint))) = parents.next() && let Some(obj_ty) = constraint.ty() diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index e9b99caf737b4..fcd0d4d40fd4c 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1673,8 +1673,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { debug!(item_def_id = ?def_id); // FIXME: document why/how this is different from `tcx.local_parent(def_id)` - let parent_def_id = - tcx.hir().get_parent_item(tcx.local_def_id_to_hir_id(def_id)).to_def_id(); + let parent_def_id = tcx.hir_get_parent_item(tcx.local_def_id_to_hir_id(def_id)).to_def_id(); debug!(?parent_def_id); // If the trait in segment is the same as the trait defining the item, diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 0859a39b15566..bdfbd540e40a3 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -251,7 +251,7 @@ pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { // In case there are any projections, etc., find the "environment" // def-ID that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. - let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id); + let env_def_id = tcx.hir_get_parent_item(hir_ty.hir_id); collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty) } @@ -262,6 +262,6 @@ pub fn lower_const_arg_for_rustdoc<'tcx>( hir_ct: &hir::ConstArg<'tcx>, feed: FeedConstTy, ) -> Const<'tcx> { - let env_def_id = tcx.hir().get_parent_item(hir_ct.hir_id); + let env_def_id = tcx.hir_get_parent_item(hir_ct.hir_id); collect::ItemCtxt::new(tcx, env_def_id.def_id).lowerer().lower_const_arg(hir_ct, feed) } diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs index c43917649de2e..32b05dcc569ef 100644 --- a/compiler/rustc_hir_analysis/src/outlives/mod.rs +++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs @@ -37,7 +37,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau // parent of generics returned by `generics_of` // // In the above code we want the anon const to have predicates in its param env for `'b: 'a` - let item_def_id = tcx.hir().get_parent_item(id); + let item_def_id = tcx.hir_get_parent_item(id); // In the above code example we would be calling `inferred_outlives_of(Foo)` here tcx.inferred_outlives_of(item_def_id) } else { diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 49ea2181b075a..5de3c05c63c58 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -346,7 +346,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; }; - let hir = self.tcx.hir(); let fn_decl_span = if let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }), .. @@ -368,7 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }), .. }), - )) = hir.parent_iter(hir_id).nth(3) + )) = self.tcx.hir_parent_iter(hir_id).nth(3) { // Actually need to unwrap one more layer of HIR to get to // the _real_ closure... diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index cf11bccae0ac0..625c7f38fbb40 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1752,7 +1752,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { return false; } let Some((_, hir::Node::Expr(expr))) = - fcx.tcx.hir().parent_iter(id).nth(1) + fcx.tcx.hir_parent_iter(id).nth(1) else { return false; }; @@ -1909,7 +1909,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { found, block_or_return_id, ); - if let Some(cond_expr) = fcx.tcx.hir().get_if_cause(expr.hir_id) + if let Some(cond_expr) = fcx.tcx.hir_get_if_cause(expr.hir_id) && expected.is_unit() && !pointing_at_return_type // If the block is from an external macro or try (`?`) desugaring, then diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 4dc736f72cf8c..38c07e473db3b 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -156,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && segment.ident.name.as_str() == name && let Res::Local(hir_id) = path.res && let Some((_, hir::Node::Expr(match_expr))) = - self.tcx.hir().parent_iter(hir_id).nth(2) + self.tcx.hir_parent_iter(hir_id).nth(2) && let hir::ExprKind::Match(scrutinee, _, _) = match_expr.kind && let hir::ExprKind::Tup(exprs) = scrutinee.kind && let hir::ExprKind::AddrOf(_, _, macro_arg) = exprs[idx].kind @@ -841,7 +841,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // The pattern we have is an fn argument. && let hir::Node::Param(hir::Param { ty_span, .. }) = self.tcx.parent_hir_node(pat.hir_id) - && let item = self.tcx.hir().get_parent_item(pat.hir_id) + && let item = self.tcx.hir_get_parent_item(pat.hir_id) && let item = self.tcx.hir_owner_node(item) && let Some(fn_decl) = item.fn_decl() diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 1c63b8b365594..277396da19c13 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1130,7 +1130,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { statement_kind: kind, }; - let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id); + let encl_item_id = self.tcx.hir_get_parent_item(expr.hir_id); if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { .. }, @@ -1279,7 +1279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Check if our original expression is a child of the condition of a while loop. // If it is, then we have a situation like `while Some(0) = value.get(0) {`, // where `while let` was more likely intended. - if self.tcx.hir().parent_id_iter(original_expr_id).any(|id| id == expr.hir_id) { + if self.tcx.hir_parent_id_iter(original_expr_id).any(|id| id == expr.hir_id) { then(expr); } break; @@ -1774,7 +1774,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) { - let parent_node = self.tcx.hir().parent_iter(expr.hir_id).find(|(_, node)| { + let parent_node = self.tcx.hir_parent_iter(expr.hir_id).find(|(_, node)| { !matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. })) }); let Some((_, hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }))) = parent_node else { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index ff41a080d6290..2d7d80e39bc31 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -856,7 +856,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>)> { // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // `while` before reaching it, as block tail returns are not available in them. - self.tcx.hir().get_fn_id_for_return_block(blk_id).and_then(|item_id| { + self.tcx.hir_get_fn_id_for_return_block(blk_id).and_then(|item_id| { match self.tcx.hir_node(item_id) { Node::Item(&hir::Item { kind: hir::ItemKind::Fn { sig, .. }, owner_id, .. diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 7ca44d23e3ed6..cf61659479b13 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -2052,7 +2052,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } fn parent_item_span(&self, id: HirId) -> Option { - let node = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(id).def_id); + let node = self.tcx.hir_node_by_def_id(self.tcx.hir_get_parent_item(id).def_id); match node { Node::Item(&hir::Item { kind: hir::ItemKind::Fn { body: body_id, .. }, .. }) | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => { @@ -2179,7 +2179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { let mut block_num = 0; let mut found_semi = false; - for (hir_id, node) in self.tcx.hir().parent_iter(binding_hir_id) { + for (hir_id, node) in self.tcx.hir_parent_iter(binding_hir_id) { // Don't proceed into parent bodies if hir_id.owner != binding_hir_id.owner { break; @@ -2521,7 +2521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Try to find earlier invocations of this closure to find if the type mismatch // is because of inference. If we find one, point at them. let mut call_finder = FindClosureArg { tcx: self.tcx, calls: vec![] }; - let parent_def_id = self.tcx.hir().get_parent_item(call_expr.hir_id).def_id; + let parent_def_id = self.tcx.hir_get_parent_item(call_expr.hir_id).def_id; match self.tcx.hir_node_by_def_id(parent_def_id) { hir::Node::Item(item) => call_finder.visit_item(item), hir::Node::TraitItem(item) => call_finder.visit_trait_item(item), diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 347a6557c2aab..f9fc121593637 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -308,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let mut tuple_indexes = Vec::new(); let mut expr_id = expr.hir_id; - for (parent_id, node) in self.tcx.hir().parent_iter(expr.hir_id) { + for (parent_id, node) in self.tcx.hir_parent_iter(expr.hir_id) { match node { Node::Expr(&Expr { kind: ExprKind::Tup(subs), .. }) => { tuple_indexes.push( @@ -565,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { found: Ty<'tcx>, ) -> bool { // Do not suggest `Box::new` in const context. - if self.tcx.hir().is_inside_const_context(hir_id) || !expected.is_box() || found.is_box() { + if self.tcx.hir_is_inside_const_context(hir_id) || !expected.is_box() || found.is_box() { return false; } if self.may_coerce(Ty::new_box(self.tcx, found), expected) { @@ -645,7 +645,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> bool { // Handle #68197. - if self.tcx.hir().is_inside_const_context(expr.hir_id) { + if self.tcx.hir_is_inside_const_context(expr.hir_id) { // Do not suggest `Box::new` in const context. return false; } @@ -1084,8 +1084,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let in_loop = self.is_loop(id) || self .tcx - .hir() - .parent_iter(id) + .hir_parent_iter(id) .take_while(|(_, node)| { // look at parents until we find the first body owner node.body_id().is_none() @@ -1095,8 +1094,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let in_local_statement = self.is_local_statement(id) || self .tcx - .hir() - .parent_iter(id) + .hir_parent_iter(id) .any(|(parent_id, _)| self.is_local_statement(parent_id)); if in_loop && in_local_statement { @@ -1111,7 +1109,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } - let scope = self.tcx.hir().parent_iter(id).find(|(_, node)| { + let scope = self.tcx.hir_parent_iter(id).find(|(_, node)| { matches!( node, Node::Expr(Expr { kind: ExprKind::Closure(..), .. }) @@ -1168,7 +1166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // -------------^^^^^^^- // Don't add semicolon `;` at the end of `dbg!(x)` expr fn is_in_arm<'tcx>(expr: &'tcx hir::Expr<'tcx>, tcx: TyCtxt<'tcx>) -> bool { - for (_, node) in tcx.hir().parent_iter(expr.hir_id) { + for (_, node) in tcx.hir_parent_iter(expr.hir_id) { match node { hir::Node::Block(block) => { if let Some(ret) = block.expr @@ -1411,8 +1409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return false; } - let hir = self.tcx.hir(); - let cond_parent = hir.parent_iter(expr.hir_id).find(|(_, node)| { + let cond_parent = self.tcx.hir_parent_iter(expr.hir_id).find(|(_, node)| { !matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And) }); // Don't suggest: @@ -2048,11 +2045,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, found: Ty<'tcx>, ) -> bool { - let map = self.tcx.hir(); let returned = matches!( self.tcx.parent_hir_node(expr.hir_id), hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Ret(_), .. }) - ) || map.get_fn_id_for_return_block(expr.hir_id).is_some(); + ) || self.tcx.hir_get_fn_id_for_return_block(expr.hir_id).is_some(); if returned && let ty::Adt(e, args_e) = expected.kind() && let ty::Adt(f, args_f) = found.kind() @@ -2095,9 +2091,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, ) -> bool { let tcx = self.tcx; - let hir = tcx.hir(); let enclosing_scope = - hir.get_enclosing_scope(expr.hir_id).map(|hir_id| tcx.hir_node(hir_id)); + tcx.hir_get_enclosing_scope(expr.hir_id).map(|hir_id| tcx.hir_node(hir_id)); // Get tail expr of the enclosing block or body let tail_expr = if let Some(Node::Block(hir::Block { expr, .. })) = enclosing_scope @@ -3098,7 +3093,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |expr: &hir::Expr<'_>| matches!(expr.kind, hir::ExprKind::Unary(hir::UnOp::Neg, ..)); let is_uint = |ty: Ty<'_>| matches!(ty.kind(), ty::Uint(..)); - let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id); + let in_const_context = self.tcx.hir_is_inside_const_context(expr.hir_id); let suggest_fallible_into_or_lhs_from = |err: &mut Diag<'_>, exp_to_found_is_fallible: bool| { @@ -3142,7 +3137,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let suggest_to_change_suffix_or_into = |err: &mut Diag<'_>, found_to_exp_is_fallible: bool, exp_to_found_is_fallible: bool| { - let exp_is_lhs = expected_ty_expr.is_some_and(|e| self.tcx.hir().is_lhs(e.hir_id)); + let exp_is_lhs = expected_ty_expr.is_some_and(|e| self.tcx.hir_is_lhs(e.hir_id)); if exp_is_lhs { return; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 780ab8c18334d..c757d089478f5 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -2390,7 +2390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { long_ty_path: &mut Option, ) -> Result<(), ErrorGuaranteed> { if let SelfSource::MethodCall(expr) = source { - for (_, parent) in tcx.hir().parent_iter(expr.hir_id).take(5) { + for (_, parent) in tcx.hir_parent_iter(expr.hir_id).take(5) { if let Node::Expr(parent_expr) = parent { let lang_item = match parent_expr.kind { ExprKind::Struct(qpath, _, _) => match *qpath { diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index e63cc090993f8..c56396c38c956 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -946,7 +946,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let var_ty = self.resolve_vars_if_possible(var_ty); let msg = format!("first introduced with type `{var_ty}` here"); err.span_label(hir.span(var_id), msg); - let in_match = hir.parent_iter(var_id).any(|(_, n)| { + let in_match = self.tcx.hir_parent_iter(var_id).any(|(_, n)| { matches!( n, hir::Node::Expr(hir::Expr { diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 762d04fdedd48..9a0b22470585f 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -1934,7 +1934,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>( /// Returns the Span of where the value with the provided HirId would be dropped fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span { - let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap(); + let owner_id = tcx.hir_get_enclosing_scope(hir_id).unwrap(); let owner_node = tcx.hir_node(owner_id); let owner_span = match owner_node { diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index e449f1106131d..b5f09ff346a7a 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -466,7 +466,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { MethodLateContext::TraitAutoImpl => {} // If the method is an impl for an item with docs_hidden, don't doc. MethodLateContext::PlainImpl => { - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); + let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()); let impl_ty = cx.tcx.type_of(parent).instantiate_identity(); let outerdef = match impl_ty.kind() { ty::Adt(def, _) => Some(def.did()), diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs index 1ca2e4e74ea6f..7f098893f7de5 100644 --- a/compiler/rustc_lint/src/drop_forget_useless.rs +++ b/compiler/rustc_lint/src/drop_forget_useless.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { let is_copy = cx.type_is_copy_modulo_regions(arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let let_underscore_ignore_sugg = || { - if let Some((_, node)) = cx.tcx.hir().parent_iter(expr.hir_id).nth(0) + if let Some((_, node)) = cx.tcx.hir_parent_iter(expr.hir_id).nth(0) && let Node::Stmt(stmt) = node && let StmtKind::Semi(e) = stmt.kind && e.hir_id == expr.hir_id diff --git a/compiler/rustc_lint/src/if_let_rescope.rs b/compiler/rustc_lint/src/if_let_rescope.rs index 869dab6799d02..c1aa95667da68 100644 --- a/compiler/rustc_lint/src/if_let_rescope.rs +++ b/compiler/rustc_lint/src/if_let_rescope.rs @@ -95,7 +95,7 @@ pub(crate) struct IfLetRescope { } fn expr_parent_is_else(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { - let Some((_, hir::Node::Expr(expr))) = tcx.hir().parent_iter(hir_id).next() else { + let Some((_, hir::Node::Expr(expr))) = tcx.hir_parent_iter(hir_id).next() else { return false; }; let hir::ExprKind::If(_cond, _conseq, Some(alt)) = expr.kind else { return false }; @@ -103,7 +103,7 @@ fn expr_parent_is_else(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { } fn expr_parent_is_stmt(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { - let mut parents = tcx.hir().parent_iter(hir_id); + let mut parents = tcx.hir_parent_iter(hir_id); let stmt = match parents.next() { Some((_, hir::Node::Stmt(stmt))) => stmt, Some((_, hir::Node::Block(_) | hir::Node::Arm(_))) => return true, diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index ddc9ae1594f90..1f999bbea5fe7 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -497,7 +497,7 @@ impl Diagnostics { return; }; - for (hir_id, _parent) in cx.tcx.hir().parent_iter(current_id) { + for (hir_id, _parent) in cx.tcx.hir_parent_iter(current_id) { if let Some(owner_did) = hir_id.as_owner() && cx.tcx.has_attr(owner_did, sym::rustc_lint_diagnostics) { @@ -512,7 +512,7 @@ impl Diagnostics { // // Otherwise, emit a `DIAGNOSTIC_OUTSIDE_OF_IMPL` lint. let mut is_inside_appropriate_impl = false; - for (_hir_id, parent) in cx.tcx.hir().parent_iter(current_id) { + for (_hir_id, parent) in cx.tcx.hir_parent_iter(current_id) { debug!(?parent); if let Node::Item(Item { kind: ItemKind::Impl(impl_), .. }) = parent && let Impl { of_trait: Some(of_trait), .. } = impl_ diff --git a/compiler/rustc_lint/src/shadowed_into_iter.rs b/compiler/rustc_lint/src/shadowed_into_iter.rs index 7cc35e20fcb64..571cab934fd6a 100644 --- a/compiler/rustc_lint/src/shadowed_into_iter.rs +++ b/compiler/rustc_lint/src/shadowed_into_iter.rs @@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for ShadowedIntoIter { // we should just suggest removing the `.into_iter()` or changing it to `.iter()` // to disambiguate if we want to iterate by-value or by-ref. let sub = if let Some((_, hir::Node::Expr(parent_expr))) = - cx.tcx.hir().parent_iter(expr.hir_id).nth(1) + cx.tcx.hir_parent_iter(expr.hir_id).nth(1) && let hir::ExprKind::Match(arg, [_], hir::MatchSource::ForLoopDesugar) = &parent_expr.kind && let hir::ExprKind::Call(path, [_]) = &arg.kind diff --git a/compiler/rustc_lint/src/unqualified_local_imports.rs b/compiler/rustc_lint/src/unqualified_local_imports.rs index b27398a950c81..50c5119285f7c 100644 --- a/compiler/rustc_lint/src/unqualified_local_imports.rs +++ b/compiler/rustc_lint/src/unqualified_local_imports.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for UnqualifiedLocalImports { return; } - let encl_item_id = cx.tcx.hir().get_parent_item(item.hir_id()); + let encl_item_id = cx.tcx.hir_get_parent_item(item.hir_id()); let encl_item = cx.tcx.hir_node_by_def_id(encl_item_id.def_id); if encl_item.fn_kind().is_some() { // `use` in a method -- don't lint, that leads to too many undesirable lints diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 3436c2f372f49..40dd6aa73fd4c 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -28,22 +28,22 @@ pub struct Map<'hir> { } /// An iterator that walks up the ancestor tree of a given `HirId`. -/// Constructed using `tcx.hir().parent_iter(hir_id)`. -struct ParentHirIterator<'hir> { +/// Constructed using `tcx.hir_parent_iter(hir_id)`. +struct ParentHirIterator<'tcx> { current_id: HirId, - map: Map<'hir>, + tcx: TyCtxt<'tcx>, // Cache the current value of `hir_owner_nodes` to avoid repeatedly calling the same query for // the same owner, which will uselessly record many times the same query dependency. - current_owner_nodes: Option<&'hir OwnerNodes<'hir>>, + current_owner_nodes: Option<&'tcx OwnerNodes<'tcx>>, } -impl<'hir> ParentHirIterator<'hir> { - fn new(map: Map<'hir>, current_id: HirId) -> ParentHirIterator<'hir> { - ParentHirIterator { current_id, map, current_owner_nodes: None } +impl<'tcx> ParentHirIterator<'tcx> { + fn new(tcx: TyCtxt<'tcx>, current_id: HirId) -> ParentHirIterator<'tcx> { + ParentHirIterator { current_id, tcx, current_owner_nodes: None } } } -impl<'hir> Iterator for ParentHirIterator<'hir> { +impl<'tcx> Iterator for ParentHirIterator<'tcx> { type Item = HirId; fn next(&mut self) -> Option { @@ -56,10 +56,10 @@ impl<'hir> Iterator for ParentHirIterator<'hir> { let parent_id = if local_id == ItemLocalId::ZERO { // We go from an owner to its parent, so clear the cache. self.current_owner_nodes = None; - self.map.tcx.hir_owner_parent(owner) + self.tcx.hir_owner_parent(owner) } else { let owner_nodes = - self.current_owner_nodes.get_or_insert_with(|| self.map.tcx.hir_owner_nodes(owner)); + self.current_owner_nodes.get_or_insert_with(|| self.tcx.hir_owner_nodes(owner)); let parent_local_id = owner_nodes.nodes[local_id].parent; // HIR indexing should have checked that. debug_assert_ne!(parent_local_id, local_id); @@ -74,33 +74,33 @@ impl<'hir> Iterator for ParentHirIterator<'hir> { } /// An iterator that walks up the ancestor tree of a given `HirId`. -/// Constructed using `tcx.hir().parent_owner_iter(hir_id)`. -pub struct ParentOwnerIterator<'hir> { +/// Constructed using `tcx.hir_parent_owner_iter(hir_id)`. +pub struct ParentOwnerIterator<'tcx> { current_id: HirId, - map: Map<'hir>, + tcx: TyCtxt<'tcx>, } -impl<'hir> Iterator for ParentOwnerIterator<'hir> { - type Item = (OwnerId, OwnerNode<'hir>); +impl<'tcx> Iterator for ParentOwnerIterator<'tcx> { + type Item = (OwnerId, OwnerNode<'tcx>); fn next(&mut self) -> Option { if self.current_id.local_id.index() != 0 { self.current_id.local_id = ItemLocalId::ZERO; - let node = self.map.tcx.hir_owner_node(self.current_id.owner); + let node = self.tcx.hir_owner_node(self.current_id.owner); return Some((self.current_id.owner, node)); } if self.current_id == CRATE_HIR_ID { return None; } - let parent_id = self.map.tcx.hir_def_key(self.current_id.owner.def_id).parent; + let parent_id = self.tcx.hir_def_key(self.current_id.owner.def_id).parent; let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| { let def_id = LocalDefId { local_def_index }; - self.map.tcx.local_def_id_to_hir_id(def_id).owner + self.tcx.local_def_id_to_hir_id(def_id).owner }); self.current_id = HirId::make_owner(parent_id.def_id); - let node = self.map.tcx.hir_owner_node(self.current_id.owner); + let node = self.tcx.hir_owner_node(self.current_id.owner); Some((self.current_id.owner, node)) } } @@ -146,7 +146,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns `HirId` of the parent HIR node of node with this `hir_id`. /// Returns the same `hir_id` if and only if `hir_id == CRATE_HIR_ID`. /// - /// If calling repeatedly and iterating over parents, prefer [`Map::parent_iter`]. + /// If calling repeatedly and iterating over parents, prefer [`TyCtxt::hir_parent_iter`]. pub fn parent_hir_id(self, hir_id: HirId) -> HirId { let HirId { owner, local_id } = hir_id; if local_id == ItemLocalId::ZERO { @@ -242,7 +242,7 @@ impl<'tcx> TyCtxt<'tcx> { #[track_caller] pub fn hir_enclosing_body_owner(self, hir_id: HirId) -> LocalDefId { - for (_, node) in self.hir().parent_iter(hir_id) { + for (_, node) in self.hir_parent_iter(hir_id) { if let Some((def_id, _)) = node.associated_body() { return def_id; } @@ -498,33 +498,31 @@ impl<'tcx> TyCtxt<'tcx> { f(LocalModDefId::new_unchecked(module.def_id)) }) } -} -impl<'hir> Map<'hir> { /// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// until the crate root is reached. Prefer this over your own loop using `parent_id`. #[inline] - pub fn parent_id_iter(self, current_id: HirId) -> impl Iterator + 'hir { + pub fn hir_parent_id_iter(self, current_id: HirId) -> impl Iterator + 'tcx { ParentHirIterator::new(self, current_id) } /// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// until the crate root is reached. Prefer this over your own loop using `parent_id`. #[inline] - pub fn parent_iter(self, current_id: HirId) -> impl Iterator)> { - self.parent_id_iter(current_id).map(move |id| (id, self.tcx.hir_node(id))) + pub fn hir_parent_iter(self, current_id: HirId) -> impl Iterator)> { + self.hir_parent_id_iter(current_id).map(move |id| (id, self.hir_node(id))) } /// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// until the crate root is reached. Prefer this over your own loop using `parent_id`. #[inline] - pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> { - ParentOwnerIterator { current_id, map: self } + pub fn hir_parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'tcx> { + ParentOwnerIterator { current_id, tcx: self } } /// Checks if the node is left-hand side of an assignment. - pub fn is_lhs(self, id: HirId) -> bool { - match self.tcx.parent_hir_node(id) { + pub fn hir_is_lhs(self, id: HirId) -> bool { + match self.parent_hir_node(id) { Node::Expr(expr) => match expr.kind { ExprKind::Assign(lhs, _rhs, _span) => lhs.hir_id == id, _ => false, @@ -535,8 +533,8 @@ impl<'hir> Map<'hir> { /// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context. /// Used exclusively for diagnostics, to avoid suggestion function calls. - pub fn is_inside_const_context(self, hir_id: HirId) -> bool { - self.tcx.hir_body_const_context(self.tcx.hir_enclosing_body_owner(hir_id)).is_some() + pub fn hir_is_inside_const_context(self, hir_id: HirId) -> bool { + self.hir_body_const_context(self.hir_enclosing_body_owner(hir_id)).is_some() } /// Retrieves the `HirId` for `id`'s enclosing function *if* the `id` block or return is @@ -561,12 +559,11 @@ impl<'hir> Map<'hir> { /// false /// } /// ``` - pub fn get_fn_id_for_return_block(self, id: HirId) -> Option { - let enclosing_body_owner = - self.tcx.local_def_id_to_hir_id(self.tcx.hir_enclosing_body_owner(id)); + pub fn hir_get_fn_id_for_return_block(self, id: HirId) -> Option { + let enclosing_body_owner = self.local_def_id_to_hir_id(self.hir_enclosing_body_owner(id)); // Return `None` if the `id` expression is not the returned value of the enclosing body - let mut iter = [id].into_iter().chain(self.parent_id_iter(id)).peekable(); + let mut iter = [id].into_iter().chain(self.hir_parent_id_iter(id)).peekable(); while let Some(cur_id) = iter.next() { if enclosing_body_owner == cur_id { break; @@ -574,14 +571,16 @@ impl<'hir> Map<'hir> { // A return statement is always the value returned from the enclosing body regardless of // what the parent expressions are. - if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = self.tcx.hir_node(cur_id) { + if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = self.hir_node(cur_id) { break; } - // If the current expression's value doesnt get used as the parent expressions value then return `None` + // If the current expression's value doesnt get used as the parent expressions value + // then return `None` if let Some(&parent_id) = iter.peek() { - match self.tcx.hir_node(parent_id) { - // The current node is not the tail expression of the block expression parent expr. + match self.hir_node(parent_id) { + // The current node is not the tail expression of the block expression parent + // expr. Node::Block(Block { expr: Some(e), .. }) if cur_id != e.hir_id => return None, Node::Block(Block { expr: Some(e), .. }) if matches!(e.kind, ExprKind::If(_, _, None)) => @@ -589,7 +588,8 @@ impl<'hir> Map<'hir> { return None; } - // The current expression's value does not pass up through these parent expressions + // The current expression's value does not pass up through these parent + // expressions. Node::Block(Block { expr: None, .. }) | Node::Expr(Expr { kind: ExprKind::Loop(..), .. }) | Node::LetStmt(..) => return None, @@ -606,11 +606,11 @@ impl<'hir> Map<'hir> { /// parent item is in this map. The "parent item" is the closest parent node /// in the HIR which is recorded by the map and is an item, either an item /// in a module, trait, or impl. - pub fn get_parent_item(self, hir_id: HirId) -> OwnerId { + pub fn hir_get_parent_item(self, hir_id: HirId) -> OwnerId { if hir_id.local_id != ItemLocalId::ZERO { // If this is a child of a HIR owner, return the owner. hir_id.owner - } else if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() { + } else if let Some((def_id, _node)) = self.hir_parent_owner_iter(hir_id).next() { def_id } else { CRATE_OWNER_ID @@ -622,8 +622,8 @@ impl<'hir> Map<'hir> { /// /// Used by error reporting when there's a type error in an if or match arm caused by the /// expression needing to be unit. - pub fn get_if_cause(self, hir_id: HirId) -> Option<&'hir Expr<'hir>> { - for (_, node) in self.parent_iter(hir_id) { + pub fn hir_get_if_cause(self, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { + for (_, node) in self.hir_parent_iter(hir_id) { match node { Node::Item(_) | Node::ForeignItem(_) @@ -640,8 +640,8 @@ impl<'hir> Map<'hir> { } /// Returns the nearest enclosing scope. A scope is roughly an item or block. - pub fn get_enclosing_scope(self, hir_id: HirId) -> Option { - for (hir_id, node) in self.parent_iter(hir_id) { + pub fn hir_get_enclosing_scope(self, hir_id: HirId) -> Option { + for (hir_id, node) in self.hir_parent_iter(hir_id) { if let Node::Item(Item { kind: ItemKind::Fn { .. } @@ -667,18 +667,20 @@ impl<'hir> Map<'hir> { } /// Returns the defining scope for an opaque type definition. - pub fn get_defining_scope(self, id: HirId) -> HirId { + pub fn hir_get_defining_scope(self, id: HirId) -> HirId { let mut scope = id; loop { - scope = self.get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID); - if scope == CRATE_HIR_ID || !matches!(self.tcx.hir_node(scope), Node::Block(_)) { + scope = self.hir_get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID); + if scope == CRATE_HIR_ID || !matches!(self.hir_node(scope), Node::Block(_)) { return scope; } } } +} +impl<'hir> Map<'hir> { pub fn get_foreign_abi(self, hir_id: HirId) -> ExternAbi { - let parent = self.get_parent_item(hir_id); + let parent = self.tcx.hir_get_parent_item(hir_id); if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = self.tcx.hir_owner_node(parent) { diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index ab711aca573e5..88bf17070b9c5 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -131,7 +131,7 @@ impl ShallowLintLevelMap { let mut owner = start.owner; let mut specs = &self.specs; - for parent in tcx.hir().parent_id_iter(start) { + for parent in tcx.hir_parent_id_iter(start) { if parent.owner != owner { owner = parent.owner; specs = &tcx.shallow_lint_levels_on(owner).specs; diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 93bbf6d7fa4ff..2260cad41b97c 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -373,7 +373,7 @@ impl<'tcx> TyCtxt<'tcx> { // Deprecated attributes apply in-crate and cross-crate. if let Some(id) = id { if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) { - let parent_def_id = self.hir().get_parent_item(id); + let parent_def_id = self.hir_get_parent_item(id); let skip = self .lookup_deprecation_entry(parent_def_id.to_def_id()) .is_some_and(|parent_depr| parent_depr.same_origin(&depr_entry)); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 35893ad953d1a..32a9e67f9ad53 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1370,7 +1370,6 @@ pub struct GlobalCtxt<'tcx> { // Internal caches for metadata decoding. No need to track deps on this. pub ty_rcache: Lock>>, - pub pred_rcache: Lock>>, /// Caches the results of trait selection. This cache is used /// for things that do not have to do with the parameters in scope. @@ -1601,7 +1600,6 @@ impl<'tcx> TyCtxt<'tcx> { query_system, query_kinds, ty_rcache: Default::default(), - pred_rcache: Default::default(), selection_cache: Default::default(), evaluation_cache: Default::default(), new_solver_evaluation_cache: Default::default(), @@ -3019,7 +3017,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Find the crate root and the appropriate span where `use` and outer attributes can be /// inserted at. pub fn crate_level_attribute_injection_span(self, hir_id: HirId) -> Option { - for (_hir_id, node) in self.hir().parent_iter(hir_id) { + for (_hir_id, node) in self.hir_parent_iter(hir_id) { if let hir::Node::Crate(m) = node { return Some(m.spans.inject_use_span.shrink_to_lo()); } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index a1d44882e63f3..bd1fb0ca41cf9 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -179,7 +179,7 @@ pub struct ResolverGlobalCtxt { pub confused_type_with_std_module: FxIndexMap, pub doc_link_resolutions: FxIndexMap, pub doc_link_traits_in_scope: FxIndexMap>, - pub all_macro_rules: FxHashMap>, + pub all_macro_rules: FxHashSet, pub stripped_cfg_items: Steal>, } diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 84f58f1968db2..d65c2097d226e 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -751,7 +751,7 @@ impl UnsafeOpKind { span: Span, suggest_unsafe_block: bool, ) { - let parent_id = tcx.hir().get_parent_item(hir_id); + let parent_id = tcx.hir_get_parent_item(hir_id); let parent_owner = tcx.hir_owner_node(parent_id); let should_suggest = parent_owner.fn_sig().is_some_and(|sig| { // Do not suggest for safe target_feature functions @@ -921,7 +921,7 @@ impl UnsafeOpKind { hir_context: HirId, unsafe_op_in_unsafe_fn_allowed: bool, ) { - let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| { + let note_non_inherited = tcx.hir_parent_iter(hir_context).find(|(id, node)| { if let hir::Node::Expr(block) = node && let hir::ExprKind::Block(block, _) = block.kind && let hir::BlockCheckMode::UnsafeBlock(_) = block.rules diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 6dbb460d8b15f..18305db28c281 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -1041,7 +1041,7 @@ fn find_fallback_pattern_typo<'tcx>( let mut imported = vec![]; let mut imported_spans = vec![]; let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env); - let parent = cx.tcx.hir().get_parent_item(hir_id); + let parent = cx.tcx.hir_get_parent_item(hir_id); for item in cx.tcx.hir_crate_items(()).free_items() { if let DefKind::Use = cx.tcx.def_kind(item.owner_id) { @@ -1137,7 +1137,7 @@ fn find_fallback_pattern_typo<'tcx>( } else { // Look for local bindings for people that might have gotten confused with how // `let` and `const` works. - for (_, node) in cx.tcx.hir().parent_iter(hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(hir_id) { match node { hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Let(let_stmt), .. }) => { if let hir::PatKind::Binding(_, _, binding_name, _) = let_stmt.pat.kind { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 74c48a45f185a..9a4db612cfed8 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -48,7 +48,7 @@ fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) match impl_item.kind { hir::ImplItemKind::Const(..) => Target::AssocConst, hir::ImplItemKind::Fn(..) => { - let parent_def_id = tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let parent_def_id = tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let containing_item = tcx.hir().expect_item(parent_def_id); let containing_impl_is_for_trait = match &containing_item.kind { hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(), @@ -868,7 +868,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let span = meta.span(); if let Some(location) = match target { Target::AssocTy => { - let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id; + let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id; let containing_item = self.tcx.hir().expect_item(parent_def_id); if Target::from_item(containing_item) == Target::Impl { Some("type alias in implementation block") @@ -877,7 +877,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } Target::AssocConst => { - let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id; + let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id; let containing_item = self.tcx.hir().expect_item(parent_def_id); // We can't link to trait impl's consts. let err = "associated constant in trait implementation block"; @@ -1161,7 +1161,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // insert a bang between `#` and `[...` let bang_span = attr.span.lo() + BytePos(1); let sugg = (attr.style == AttrStyle::Outer - && self.tcx.hir().get_parent_item(hir_id) == CRATE_OWNER_ID) + && self.tcx.hir_get_parent_item(hir_id) == CRATE_OWNER_ID) .then_some(errors::AttrCrateLevelOnlySugg { attr: attr.span.with_lo(bang_span).with_hi(bang_span), }); @@ -1449,7 +1449,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // `#[must_use]` can be applied to a trait method definition with a default body if let Target::Method(MethodKind::Trait { body: true }) = target - && let parent_def_id = self.tcx.hir().get_parent_item(hir_id).def_id + && let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id && let containing_item = self.tcx.hir().expect_item(parent_def_id) && let hir::ItemKind::Trait(..) = containing_item.kind { @@ -2580,7 +2580,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { .. }) ); - let parent_did = self.tcx.hir().get_parent_item(hir_id).to_def_id(); + let parent_did = self.tcx.hir_get_parent_item(hir_id).to_def_id(); let parent_span = self.tcx.def_span(parent_did); let parent_force_inline_attr = self.tcx.get_attr(parent_did, sym::rustc_force_inline); diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index a7bca67e4e4a4..24dc018c66124 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -1623,7 +1623,7 @@ impl<'tcx> Liveness<'_, 'tcx> { && let hir::Node::Pat(pat) = self.ir.tcx.hir_node(var_hid) && let hir::Node::Param(hir::Param { ty_span, .. }) = self.ir.tcx.parent_hir_node(pat.hir_id) - && let item_id = self.ir.tcx.hir().get_parent_item(pat.hir_id) + && let item_id = self.ir.tcx.hir_get_parent_item(pat.hir_id) && let item = self.ir.tcx.hir_owner_node(item_id) && let Some(fn_decl) = item.fn_decl() && let hir::PatKind::Binding(hir::BindingMode::MUT, _hir_id, ident, _) = pat.kind diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index a65859466561a..4124e8a4dd1f8 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -645,7 +645,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { } fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { - let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id()); + let impl_def_id = self.tcx.hir_get_parent_item(ii.hir_id()); if self.tcx.impl_trait_ref(impl_def_id).is_none() { self.check_missing_stability(ii.owner_id.def_id, ii.span); self.check_missing_const_stability(ii.owner_id.def_id, ii.span); diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index c6781ecc56681..87f7eda391d9d 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -1241,7 +1241,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { }; let binding = (res, vis, span, expansion).to_name_binding(self.r.arenas); self.r.set_binding_parent_module(binding, parent_scope.module); - self.r.all_macro_rules.insert(ident.name, res); + self.r.all_macro_rules.insert(ident.name); if is_macro_export { let import = self.r.arenas.alloc_import(ImportData { kind: ImportKind::MacroExport, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 5bc37e09f0890..eb4ac6ce77c9c 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1220,7 +1220,7 @@ pub struct Resolver<'ra, 'tcx> { effective_visibilities: EffectiveVisibilities, doc_link_resolutions: FxIndexMap, doc_link_traits_in_scope: FxIndexMap>, - all_macro_rules: FxHashMap, + all_macro_rules: FxHashSet, /// Invocation ids of all glob delegations. glob_delegation_invoc_ids: FxHashSet, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs index 5b8d48e3ca9e9..3f15a79271d5b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs @@ -146,7 +146,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { if let ObligationCauseCode::ReturnValue(hir_id) | ObligationCauseCode::BlockTailExpression(hir_id, ..) = cause.code() { - let parent_id = tcx.hir().get_parent_item(*hir_id); + let parent_id = tcx.hir_get_parent_item(*hir_id); if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(parent_id.into()) { let mut span: MultiSpan = fn_decl.output.span().into(); let mut spans = Vec::new(); @@ -472,7 +472,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { ) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> { match tcx.hir_get_if_local(def_id)? { Node::ImplItem(impl_item) => { - let impl_did = tcx.hir().get_parent_item(impl_item.hir_id()); + let impl_did = tcx.hir_get_parent_item(impl_item.hir_id()); if let hir::OwnerNode::Item(Item { kind: ItemKind::Impl(hir::Impl { self_ty, .. }), .. @@ -484,7 +484,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { } } Node::TraitItem(trait_item) => { - let trait_id = tcx.hir().get_parent_item(trait_item.hir_id()); + let trait_id = tcx.hir_get_parent_item(trait_item.hir_id()); debug_assert_eq!(tcx.def_kind(trait_id.def_id), hir::def::DefKind::Trait); // The method being called is defined in the `trait`, but the `'static` // obligation comes from the `impl`. Find that `impl` so that we can point diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index 37032b5390187..36726cc6cae0d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -586,7 +586,7 @@ impl Trait for X { hir::Node::TraitItem(item) => item.hir_id(), _ => return false, }; - let parent = tcx.hir().get_parent_item(hir_id).def_id; + let parent = tcx.hir_get_parent_item(hir_id).def_id; self.suggest_constraint(diag, msg, parent.into(), proj_ty, ty) } @@ -820,7 +820,7 @@ fn foo(&self) -> Self::T { String::new() } // When `body_owner` is an `impl` or `trait` item, look in its associated types for // `expected` and point at it. let hir_id = tcx.local_def_id_to_hir_id(def_id); - let parent_id = tcx.hir().get_parent_item(hir_id); + let parent_id = tcx.hir_get_parent_item(hir_id); let item = tcx.hir_node_by_def_id(parent_id.def_id); debug!("expected_projection parent item {:?}", item); diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index 22d219cd64d27..4d87a93be0ca0 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -587,7 +587,7 @@ fn attempt_dyn_to_impl_suggestion(tcx: TyCtxt<'_>, hir_id: Option, e // `type Alias = Box;` to // `type Alias = Box;` let Some((_id, first_non_type_parent_node)) = - tcx.hir().parent_iter(hir_id).find(|(_id, node)| !matches!(node, hir::Node::Ty(_))) + tcx.hir_parent_iter(hir_id).find(|(_id, node)| !matches!(node, hir::Node::Ty(_))) else { return; }; diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index ee0ab0dfbb82a..6eeb47a21f8dd 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -1552,7 +1552,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, ) { - let hir = self.tcx.hir(); if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives() && let hir::Node::Expr(expr) = self.tcx.hir_node(*hir_id) { @@ -1562,7 +1561,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // it is from the local crate. // use nth(1) to skip one layer of desugaring from `IntoIter::into_iter` - if let Some((_, hir::Node::Expr(await_expr))) = hir.parent_iter(*hir_id).nth(1) + if let Some((_, hir::Node::Expr(await_expr))) = self.tcx.hir_parent_iter(*hir_id).nth(1) && let Some(expr_span) = expr.span.find_ancestor_inside_same_ctxt(await_expr.span) { let removal_span = self @@ -4118,8 +4117,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let ty::Param(..) = ty.kind() else { continue; }; - let hir = tcx.hir(); - let node = tcx.hir_node_by_def_id(hir.get_parent_item(expr.hir_id).def_id); + let node = + tcx.hir_node_by_def_id(tcx.hir_get_parent_item(expr.hir_id).def_id); let pred = ty::Binder::dummy(ty::TraitPredicate { trait_ref: ty::TraitRef::new( diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index ac4399750f598..e8d30d3ee7996 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1880,8 +1880,7 @@ pub fn impl_trait_overcapture_suggestion<'tcx>( let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id); // FIXME: This is a bit too conservative, since it ignores parens already written in AST. let (lparen, rparen) = match tcx - .hir() - .parent_iter(opaque_hir_id) + .hir_parent_iter(opaque_hir_id) .nth(1) .expect("expected ty to have a parent always") .1 diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index f71b924b177a5..c8034f4e7b9f6 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -95,7 +95,7 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> DefIdMap fn associated_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AssocItem { let id = tcx.local_def_id_to_hir_id(def_id); - let parent_def_id = tcx.hir().get_parent_item(id); + let parent_def_id = tcx.hir_get_parent_item(id); let parent_item = tcx.hir().expect_item(parent_def_id.def_id); match parent_item.kind { hir::ItemKind::Impl(impl_) => { diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 7ce72c76e5c03..98881905bcf88 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -98,10 +98,10 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { let opaque_hir_id = self.tcx.local_def_id_to_hir_id(opaque_def_id); // Named opaque types can be defined by any siblings or children of siblings. - let scope = self.tcx.hir().get_defining_scope(opaque_hir_id); + let scope = self.tcx.hir_get_defining_scope(opaque_hir_id); // We walk up the node tree until we hit the root or the scope of the opaque type. while hir_id != scope && hir_id != CRATE_HIR_ID { - hir_id = self.tcx.hir().get_parent_item(hir_id).into(); + hir_id = self.tcx.hir_get_parent_item(hir_id).into(); } // Syntactically, we are allowed to define the concrete type if: hir_id == scope diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index b7c6db6c78dde..e49d978a36787 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -23,6 +23,8 @@ optimize_for_size = [] # Make `RefCell` store additional debugging information, which is printed out when # a borrow error occurs debug_refcell = [] +# Make `TypeId` store a reference to the name of the type, so that it can print that name. +debug_typeid = [] [lints.rust.unexpected_cfgs] level = "warn" diff --git a/library/core/src/any.rs b/library/core/src/any.rs index f90de1f5ced40..9ed2c8e9f3ad1 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -711,6 +711,8 @@ pub struct TypeId { // We avoid using `u128` because that imposes higher alignment requirements on many platforms. // See issue #115620 for more information. t: (u64, u64), + #[cfg(feature = "debug_typeid")] + name: &'static str, } #[stable(feature = "rust1", since = "1.0.0")] @@ -741,10 +743,14 @@ impl TypeId { #[rustc_const_unstable(feature = "const_type_id", issue = "77125")] pub const fn of() -> TypeId { let t: u128 = intrinsics::type_id::(); - let t1 = (t >> 64) as u64; let t2 = t as u64; - TypeId { t: (t1, t2) } + + TypeId { + t: (t1, t2), + #[cfg(feature = "debug_typeid")] + name: type_name::(), + } } fn as_u128(self) -> u128 { @@ -775,7 +781,15 @@ impl hash::Hash for TypeId { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for TypeId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "TypeId({:#034x})", self.as_u128()) + #[cfg(feature = "debug_typeid")] + { + write!(f, "TypeId({:#034x} = {})", self.as_u128(), self.name)?; + } + #[cfg(not(feature = "debug_typeid"))] + { + write!(f, "TypeId({:#034x})", self.as_u128())?; + } + Ok(()) } } diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index b11ba05685352..8e4417ec461b8 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -451,6 +451,28 @@ impl IpAddr { IpAddr::V6(v6) => v6.to_canonical(), } } + + /// Returns the eight-bit integers this address consists of as a slice. + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_as_octets)] + /// + /// use std::net::{Ipv4Addr, Ipv6Addr, IpAddr}; + /// + /// assert_eq!(IpAddr::V4(Ipv4Addr::LOCALHOST).as_octets(), &[127, 0, 0, 1]); + /// assert_eq!(IpAddr::V6(Ipv6Addr::LOCALHOST).as_octets(), + /// &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) + /// ``` + #[unstable(feature = "ip_as_octets", issue = "137259")] + #[inline] + pub const fn as_octets(&self) -> &[u8] { + match self { + IpAddr::V4(ip) => ip.as_octets().as_slice(), + IpAddr::V6(ip) => ip.as_octets().as_slice(), + } + } } impl Ipv4Addr { @@ -616,6 +638,25 @@ impl Ipv4Addr { Ipv4Addr { octets } } + /// Returns the four eight-bit integers that make up this address + /// as a slice. + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_as_octets)] + /// + /// use std::net::Ipv4Addr; + /// + /// let addr = Ipv4Addr::new(127, 0, 0, 1); + /// assert_eq!(addr.as_octets(), &[127, 0, 0, 1]); + /// ``` + #[unstable(feature = "ip_as_octets", issue = "137259")] + #[inline] + pub const fn as_octets(&self) -> &[u8; 4] { + &self.octets + } + /// Returns [`true`] for the special 'unspecified' address (`0.0.0.0`). /// /// This property is defined in _UNIX Network Programming, Second Edition_, @@ -2001,6 +2042,25 @@ impl Ipv6Addr { pub const fn from_octets(octets: [u8; 16]) -> Ipv6Addr { Ipv6Addr { octets } } + + /// Returns the sixteen eight-bit integers the IPv6 address consists of + /// as a slice. + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_as_octets)] + /// + /// use std::net::Ipv6Addr; + /// + /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).as_octets(), + /// &[255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + /// ``` + #[unstable(feature = "ip_as_octets", issue = "137259")] + #[inline] + pub const fn as_octets(&self) -> &[u8; 16] { + &self.octets + } } /// Writes an Ipv6Addr, conforming to the canonical style described by diff --git a/library/coretests/tests/any.rs b/library/coretests/tests/any.rs index 25002617d0bbd..117ef0042380d 100644 --- a/library/coretests/tests/any.rs +++ b/library/coretests/tests/any.rs @@ -118,6 +118,14 @@ fn any_unsized() { is_any::<[i32]>(); } +#[cfg(feature = "debug_typeid")] +#[test] +fn debug_typeid_includes_name() { + let type_id = TypeId::of::<[usize; 2]>(); + let debug_str = format!("{type_id:?}"); + assert!(debug_str.ends_with("= [usize; 2])"), "{debug_str:?} did not match"); +} + #[test] fn distinct_type_names() { // https://github.com/rust-lang/rust/issues/84666 diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 36a0a59d939f3..228ee6eea05fa 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -110,6 +110,13 @@ panic_immediate_abort = [ # Choose algorithms that are optimized for binary size instead of runtime performance optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"] +# Make `RefCell` store additional debugging information, which is printed out when +# a borrow error occurs +debug_refcell = ["core/debug_refcell"] +# Make `TypeId` store a reference to the name of the type, so that it can print that name. +debug_typeid = ["core/debug_typeid"] + + # Enable std_detect default features for stdarch/crates/std_detect: # https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml std_detect_file_io = ["std_detect/std_detect_file_io"] diff --git a/library/std/src/ffi/mod.rs b/library/std/src/ffi/mod.rs index 7d7cce09a3f09..860ec3a6be16e 100644 --- a/library/std/src/ffi/mod.rs +++ b/library/std/src/ffi/mod.rs @@ -201,5 +201,5 @@ pub use self::c_str::{CStr, CString}; #[doc(inline)] pub use self::os_str::{OsStr, OsString}; -#[unstable(feature = "os_str_display", issue = "120048")] +#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")] pub mod os_str; diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index c4c8dbccd7a44..f4a02802336d5 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1204,13 +1204,12 @@ impl OsStr { /// # Examples /// /// ``` - /// #![feature(os_str_display)] /// use std::ffi::OsStr; /// /// let s = OsStr::new("Hello, world!"); /// println!("{}", s.display()); /// ``` - #[unstable(feature = "os_str_display", issue = "120048")] + #[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")] #[must_use = "this does not display the `OsStr`; \ it returns an object that can be displayed"] #[inline] @@ -1559,7 +1558,6 @@ impl fmt::Debug for OsStr { /// # Examples /// /// ``` -/// #![feature(os_str_display)] /// use std::ffi::OsStr; /// /// let s = OsStr::new("Hello, world!"); @@ -1568,19 +1566,19 @@ impl fmt::Debug for OsStr { /// /// [`Display`]: fmt::Display /// [`format!`]: crate::format -#[unstable(feature = "os_str_display", issue = "120048")] +#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")] pub struct Display<'a> { os_str: &'a OsStr, } -#[unstable(feature = "os_str_display", issue = "120048")] +#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")] impl fmt::Debug for Display<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.os_str, f) } } -#[unstable(feature = "os_str_display", issue = "120048")] +#[stable(feature = "os_str_display", since = "CURRENT_RUSTC_VERSION")] impl fmt::Display for Display<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.os_str.inner, f) diff --git a/library/std/src/sys/pal/wasi/stdio.rs b/library/std/src/sys/pal/wasi/stdio.rs index d08b772e5fc7d..fb21cb4d393d0 100644 --- a/library/std/src/sys/pal/wasi/stdio.rs +++ b/library/std/src/sys/pal/wasi/stdio.rs @@ -1,7 +1,7 @@ #![forbid(unsafe_op_in_unsafe_fn)] use super::fd::WasiFd; -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::mem::ManuallyDrop; use crate::os::raw; use crate::os::wasi::io::{AsRawFd, FromRawFd}; @@ -28,6 +28,10 @@ impl io::Read for Stdin { self.read_vectored(&mut [IoSliceMut::new(data)]) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read_buf(buf) + } + fn read_vectored(&mut self, data: &mut [IoSliceMut<'_>]) -> io::Result { ManuallyDrop::new(unsafe { WasiFd::from_raw_fd(self.as_raw_fd()) }).read(data) } @@ -64,6 +68,7 @@ impl io::Write for Stdout { fn is_write_vectored(&self) -> bool { true } + fn flush(&mut self) -> io::Result<()> { Ok(()) } diff --git a/library/sysroot/Cargo.toml b/library/sysroot/Cargo.toml index aa6c3dc32e2ba..6ed2756e526d6 100644 --- a/library/sysroot/Cargo.toml +++ b/library/sysroot/Cargo.toml @@ -19,11 +19,13 @@ compiler-builtins-mem = ["std/compiler-builtins-mem"] compiler-builtins-no-asm = ["std/compiler-builtins-no-asm"] compiler-builtins-no-f16-f128 = ["std/compiler-builtins-no-f16-f128"] compiler-builtins-mangled-names = ["std/compiler-builtins-mangled-names"] +debug_refcell = ["std/debug_refcell"] +debug_typeid = ["std/debug_typeid"] llvm-libunwind = ["std/llvm-libunwind"] system-llvm-libunwind = ["std/system-llvm-libunwind"] +optimize_for_size = ["std/optimize_for_size"] panic-unwind = ["std/panic_unwind"] panic_immediate_abort = ["std/panic_immediate_abort"] -optimize_for_size = ["std/optimize_for_size"] profiler = ["dep:profiler_builtins"] std_detect_file_io = ["std/std_detect_file_io"] std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"] diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 1af5e2b0e1d4f..872592d669d6d 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -100,7 +100,8 @@ mod private { // this item is private and will not be documented } ``` -`--document-private-items` documents all items, even if they're not public. +`--document-private-items` includes all non-public items in the generated documentation except for `#[doc(hidden)]` items. Private items will be shown with a 🔒 icon. + ## `-L`/`--library-path`: where to look for dependencies diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 3abd538d372c4..d4ff69a99338b 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -262,6 +262,25 @@ themselves marked as unstable. To use any of these options, pass `-Z unstable-op the flag in question to Rustdoc on the command-line. To do this from Cargo, you can either use the `RUSTDOCFLAGS` environment variable or the `cargo rustdoc` command. +### `--document-hidden-items`: Show items that are `#[doc(hidden)]` + + +By default, `rustdoc` does not document items that are annotated with +[`#[doc(hidden)]`](write-documentation/the-doc-attribute.html#hidden). + +`--document-hidden-items` causes all items to be documented as if they did not have `#[doc(hidden)]`, except that hidden items will be shown with a 👻 icon. + +Here is a table that fully describes which items are documented with each combination of `--document-hidden-items` and `--document-private-items`: + + +| rustdoc flags | items that will be documented | +|---------------------------------|---------------------------------------| +| neither flag | only public items that are not hidden | +| only `--document-hidden-items` | all public items | +| only `--document-private-items` | all items that are not hidden | +| both flags | all items | + + ### `--markdown-before-content`: include rendered Markdown before the content * Tracking issue: [#44027](https://github.com/rust-lang/rust/issues/44027) diff --git a/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md b/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md index ff033aa14b821..45146993371f9 100644 --- a/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md +++ b/src/doc/rustdoc/src/write-documentation/the-doc-attribute.md @@ -230,9 +230,8 @@ If you want to know more about inlining rules, take a look at the -Any item annotated with `#[doc(hidden)]` will not appear in the documentation, unless -the `strip-hidden` pass is removed. Re-exported items where one of its ancestors has -`#[doc(hidden)]` will be considered the same as private. +Any item annotated with `#[doc(hidden)]` will not appear in the documentation, +unless the [`--document-hidden-items`](../unstable-features.md#document-hidden-items) flag is used. You can find more information in the [`re-exports` chapter](./re-exports.md). diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e4acbcf2c626f..1f2f8f7d33a4a 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -13,7 +13,6 @@ #![feature(iter_intersperse)] #![feature(let_chains)] #![feature(never_type)] -#![feature(os_str_display)] #![feature(round_char_boundary)] #![feature(test)] #![feature(type_alias_impl_trait)] diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 9fe8b99e8af87..97e6d3146427c 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1983,7 +1983,7 @@ fn resolution_failure( .tcx .resolutions(()) .all_macro_rules - .contains_key(&Symbol::intern(path_str)) + .contains(&Symbol::intern(path_str)) { diag.note(format!( "`macro_rules` named `{path_str}` exists in this crate, \ diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index a36dcb0d30e5c..44551d75903da 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -177,7 +177,7 @@ where // If the enclosing item has a span coming from a proc macro, then we also don't want to // include the example. let enclosing_item_span = - tcx.hir().span_with_body(tcx.hir().get_parent_item(ex.hir_id).into()); + tcx.hir().span_with_body(tcx.hir_get_parent_item(ex.hir_id).into()); if enclosing_item_span.from_expansion() { trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}"); return; diff --git a/src/tools/clippy/clippy_lints/src/assigning_clones.rs b/src/tools/clippy/clippy_lints/src/assigning_clones.rs index c01155ca86e01..348495f97a27b 100644 --- a/src/tools/clippy/clippy_lints/src/assigning_clones.rs +++ b/src/tools/clippy/clippy_lints/src/assigning_clones.rs @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones { && !cx.tcx.is_builtin_derived(resolved_impl) // Don't suggest calling a function we're implementing. && resolved_impl.as_local().is_none_or(|block_id| { - cx.tcx.hir().parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id) + cx.tcx.hir_parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id) }) && let resolved_assoc_items = cx.tcx.associated_items(resolved_impl) // Only suggest if `clone_from`/`clone_into` is explicitly implemented diff --git a/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs b/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs index d1ffbb6ffe251..e8638595c4b26 100644 --- a/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs +++ b/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs @@ -24,8 +24,7 @@ pub fn check( if !check_private_items && cx .tcx - .hir() - .parent_iter(owner_id.into()) + .hir_parent_iter(owner_id.into()) .any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id))) { return; diff --git a/src/tools/clippy/clippy_lints/src/doc/mod.rs b/src/tools/clippy/clippy_lints/src/doc/mod.rs index 93c2b7a2d1823..713d62a8801d8 100644 --- a/src/tools/clippy/clippy_lints/src/doc/mod.rs +++ b/src/tools/clippy/clippy_lints/src/doc/mod.rs @@ -1057,7 +1057,7 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> { "assert" | "assert_eq" | "assert_ne" ) { - self.is_const = self.cx.tcx.hir().is_inside_const_context(expr.hir_id); + self.is_const = self.cx.tcx.hir_is_inside_const_context(expr.hir_id); self.panic_span = Some(macro_call.span); } } diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs index c55d4387d6961..0c06c9117d737 100644 --- a/src/tools/clippy/clippy_lints/src/escape.rs +++ b/src/tools/clippy/clippy_lints/src/escape.rs @@ -80,8 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { let parent_id = cx .tcx - .hir() - .get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id)) + .hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id)) .def_id; let mut trait_self_ty = None; diff --git a/src/tools/clippy/clippy_lints/src/exit.rs b/src/tools/clippy/clippy_lints/src/exit.rs index e6ddcd107d9d3..cc8e4d7d9e281 100644 --- a/src/tools/clippy/clippy_lints/src/exit.rs +++ b/src/tools/clippy/clippy_lints/src/exit.rs @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { && let ExprKind::Path(ref path) = path_expr.kind && let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id() && cx.tcx.is_diagnostic_item(sym::process_exit, def_id) - && let parent = cx.tcx.hir().get_parent_item(e.hir_id) + && let parent = cx.tcx.hir_get_parent_item(e.hir_id) && let OwnerNode::Item(Item{kind: ItemKind::Fn{ .. }, ..}) = cx.tcx.hir_owner_node(parent) // If the next item up is a function we check if it is an entry point // and only then emit a linter warning diff --git a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs index f666ed0a440bf..33431385c7de3 100644 --- a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs +++ b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs @@ -112,7 +112,7 @@ impl IndexingSlicing { impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let ExprKind::Index(array, index, _) = &expr.kind - && (!self.suppress_restriction_lint_in_const || !cx.tcx.hir().is_inside_const_context(expr.hir_id)) + && (!self.suppress_restriction_lint_in_const || !cx.tcx.hir_is_inside_const_context(expr.hir_id)) && let expr_ty = cx.typeck_results().expr_ty(array) && let mut deref = deref_chain(cx, expr_ty) && deref.any(|l| { @@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { span_lint_and_then(cx, INDEXING_SLICING, expr.span, "slicing may panic", |diag| { diag.help(help_msg); - if cx.tcx.hir().is_inside_const_context(expr.hir_id) { + if cx.tcx.hir_is_inside_const_context(expr.hir_id) { diag.note(note); } }); @@ -223,7 +223,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { span_lint_and_then(cx, INDEXING_SLICING, expr.span, "indexing may panic", |diag| { diag.help("consider using `.get(n)` or `.get_mut(n)` instead"); - if cx.tcx.hir().is_inside_const_context(expr.hir_id) { + if cx.tcx.hir_is_inside_const_context(expr.hir_id) { diag.note(note); } }); diff --git a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs index c68499ce9f781..620e27fa67c62 100644 --- a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind() && let Some(element_count) = cst.try_to_target_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) - && !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| { + && !cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| { matches!( node, Node::Item(Item { diff --git a/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs b/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs index 4d206850c9984..797ff1f398668 100644 --- a/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs @@ -61,7 +61,7 @@ pub(super) fn check<'tcx>( } fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option> { - for (_, parent_node) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, parent_node) in cx.tcx.hir_parent_iter(expr.hir_id) { match parent_node { // Skip `Coroutine` closures, these are the body of `async fn`, not async closures. // This is because we still need to backtrack one parent node to get the `OpaqueDef` ty. diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_find.rs b/src/tools/clippy/clippy_lints/src/loops/manual_find.rs index 1721f569541b4..aa8a2934f89bd 100644 --- a/src/tools/clippy/clippy_lints/src/loops/manual_find.rs +++ b/src/tools/clippy/clippy_lints/src/loops/manual_find.rs @@ -134,7 +134,7 @@ fn last_stmt_and_ret<'tcx>( } None } - let mut parent_iter = cx.tcx.hir().parent_iter(expr.hir_id); + let mut parent_iter = cx.tcx.hir_parent_iter(expr.hir_id); if let Some((node_hir, Node::Stmt(..))) = parent_iter.next() // This should be the loop // This should be the function body diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs index e98c3c9698ba0..0f62183eb33d6 100644 --- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs @@ -56,7 +56,7 @@ pub(super) fn check<'tcx>( // ensure that the indexed variable was declared before the loop, see #601 if let Some(indexed_extent) = indexed_extent { - let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id); + let parent_def_id = cx.tcx.hir_get_parent_item(expr.hir_id); let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap(); if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { @@ -256,7 +256,7 @@ impl<'tcx> VarVisitor<'_, 'tcx> { let res = self.cx.qpath_res(seqpath, seqexpr.hir_id); match res { Res::Local(hir_id) => { - let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id); + let parent_def_id = self.cx.tcx.hir_get_parent_item(expr.hir_id); let extent = self .cx .tcx diff --git a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs index 393399660131f..722ea7042dd7f 100644 --- a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs @@ -199,7 +199,7 @@ fn find_method_sugg_for_if_let<'tcx>( // type needs to be considered, not just the inner type of the branch being matched on. // Note the last expression in a block is dropped after all local bindings. let check_ty = if has_else - || (keyword == "if" && matches!(cx.tcx.hir().parent_iter(expr.hir_id).next(), Some((_, Node::Block(..))))) + || (keyword == "if" && matches!(cx.tcx.hir_parent_iter(expr.hir_id).next(), Some((_, Node::Block(..))))) { op_ty } else { diff --git a/src/tools/clippy/clippy_lints/src/methods/is_empty.rs b/src/tools/clippy/clippy_lints/src/methods/is_empty.rs index 92c81b3c49d87..1c64f78678aeb 100644 --- a/src/tools/clippy/clippy_lints/src/methods/is_empty.rs +++ b/src/tools/clippy/clippy_lints/src/methods/is_empty.rs @@ -40,8 +40,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_ fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool { cx.tcx - .hir() - .parent_id_iter(id) + .hir_parent_id_iter(id) .any(|id| cx.tcx.hir().attrs(id).iter().any(|attr| attr.has_name(sym::cfg))) } diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs b/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs index 9ff6eaa348710..4bdf589f48762 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs @@ -11,7 +11,7 @@ use rustc_span::sym; use super::ITER_NTH_ZERO; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) { - if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) + if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id)) && let def_id = item.owner_id.to_def_id() && is_trait_method(cx, expr, sym::Iterator) && let Some(Constant::Int(0)) = ConstEvalCtxt::new(cx).eval(arg) diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_c_str_literals.rs b/src/tools/clippy/clippy_lints/src/methods/manual_c_str_literals.rs index 7d5ebdedd0c30..e1ebca0b09dfb 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_c_str_literals.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_c_str_literals.rs @@ -187,7 +187,7 @@ fn peel_ptr_cast<'tcx>(e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { /// ^ given this `x` expression, returns the `foo(...)` expression fn peel_ptr_cast_ancestors<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { let mut prev = e; - for (_, node) in cx.tcx.hir().parent_iter(e.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(e.hir_id) { if let Node::Expr(e) = node && get_cast_target(e).is_some() { diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs b/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs index de37df2394d30..09ccb386a20bc 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs @@ -123,7 +123,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: }; let mut prev_expr = e; - for (_, parent) in cx.tcx.hir().parent_iter(e.hir_id) { + for (_, parent) in cx.tcx.hir_parent_iter(e.hir_id) { if let Node::Expr(e) = parent { match e.kind { ExprKind::Field(_, name) diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index ccc5cd4fa417f..b58e8ba32e78b 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -4671,7 +4671,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); diff --git a/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs b/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs index f5f404070caba..69f933fee68f2 100644 --- a/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs +++ b/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs @@ -92,7 +92,7 @@ pub(super) fn check<'tcx>( let in_sugg_method_implementation = { matches!( suggested_method_def_id.as_local(), - Some(local_def_id) if local_def_id == cx.tcx.hir().get_parent_item(receiver.hir_id).def_id + Some(local_def_id) if local_def_id == cx.tcx.hir_get_parent_item(receiver.hir_id).def_id ) }; if in_sugg_method_implementation { diff --git a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs index 8a99974394c32..8389c2e3f9826 100644 --- a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs +++ b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs @@ -35,7 +35,7 @@ pub(super) fn check( }; let manual = count == 2 && msrv.meets(msrvs::STR_SPLIT_ONCE); - match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir().parent_iter(expr.hir_id)) { + match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir_parent_iter(expr.hir_id)) { Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg), Some(usage) if manual => check_manual_split_once(cx, method_name, expr, self_arg, pat_arg, &usage), None if manual => { @@ -127,7 +127,7 @@ fn check_manual_split_once_indirect( pat_arg: &Expr<'_>, ) -> Option<()> { let ctxt = expr.span.ctxt(); - let mut parents = cx.tcx.hir().parent_iter(expr.hir_id); + let mut parents = cx.tcx.hir_parent_iter(expr.hir_id); if let (_, Node::LetStmt(local)) = parents.next()? && let PatKind::Binding(BindingMode::MUT, iter_binding_id, _, None) = local.pat.kind && let (iter_stmt_id, Node::Stmt(_)) = parents.next()? @@ -220,7 +220,7 @@ fn indirect_usage<'tcx>( ControlFlow::Continue(Descend::from(path_to_binding.is_none())) }); - let mut parents = cx.tcx.hir().parent_iter(path_to_binding?.hir_id); + let mut parents = cx.tcx.hir_parent_iter(path_to_binding?.hir_id); let iter_usage = parse_iter_usage(cx, ctxt, &mut parents)?; let (parent_id, _) = parents.find(|(_, node)| { diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs index e80d99dca56d1..ea134c0570537 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -494,7 +494,7 @@ fn get_input_traits_and_projections<'tcx>( #[expect(clippy::too_many_lines)] fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<'a>) -> bool { - for (_, node) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(expr.hir_id) { match node { Node::Stmt(_) => return true, Node::Block(..) => {}, diff --git a/src/tools/clippy/clippy_lints/src/min_ident_chars.rs b/src/tools/clippy/clippy_lints/src/min_ident_chars.rs index 4119b1d1051cb..e5801124db48e 100644 --- a/src/tools/clippy/clippy_lints/src/min_ident_chars.rs +++ b/src/tools/clippy/clippy_lints/src/min_ident_chars.rs @@ -121,9 +121,9 @@ impl Visitor<'_> for IdentVisitor<'_, '_> { // Check whether the node is part of a `use` statement. We don't want to emit a warning if the user // has no control over the type. let usenode = opt_as_use_node(node).or_else(|| { - cx.tcx - .hir() - .parent_iter(hir_id) + cx + .tcx + .hir_parent_iter(hir_id) .find_map(|(_, node)| opt_as_use_node(node)) }); diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs index ba4af134ccd0b..8d751c2c0acb8 100644 --- a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs +++ b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { // Const fns are not allowed as methods in a trait. { - let parent = cx.tcx.hir().get_parent_item(hir_id).def_id; + let parent = cx.tcx.hir_get_parent_item(hir_id).def_id; if parent != CRATE_DEF_ID { if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) { if let hir::ItemKind::Trait(..) = &item.kind { diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs index e2ca4458edaa0..d4181c677afda 100644 --- a/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs +++ b/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs @@ -81,7 +81,7 @@ fn is_unreachable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { | sym::core_panic_2015_macro | sym::std_panic_2015_macro | sym::core_panic_2021_macro - ) && !cx.tcx.hir().is_inside_const_context(expr.hir_id)) + ) && !cx.tcx.hir_is_inside_const_context(expr.hir_id)) || matches!( diag_name, sym::unimplemented_macro | sym::todo_macro | sym::unreachable_macro | sym::unreachable_2015_macro diff --git a/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs b/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs index 098098718af39..1b6896827fed8 100644 --- a/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs +++ b/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs @@ -41,8 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef { && !ref_pat.span.from_expansion() && cx .tcx - .hir() - .parent_iter(ref_pat.hir_id) + .hir_parent_iter(ref_pat.hir_id) .map_while(|(_, parent)| if let Node::Pat(pat) = parent { Some(pat) } else { None }) // Do not lint patterns that are part of an OR `|` pattern, the binding mode must match in all arms .all(|pat| !matches!(pat.kind, PatKind::Or(_))) diff --git a/src/tools/clippy/clippy_lints/src/needless_late_init.rs b/src/tools/clippy/clippy_lints/src/needless_late_init.rs index 4e19a2f409dd3..863a1f895c937 100644 --- a/src/tools/clippy/clippy_lints/src/needless_late_init.rs +++ b/src/tools/clippy/clippy_lints/src/needless_late_init.rs @@ -347,7 +347,7 @@ fn check<'tcx>( impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) { - let mut parents = cx.tcx.hir().parent_iter(local.hir_id); + let mut parents = cx.tcx.hir_parent_iter(local.hir_id); if let LetStmt { init: None, pat: diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs index 5e85d23718a9c..36a0738cbc95a 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs @@ -350,8 +350,7 @@ impl MutablyUsedVariablesCtxt<'_> { // The goal here is to find if the current scope is unsafe or not. It stops when it finds // a function or an unsafe block. fn is_in_unsafe_block(&self, item: HirId) -> bool { - let hir = self.tcx.hir(); - for (parent, node) in hir.parent_iter(item) { + for (parent, node) in self.tcx.hir_parent_iter(item) { if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) { return fn_sig.header.is_unsafe(); } else if let Node::Block(block) = node { diff --git a/src/tools/clippy/clippy_lints/src/new_without_default.rs b/src/tools/clippy/clippy_lints/src/new_without_default.rs index cf407e51f7afb..f0ee613791fb9 100644 --- a/src/tools/clippy/clippy_lints/src/new_without_default.rs +++ b/src/tools/clippy/clippy_lints/src/new_without_default.rs @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { if sig.decl.inputs.is_empty() && name == sym::new && cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id) - && let self_def_id = cx.tcx.hir().get_parent_item(id.into()) + && let self_def_id = cx.tcx.hir_get_parent_item(id.into()) && let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity() && self_ty == return_ty(cx, id) && let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default) diff --git a/src/tools/clippy/clippy_lints/src/no_effect.rs b/src/tools/clippy/clippy_lints/src/no_effect.rs index 4d3e6aa79d0a0..7187a8f2c11a1 100644 --- a/src/tools/clippy/clippy_lints/src/no_effect.rs +++ b/src/tools/clippy/clippy_lints/src/no_effect.rs @@ -141,7 +141,7 @@ impl NoEffect { stmt.span, "statement with no effect", |diag| { - for parent in cx.tcx.hir().parent_iter(stmt.hir_id) { + for parent in cx.tcx.hir_parent_iter(stmt.hir_id) { if let Node::Item(item) = parent.1 && let ItemKind::Fn { .. } = item.kind && let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id) diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index f965ab90da239..4007ca88a00e7 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -344,7 +344,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(_, body_id) = &impl_item.kind { - let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let item_def_id = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(item_def_id); match &item.kind { diff --git a/src/tools/clippy/clippy_lints/src/non_zero_suggestions.rs b/src/tools/clippy/clippy_lints/src/non_zero_suggestions.rs index f6ce1d1d58672..16c4391c0fbea 100644 --- a/src/tools/clippy/clippy_lints/src/non_zero_suggestions.rs +++ b/src/tools/clippy/clippy_lints/src/non_zero_suggestions.rs @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for NonZeroSuggestions { check_non_zero_conversion(cx, rhs, Applicability::MachineApplicable); } else { // Check if the parent expression is a binary operation - let parent_is_binary = cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| { + let parent_is_binary = cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| { matches!(node, rustc_hir::Node::Expr(parent_expr) if matches!(parent_expr.kind, ExprKind::Binary(..))) }); diff --git a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs index 1315c3dfc127c..5737a91031db2 100644 --- a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs +++ b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>( let rty = cx.typeck_results().expr_ty(rhs); if let Some((_, lang_item)) = binop_traits(op.node) && let Some(trait_id) = cx.tcx.lang_items().get(lang_item) - && let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id + && let parent_fn = cx.tcx.hir_get_parent_item(e.hir_id).def_id && trait_ref_of_method(cx, parent_fn).is_none_or(|t| t.path.res.def_id() != trait_id) && implements_trait(cx, ty, trait_id, &[rty.into()]) { diff --git a/src/tools/clippy/clippy_lints/src/operators/identity_op.rs b/src/tools/clippy/clippy_lints/src/operators/identity_op.rs index 1c2d6e90fc95e..0358232282786 100644 --- a/src/tools/clippy/clippy_lints/src/operators/identity_op.rs +++ b/src/tools/clippy/clippy_lints/src/operators/identity_op.rs @@ -120,7 +120,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>) // the parent HIR node is an expression, or if the parent HIR node // is a Block or Stmt, and the new left hand side would need // parenthesis be treated as a statement rather than an expression. - if let Some((_, parent)) = cx.tcx.hir().parent_iter(binary.hir_id).next() { + if let Some((_, parent)) = cx.tcx.hir_parent_iter(binary.hir_id).next() { match parent { Node::Expr(_) => return Parens::Needed, Node::Block(_) | Node::Stmt(_) => { @@ -142,7 +142,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>) // This would mean that the rustfix suggestion will appear at the start of a line, which causes // these expressions to be interpreted as statements if they do not have parenthesis. let mut prev_id = binary.hir_id; - for (_, parent) in cx.tcx.hir().parent_iter(binary.hir_id) { + for (_, parent) in cx.tcx.hir_parent_iter(binary.hir_id) { if let Node::Expr(expr) = parent && let ExprKind::Binary(_, lhs, _) | ExprKind::Cast(lhs, _) | ExprKind::Unary(_, lhs) = expr.kind && lhs.hir_id == prev_id diff --git a/src/tools/clippy/clippy_lints/src/panic_unimplemented.rs b/src/tools/clippy/clippy_lints/src/panic_unimplemented.rs index fa5b02a5a41ba..c9bdeed660e20 100644 --- a/src/tools/clippy/clippy_lints/src/panic_unimplemented.rs +++ b/src/tools/clippy/clippy_lints/src/panic_unimplemented.rs @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { if let Some(macro_call) = root_macro_call_first_node(cx, expr) { if is_panic(cx, macro_call.def_id) { - if cx.tcx.hir().is_inside_const_context(expr.hir_id) + if cx.tcx.hir_is_inside_const_context(expr.hir_id) || self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id) { return; @@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented { && let Res::Def(DefKind::Fn, def_id) = expr_path.res && match_def_path(cx, def_id, &paths::PANIC_ANY) { - if cx.tcx.hir().is_inside_const_context(expr.hir_id) + if cx.tcx.hir_is_inside_const_context(expr.hir_id) || self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id) { return; diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs index 9b241edf4ccf2..ef4948a05b7f4 100644 --- a/src/tools/clippy/clippy_lints/src/ptr.rs +++ b/src/tools/clippy/clippy_lints/src/ptr.rs @@ -186,8 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { - let hir = cx.tcx.hir(); - let mut parents = hir.parent_iter(body.value.hir_id); + let mut parents = cx.tcx.hir_parent_iter(body.value.hir_id); let (item_id, sig, is_trait_item) = match parents.next() { Some((_, Node::Item(i))) => { if let ItemKind::Fn { sig, .. } = &i.kind { diff --git a/src/tools/clippy/clippy_lints/src/redundant_locals.rs b/src/tools/clippy/clippy_lints/src/redundant_locals.rs index e15e12629209d..f3ccc9e38f4d8 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_locals.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_locals.rs @@ -122,8 +122,7 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option { /// Check if a rebinding of a local changes the effect of assignments to the binding. fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId, rebind: HirId) -> bool { - let hir = cx.tcx.hir(); - // the binding is mutable and the rebinding is in a different scope than the original binding - mutability == Mutability::Mut && hir.get_enclosing_scope(bind) != hir.get_enclosing_scope(rebind) + mutability == Mutability::Mut + && cx.tcx.hir_get_enclosing_scope(bind) != cx.tcx.hir_get_enclosing_scope(rebind) } diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs index 9f0ea84246ddd..152739c2973b6 100644 --- a/src/tools/clippy/clippy_lints/src/returns.rs +++ b/src/tools/clippy/clippy_lints/src/returns.rs @@ -177,8 +177,7 @@ declare_lint_pass!(Return => [LET_AND_RETURN, NEEDLESS_RETURN, NEEDLESS_RETURN_W /// because of the never-ness of `return` expressions fn stmt_needs_never_type(cx: &LateContext<'_>, stmt_hir_id: HirId) -> bool { cx.tcx - .hir() - .parent_iter(stmt_hir_id) + .hir_parent_iter(stmt_hir_id) .find_map(|(_, node)| if let Node::Expr(expr) = node { Some(expr) } else { None }) .is_some_and(|e| { cx.typeck_results() @@ -203,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { && is_res_lang_ctor(cx, path_res(cx, maybe_constr), ResultErr) // Ensure this is not the final stmt, otherwise removing it would cause a compile error - && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) + && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id)) && let ItemKind::Fn { body, .. } = item.kind && let block = cx.tcx.hir_body(body).value && let ExprKind::Block(block, _) = block.kind diff --git a/src/tools/clippy/clippy_lints/src/self_named_constructors.rs b/src/tools/clippy/clippy_lints/src/self_named_constructors.rs index 23b47606f8aa2..fc02c3a51716e 100644 --- a/src/tools/clippy/clippy_lints/src/self_named_constructors.rs +++ b/src/tools/clippy/clippy_lints/src/self_named_constructors.rs @@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { _ => return, } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let ret_ty = return_ty(cx, impl_item.owner_id); diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs index a931e39bac9c2..ee282ee1dfb71 100644 --- a/src/tools/clippy/clippy_lints/src/shadow.rs +++ b/src/tools/clippy/clippy_lints/src/shadow.rs @@ -224,9 +224,9 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span) /// Returns true if the expression is a simple transformation of a local binding such as `&x` fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_id: HirId) -> bool { - let hir = cx.tcx.hir(); - let is_direct_binding = hir - .parent_iter(pat.hir_id) + let is_direct_binding = cx + .tcx + .hir_parent_iter(pat.hir_id) .map_while(|(_id, node)| match node { Node::Pat(pat) => Some(pat), _ => None, @@ -259,14 +259,14 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_ /// For closure arguments passed to a method call, returns the method call, and the `HirId` of the /// closure (which will later be skipped). This is for fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<(&'tcx Expr<'tcx>, Option)> { - for (hir_id, node) in cx.tcx.hir().parent_iter(hir_id) { + for (hir_id, node) in cx.tcx.hir_parent_iter(hir_id) { let init = match node { Node::Arm(_) | Node::Pat(_) | Node::PatField(_) | Node::Param(_) => continue, Node::Expr(expr) => match expr.kind { ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some((e, None)), // If we're a closure argument, then a parent call is also an associated item. ExprKind::Closure(_) => { - if let Some((_, node)) = cx.tcx.hir().parent_iter(hir_id).next() { + if let Some((_, node)) = cx.tcx.hir_parent_iter(hir_id).next() { match node { Node::Expr(expr) => match expr.kind { ExprKind::MethodCall(_, _, _, _) | ExprKind::Call(_, _) => Some((expr, Some(hir_id))), diff --git a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs index 597bfddecbc5f..e9db7c9d031a9 100644 --- a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs +++ b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs @@ -232,8 +232,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> StmtsChecker<'ap, 'lc, 'others, 'stmt, 'tcx let block_is_ancestor = self .cx .tcx - .hir() - .parent_iter(self.ap.curr_block_hir_id) + .hir_parent_iter(self.ap.curr_block_hir_id) .any(|(id, _)| id == apa.first_block_hir_id); if last_stmt_is_not_dummy && last_stmt_is_not_curr && (block_equals_curr || block_is_ancestor) { apa.has_expensive_expr_after_last_attr = true; diff --git a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs index 9326b2adaffb7..fb426e91bf01d 100644 --- a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs +++ b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs @@ -63,11 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl { // Check for more than one binary operation in the implemented function // Linting when multiple operations are involved can result in false positives - && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id + && let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id).def_id && let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn) && let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind && let body = cx.tcx.hir_body(body_id) - && let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id + && let parent_fn = cx.tcx.hir_get_parent_item(expr.hir_id).def_id && let Some(trait_ref) = trait_ref_of_method(cx, parent_fn) && let trait_id = trait_ref.path.res.def_id() && ![binop_trait_id, op_assign_trait_id].contains(&trait_id) diff --git a/src/tools/clippy/clippy_lints/src/transmute/eager_transmute.rs b/src/tools/clippy/clippy_lints/src/transmute/eager_transmute.rs index 1209bd5b34f2c..81c0a57083e80 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/eager_transmute.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/eager_transmute.rs @@ -10,7 +10,7 @@ use rustc_middle::ty::Ty; use super::EAGER_TRANSMUTE; fn peel_parent_unsafe_blocks<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> { - for (_, parent) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, parent) in cx.tcx.hir_parent_iter(expr.hir_id) { match parent { Node::Block(_) => {}, Node::Expr(e) if let ExprKind::Block(..) = e.kind => {}, diff --git a/src/tools/clippy/clippy_lints/src/transmute/missing_transmute_annotations.rs b/src/tools/clippy/clippy_lints/src/transmute/missing_transmute_annotations.rs index 0b5d83ef58ca1..96286fcf73d67 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/missing_transmute_annotations.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/missing_transmute_annotations.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::Ty; use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS; fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) -> Option> { - let mut parent_iter = cx.tcx.hir().parent_iter(expr_hir_id); + let mut parent_iter = cx.tcx.hir_parent_iter(expr_hir_id); if let Some((_, node)) = parent_iter.next() { match node { Node::LetStmt(local) => Some(*local), diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs index 579cbf447a2b0..71e6e75c1bd3a 100644 --- a/src/tools/clippy/clippy_lints/src/types/mod.rs +++ b/src/tools/clippy/clippy_lints/src/types/mod.rs @@ -375,8 +375,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { ) { let is_in_trait_impl = if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id( cx.tcx - .hir() - .get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id)) + .hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id)) .def_id, ) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) @@ -420,7 +419,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { ImplItemKind::Const(ty, _) => { let is_in_trait_impl = if let hir::Node::Item(item) = cx .tcx - .hir_node_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id) + .hir_node_by_def_id(cx.tcx.hir_get_parent_item(item.hir_id()).def_id) { matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { diff --git a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs index 76a0b927df420..a443043bef902 100644 --- a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs @@ -111,7 +111,7 @@ fn get_impl_trait_def_id(cx: &LateContext<'_>, method_def_id: LocalDefId) -> Opt owner_id, .. }), - )) = cx.tcx.hir().parent_iter(hir_id).next() + )) = cx.tcx.hir_parent_iter(hir_id).next() // We exclude `impl` blocks generated from rustc's proc macros. && !cx.tcx.has_attr(*owner_id, sym::automatically_derived) // It is a implementation of a trait. @@ -216,7 +216,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local owner_id, .. }), - )) = cx.tcx.hir().parent_iter(hir_id).next() + )) = cx.tcx.hir_parent_iter(hir_id).next() // We exclude `impl` blocks generated from rustc's proc macros. && !cx.tcx.has_attr(*owner_id, sym::automatically_derived) // It is a implementation of a trait. @@ -367,7 +367,7 @@ impl UnconditionalRecursion { kind: ItemKind::Impl(impl_), .. }), - )) = cx.tcx.hir().parent_iter(hir_id).next() + )) = cx.tcx.hir_parent_iter(hir_id).next() && let Some(implemented_ty_id) = get_hir_ty_def_id(cx.tcx, *impl_.self_ty) && { self.init_default_impl_for_type_if_needed(cx); diff --git a/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs b/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs index c8e3c46f2f6f1..93abf95e35773 100644 --- a/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -291,7 +291,7 @@ fn expr_has_unnecessary_safety_comment<'tcx>( expr: &'tcx hir::Expr<'tcx>, comment_pos: BytePos, ) -> Option { - if cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, ref node)| { + if cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, ref node)| { matches!( node, Node::Block(Block { @@ -604,10 +604,9 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span fn get_body_search_span(cx: &LateContext<'_>) -> Option { let body = cx.enclosing_body?; - let map = cx.tcx.hir(); let mut span = cx.tcx.hir_body(body).value.span; let mut maybe_global_var = false; - for (_, node) in map.parent_iter(body.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(body.hir_id) { match node { Node::Expr(e) => span = e.span, Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (), diff --git a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs index e65123b8a9492..0687fc319af68 100644 --- a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs +++ b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs @@ -224,7 +224,7 @@ fn is_unreachable_or_panic(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { return false; }; if is_panic(cx, macro_call.def_id) { - return !cx.tcx.hir().is_inside_const_context(expr.hir_id); + return !cx.tcx.hir_is_inside_const_context(expr.hir_id); } matches!(cx.tcx.item_name(macro_call.def_id).as_str(), "unreachable") } diff --git a/src/tools/clippy/clippy_lints/src/unused_peekable.rs b/src/tools/clippy/clippy_lints/src/unused_peekable.rs index 0f9b05c84d4b0..7487e273caa7e 100644 --- a/src/tools/clippy/clippy_lints/src/unused_peekable.rs +++ b/src/tools/clippy/clippy_lints/src/unused_peekable.rs @@ -118,7 +118,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> { if path_to_local_id(ex, self.expected_hir_id) { - for (_, node) in self.cx.tcx.hir().parent_iter(ex.hir_id) { + for (_, node) in self.cx.tcx.hir_parent_iter(ex.hir_id) { match node { Node::Expr(expr) => { match expr.kind { diff --git a/src/tools/clippy/clippy_lints/src/unused_self.rs b/src/tools/clippy/clippy_lints/src/unused_self.rs index d8305a6282908..2c6c75693166f 100644 --- a/src/tools/clippy/clippy_lints/src/unused_self.rs +++ b/src/tools/clippy/clippy_lints/src/unused_self.rs @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id; + let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let parent_item = cx.tcx.hir().expect_item(parent); let assoc_item = cx.tcx.associated_item(impl_item.owner_id); let contains_todo = |cx, body: &'_ Body<'_>| -> bool { diff --git a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs index 1221abec1abf0..4c9a7f0e16de6 100644 --- a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs +++ b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs @@ -73,8 +73,8 @@ impl LateLintPass<'_> for ZeroSizedMapValues { } fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { - let parent_id = cx.tcx.hir().get_parent_item(hir_id); - let second_parent_id = cx.tcx.hir().get_parent_item(parent_id.into()).def_id; + let parent_id = cx.tcx.hir_get_parent_item(hir_id); + let second_parent_id = cx.tcx.hir_get_parent_item(parent_id.into()).def_id; if let Node::Item(item) = cx.tcx.hir_node_by_def_id(second_parent_id) { if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs index 6bb876322f24f..c4d00002292c9 100644 --- a/src/tools/clippy/clippy_utils/src/higher.rs +++ b/src/tools/clippy/clippy_utils/src/higher.rs @@ -117,7 +117,7 @@ impl<'hir> IfLet<'hir> { if_else, ) = expr.kind { - let mut iter = cx.tcx.hir().parent_iter(expr.hir_id); + let mut iter = cx.tcx.hir_parent_iter(expr.hir_id); if let Some((_, Node::Block(Block { stmts: [], .. }))) = iter.next() { if let Some(( _, diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 15e395731ade4..40ddd75b7fad1 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -212,7 +212,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option< /// /// e.g. returns true for `x` in `fn f(x: usize) { .. }` and `let x = 1;` but false for `let x;` pub fn local_is_initialized(cx: &LateContext<'_>, local: HirId) -> bool { - for (_, node) in cx.tcx.hir().parent_iter(local) { + for (_, node) in cx.tcx.hir_parent_iter(local) { match node { Node::Pat(..) | Node::PatField(..) => {}, Node::LetStmt(let_stmt) => return let_stmt.init.is_some(), @@ -227,7 +227,7 @@ pub fn local_is_initialized(cx: &LateContext<'_>, local: HirId) -> bool { /// /// The current context is determined based on the current body which is set before calling a lint's /// entry point (any function on `LateLintPass`). If you need to check in a different context use -/// `tcx.hir().is_inside_const_context(_)`. +/// `tcx.hir_is_inside_const_context(_)`. /// /// Do not call this unless the `LateContext` has an enclosing body. For release build this case /// will safely return `false`, but debug builds will ICE. Note that `check_expr`, `check_block`, @@ -806,7 +806,7 @@ pub fn get_trait_def_id(tcx: TyCtxt<'_>, path: &[&str]) -> Option { pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) -> Option<&'tcx TraitRef<'tcx>> { // Get the implemented trait for the current function let hir_id = cx.tcx.local_def_id_to_hir_id(def_id); - let parent_impl = cx.tcx.hir().get_parent_item(hir_id); + let parent_impl = cx.tcx.hir_get_parent_item(hir_id); if parent_impl != hir::CRATE_OWNER_ID && let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent_impl.def_id) && let ItemKind::Impl(impl_) = &item.kind @@ -1117,7 +1117,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind { let mut capture = CaptureKind::Value; let mut capture_expr_ty = e; - for (parent_id, parent) in cx.tcx.hir().parent_iter(e.hir_id) { + for (parent_id, parent) in cx.tcx.hir_parent_iter(e.hir_id) { if let [ Adjustment { kind: Adjust::Deref(_) | Adjust::Borrow(AutoBorrow::Ref(..)), @@ -1336,13 +1336,13 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool { /// Returns `true` if the expression is in the program's `#[panic_handler]`. pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { - let parent = cx.tcx.hir().get_parent_item(e.hir_id); + let parent = cx.tcx.hir_get_parent_item(e.hir_id); Some(parent.to_def_id()) == cx.tcx.lang_items().panic_impl() } /// Gets the name of the item the expression is in, if available. pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { - let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id).def_id; + let parent_id = cx.tcx.hir_get_parent_item(expr.hir_id).def_id; match cx.tcx.hir_node_by_def_id(parent_id) { Node::Item(Item { ident, .. }) | Node::TraitItem(TraitItem { ident, .. }) @@ -1407,9 +1407,9 @@ pub fn get_parent_expr_for_hir<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> O /// Gets the enclosing block, if any. pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Block<'tcx>> { - let map = &cx.tcx.hir(); - let enclosing_node = map - .get_enclosing_scope(hir_id) + let enclosing_node = cx + .tcx + .hir_get_enclosing_scope(hir_id) .map(|enclosing_id| cx.tcx.hir_node(enclosing_id)); enclosing_node.and_then(|node| match node { Node::Block(block) => Some(block), @@ -1433,7 +1433,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( cx: &LateContext<'tcx>, expr: &Expr<'_>, ) -> Option<&'tcx Expr<'tcx>> { - for (_, node) in cx.tcx.hir().parent_iter(expr.hir_id) { + for (_, node) in cx.tcx.hir_parent_iter(expr.hir_id) { match node { Node::Expr(e) => match e.kind { ExprKind::Closure { .. } @@ -1453,7 +1453,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( /// Gets the parent node if it's an impl block. pub fn get_parent_as_impl(tcx: TyCtxt<'_>, id: HirId) -> Option<&Impl<'_>> { - match tcx.hir().parent_iter(id).next() { + match tcx.hir_parent_iter(id).next() { Some(( _, Node::Item(Item { @@ -1531,7 +1531,7 @@ pub fn peel_blocks_with_stmt<'a>(mut expr: &'a Expr<'a>) -> &'a Expr<'a> { /// Checks if the given expression is the else clause of either an `if` or `if let` expression. pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { - let mut iter = tcx.hir().parent_iter(expr.hir_id); + let mut iter = tcx.hir_parent_iter(expr.hir_id); match iter.next() { Some(( _, @@ -1548,7 +1548,7 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { /// returns `true` for both the `init` and the `else` part pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; - for (parent_id, node) in tcx.hir().parent_iter(child_id) { + for (parent_id, node) in tcx.hir_parent_iter(child_id) { if let Node::LetStmt(LetStmt { init: Some(init), els: Some(els), @@ -1568,7 +1568,7 @@ pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { /// Checks if the given expression is the else clause of a `let else` expression pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { let mut child_id = expr.hir_id; - for (parent_id, node) in tcx.hir().parent_iter(child_id) { + for (parent_id, node) in tcx.hir_parent_iter(child_id) { if let Node::LetStmt(LetStmt { els: Some(els), .. }) = node && els.hir_id == child_id { @@ -1961,7 +1961,7 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool return true; } prev_enclosing_node = Some(enclosing_node); - enclosing_node = map.get_parent_item(enclosing_node).into(); + enclosing_node = tcx.hir_get_parent_item(enclosing_node).into(); } false @@ -1970,8 +1970,8 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool /// Checks if the given HIR node is inside an `impl` block with the `automatically_derived` /// attribute. pub fn in_automatically_derived(tcx: TyCtxt<'_>, id: HirId) -> bool { - tcx.hir() - .parent_owner_iter(id) + tcx + .hir_parent_owner_iter(id) .filter(|(_, node)| matches!(node, OwnerNode::Item(item) if matches!(item.kind, ItemKind::Impl(_)))) .any(|(id, _)| { has_attr( @@ -2202,7 +2202,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool /// Returns both the node and the `HirId` of the closest child node. pub fn get_expr_use_or_unification_node<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<(Node<'tcx>, HirId)> { let mut child_id = expr.hir_id; - let mut iter = tcx.hir().parent_iter(child_id); + let mut iter = tcx.hir_parent_iter(child_id); loop { match iter.next() { None => break None, @@ -2581,7 +2581,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool { with_test_item_names(tcx, tcx.parent_module(id), |names| { let node = tcx.hir_node(id); once((id, node)) - .chain(tcx.hir().parent_iter(id)) + .chain(tcx.hir_parent_iter(id)) // Since you can nest functions we need to collect all until we leave // function scope .any(|(_id, node)| { @@ -2617,8 +2617,8 @@ pub fn is_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool { /// Checks if any parent node of `HirId` has `#[cfg(test)]` attribute applied pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool { - tcx.hir() - .parent_id_iter(id) + tcx + .hir_parent_id_iter(id) .any(|parent_id| is_cfg_test(tcx, parent_id)) } @@ -2632,8 +2632,8 @@ pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { let hir = tcx.hir(); tcx.has_attr(def_id, sym::cfg) - || hir - .parent_iter(tcx.local_def_id_to_hir_id(def_id)) + || tcx + .hir_parent_iter(tcx.local_def_id_to_hir_id(def_id)) .flat_map(|(parent_id, _)| hir.attrs(parent_id)) .any(|attr| attr.has_name(sym::cfg)) } @@ -2653,8 +2653,7 @@ pub fn walk_to_expr_usage<'tcx, T>( e: &Expr<'tcx>, mut f: impl FnMut(HirId, Node<'tcx>, HirId) -> ControlFlow, ) -> Option, HirId)>> { - let map = cx.tcx.hir(); - let mut iter = map.parent_iter(e.hir_id); + let mut iter = cx.tcx.hir_parent_iter(e.hir_id); let mut child_id = e.hir_id; while let Some((parent_id, parent)) = iter.next() { @@ -2677,7 +2676,7 @@ pub fn walk_to_expr_usage<'tcx, T>( ExprKind::If(child, ..) | ExprKind::Match(child, ..) if child.hir_id != child_id => child_id = parent_id, ExprKind::Break(Destination { target_id: Ok(id), .. }, _) => { child_id = id; - iter = map.parent_iter(id); + iter = cx.tcx.hir_parent_iter(id); }, ExprKind::Block(..) | ExprKind::DropTemps(_) => child_id = parent_id, _ => return Some(ControlFlow::Continue((parent, child_id))), diff --git a/src/tools/clippy/clippy_utils/src/macros.rs b/src/tools/clippy/clippy_utils/src/macros.rs index 30fd48fc0605b..9ce0fd8318f1d 100644 --- a/src/tools/clippy/clippy_utils/src/macros.rs +++ b/src/tools/clippy/clippy_utils/src/macros.rs @@ -178,7 +178,7 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option< // get the parent node, possibly skipping over a statement // if the parent is not found, it is sensible to return `Some(root)` let hir = cx.tcx.hir(); - let mut parent_iter = hir.parent_iter(node.hir_id()); + let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id()); let (parent_id, _) = match parent_iter.next() { None => return Some(ExpnId::root()), Some((_, Node::Stmt(_))) => match parent_iter.next() { diff --git a/src/tools/tidy/src/target_policy.rs b/src/tools/tidy/src/target_policy.rs index b2681934417cb..776221d306233 100644 --- a/src/tools/tidy/src/target_policy.rs +++ b/src/tools/tidy/src/target_policy.rs @@ -21,7 +21,6 @@ const EXCEPTIONS: &[&str] = &[ "xtensa_esp32s2_espidf", "xtensa_esp32s3_none_elf", "xtensa_esp32s3_espidf", - "i586_pc_nto_qnx700", // Renamed to i686-pc-nto-qnx700, see https://github.com/rust-lang/rust/issues/136495 ]; pub fn check(root_path: &Path, bad: &mut bool) {