Auto merge of #137397 - matthiaskrgr:rollup-ls2pilo, r=matthiaskrgr

Rollup of 10 pull requests

Successful merges:

 - #132876 (rustdoc book: acknowledge --document-hidden-items)
 - #136148 (Optionally add type names to `TypeId`s.)
 - #136609 (libcore/net: `IpAddr::as_octets()`)
 - #137336 (Stabilise `os_str_display`)
 - #137350 (Move methods from Map to TyCtxt, part 3.)
 - #137353 (Implement `read_buf` for WASI stdin)
 - #137361 (Refactor `OperandRef::extract_field` to prep for MCP838)
 - #137367 (Do not exempt nonexistent platforms from platform policy)
 - #137374 (Stacker now handles miri using a noop impl itself)
 - #137392 (remove few unused fields)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-02-21 19:57:50 +00:00
commit 794c12416b
126 changed files with 422 additions and 351 deletions

View file

@ -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",

View file

@ -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::<Vec<Span>>();
// 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

View file

@ -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<G: EmissionGuarantee>(
);
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 {

View file

@ -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

View file

@ -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, .. }, ..
})

View file

@ -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<RegionName> {
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")

View file

@ -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);
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));
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);
if let Some(field_val) = fx.codegen_transmute_operand(bx, *self, field) {
field_val
} else {
// we have to go through memory for things like
// 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
}
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 <https://github.com/rust-lang/rust/issues/137108>",
);
}
BackendRepr::ScalarPair(_, _) | BackendRepr::Memory { sized: false } => bug!(),
BackendRepr::ScalarPair(_, _) | BackendRepr::Memory { .. } => bug!(),
})
};

View file

@ -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<R>(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<R>(f: impl FnOnce() -> R) -> R {
f()
}

View file

@ -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 {

View file

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

View file

@ -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,

View file

@ -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

View file

@ -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 };

View file

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

View file

@ -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);

View file

@ -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);

View file

@ -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),

View file

@ -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);

View file

@ -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 =

View file

@ -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 {

View file

@ -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<Ty = Trait1>`
// and suggest `Trait0<Ty = impl Trait1>`.
// 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()

View file

@ -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,

View file

@ -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)
}

View file

@ -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 {

View file

@ -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...

View file

@ -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

View file

@ -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()

View file

@ -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 {

View file

@ -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, ..

View file

@ -2052,7 +2052,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
fn parent_item_span(&self, id: HirId) -> Option<Span> {
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),

View file

@ -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;

View file

@ -2390,7 +2390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
long_ty_path: &mut Option<PathBuf>,
) -> 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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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()),

View file

@ -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

View file

@ -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,

View file

@ -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_

View file

@ -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

View file

@ -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

View file

@ -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<Self::Item> {
@ -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<Self::Item> {
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<Item = HirId> + 'hir {
pub fn hir_parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + '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<Item = (HirId, Node<'hir>)> {
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<Item = (HirId, Node<'tcx>)> {
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<HirId> {
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<HirId> {
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<HirId> {
for (hir_id, node) in self.parent_iter(hir_id) {
pub fn hir_get_enclosing_scope(self, hir_id: HirId) -> Option<HirId> {
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)
{

View file

@ -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;

View file

@ -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));

View file

@ -1370,7 +1370,6 @@ pub struct GlobalCtxt<'tcx> {
// Internal caches for metadata decoding. No need to track deps on this.
pub ty_rcache: Lock<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
pub pred_rcache: Lock<FxHashMap<ty::CReaderCacheKey, Predicate<'tcx>>>,
/// 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<Span> {
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());
}

View file

@ -179,7 +179,7 @@ pub struct ResolverGlobalCtxt {
pub confused_type_with_std_module: FxIndexMap<Span, Span>,
pub doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
pub doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
pub all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
pub all_macro_rules: FxHashSet<Symbol>,
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
}

View file

@ -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

View file

@ -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 {

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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,

View file

@ -1220,7 +1220,7 @@ pub struct Resolver<'ra, 'tcx> {
effective_visibilities: EffectiveVisibilities,
doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
all_macro_rules: FxHashMap<Symbol, Res>,
all_macro_rules: FxHashSet<Symbol>,
/// Invocation ids of all glob delegations.
glob_delegation_invoc_ids: FxHashSet<LocalExpnId>,

View file

@ -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

View file

@ -586,7 +586,7 @@ impl<T> Trait<T> 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);

View file

@ -587,7 +587,7 @@ fn attempt_dyn_to_impl_suggestion(tcx: TyCtxt<'_>, hir_id: Option<hir::HirId>, e
// `type Alias = Box<dyn DynIncompatibleTrait>;` to
// `type Alias = Box<impl DynIncompatibleTrait>;`
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;
};

View file

@ -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(

View file

@ -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

View file

@ -95,7 +95,7 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> DefIdMap<DefId>
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_) => {

View file

@ -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

View file

@ -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"

View file

@ -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<T: ?Sized + 'static>() -> TypeId {
let t: u128 = intrinsics::type_id::<T>();
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::<T>(),
}
}
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(())
}
}

View file

@ -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

View file

@ -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

View file

@ -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"]

View file

@ -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;

View file

@ -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)

View file

@ -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<usize> {
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(())
}

View file

@ -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"]

View file

@ -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

View file

@ -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)]`
<span id="document-hidden-items"></span>
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)

View file

@ -230,9 +230,8 @@ If you want to know more about inlining rules, take a look at the
<span id="dochidden"></span>
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).

View file

@ -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)]

View file

@ -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, \

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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

View file

@ -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);
}
});

View file

@ -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 {

View file

@ -61,7 +61,7 @@ pub(super) fn check<'tcx>(
}
fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<FnRetTy<'tcx>> {
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.

View file

@ -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

View file

@ -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

View file

@ -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 {

View file

@ -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)))
}

View file

@ -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)

View file

@ -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()
{

View file

@ -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)

View file

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

View file

@ -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 {

View file

@ -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)| {

View file

@ -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(..) => {},

View file

@ -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))
});

View file

@ -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 {

View file

@ -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

View file

@ -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(_)))

View file

@ -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:

View file

@ -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 {

View file

@ -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)

Some files were not shown because too many files have changed in this diff Show more