Skip to content

Commit

Permalink
Auto merge of #137397 - matthiaskrgr:rollup-ls2pilo, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Feb 21, 2025
2 parents 71e06b9 + cfc2d11 commit 794c124
Show file tree
Hide file tree
Showing 126 changed files with 422 additions and 351 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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), .. }) => {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: _,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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, .. }, ..
})
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
46 changes: 24 additions & 22 deletions compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
Expand All @@ -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!(),
})
};

Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_data_structures/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 };

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 794c124

Please sign in to comment.