Skip to content

Commit e015ef5

Browse files
committed
Auto merge of #90119 - JohnTitor:rollup-e5t6khz, r=JohnTitor
Rollup of 14 pull requests Successful merges: - #86984 (Reject octal zeros in IPv4 addresses) - #87440 (Remove unnecessary condition in Barrier::wait()) - #88644 (`AbstractConst` private fields) - #89292 (Stabilize CString::from_vec_with_nul[_unchecked]) - #90010 (Avoid overflow in `VecDeque::with_capacity_in()`.) - #90029 (Add test for debug logging during incremental compilation) - #90031 (config: add the option to enable LLVM tests) - #90048 (Add test for line-number setting) - #90071 (Remove hir::map::blocks and use FnKind instead) - #90074 (2229 migrations small cleanup) - #90077 (Make `From` impls of NonZero integer const.) - #90097 (Add test for duplicated sidebar entries for reexported macro) - #90098 (Add test to ensure that the missing_doc_code_examples is not triggered on foreign trait implementations) - #90099 (Fix MIRI UB in `Vec::swap_remove`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 40ebd07 + 3680ecd commit e015ef5

File tree

41 files changed

+227
-342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+227
-342
lines changed

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_hir as hir;
22
use rustc_hir::def_id::DefId;
3-
use rustc_middle::hir::map::blocks::FnLikeNode;
43
use rustc_middle::ty::query::Providers;
54
use rustc_middle::ty::TyCtxt;
65
use rustc_span::symbol::Symbol;
@@ -44,8 +43,8 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
4443
} else {
4544
false
4645
}
47-
} else if let Some(fn_like) = FnLikeNode::from_node(node) {
48-
if fn_like.constness() == hir::Constness::Const {
46+
} else if let Some(fn_kind) = node.fn_kind() {
47+
if fn_kind.constness() == hir::Constness::Const {
4948
return true;
5049
}
5150

compiler/rustc_hir/src/hir.rs

+27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::def::{CtorKind, DefKind, Res};
22
use crate::def_id::DefId;
33
crate use crate::hir_id::{HirId, ItemLocalId};
4+
use crate::intravisit::FnKind;
45
use crate::LangItem;
56

67
use rustc_ast::util::parser::ExprPrecedence;
@@ -3258,6 +3259,32 @@ impl<'hir> Node<'hir> {
32583259
_ => None,
32593260
}
32603261
}
3262+
3263+
pub fn fn_kind(self) -> Option<FnKind<'hir>> {
3264+
match self {
3265+
Node::Item(i) => match i.kind {
3266+
ItemKind::Fn(ref sig, ref generics, _) => {
3267+
Some(FnKind::ItemFn(i.ident, generics, sig.header, &i.vis))
3268+
}
3269+
_ => None,
3270+
},
3271+
Node::TraitItem(ti) => match ti.kind {
3272+
TraitItemKind::Fn(ref sig, TraitFn::Provided(_)) => {
3273+
Some(FnKind::Method(ti.ident, sig, None))
3274+
}
3275+
_ => None,
3276+
},
3277+
Node::ImplItem(ii) => match ii.kind {
3278+
ImplItemKind::Fn(ref sig, _) => Some(FnKind::Method(ii.ident, sig, Some(&ii.vis))),
3279+
_ => None,
3280+
},
3281+
Node::Expr(e) => match e.kind {
3282+
ExprKind::Closure(..) => Some(FnKind::Closure),
3283+
_ => None,
3284+
},
3285+
_ => None,
3286+
}
3287+
}
32613288
}
32623289

32633290
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.

compiler/rustc_hir/src/intravisit.rs

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ impl<'a> FnKind<'a> {
117117
FnKind::Closure => None,
118118
}
119119
}
120+
121+
pub fn constness(self) -> Constness {
122+
self.header().map_or(Constness::NotConst, |header| header.constness)
123+
}
124+
125+
pub fn asyncness(self) -> IsAsync {
126+
self.header().map_or(IsAsync::NotAsync, |header| header.asyncness)
127+
}
120128
}
121129

122130
/// An abstract representation of the HIR `rustc_middle::hir::map::Map`.

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
143143
// similar to the asyncness fn in rustc_ty_utils::ty
144144
let hir_id = self.tcx().hir().local_def_id_to_hir_id(local_def_id);
145145
let node = self.tcx().hir().get(hir_id);
146-
let fn_like = rustc_middle::hir::map::blocks::FnLikeNode::from_node(node)?;
147-
148-
Some(fn_like.asyncness())
146+
let fn_kind = node.fn_kind()?;
147+
Some(fn_kind.asyncness())
149148
}
150149

151150
// Here, we check for the case where the anonymous region

compiler/rustc_middle/src/hir/map/blocks.rs

-239
This file was deleted.

compiler/rustc_middle/src/hir/map/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use rustc_span::Span;
2020
use rustc_target::spec::abi::Abi;
2121
use std::collections::VecDeque;
2222

23-
pub mod blocks;
24-
2523
fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
2624
match node {
2725
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })

compiler/rustc_mir_build/src/lints.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_data_structures::graph::iterate::{
22
NodeStatus, TriColorDepthFirstSearch, TriColorVisitor,
33
};
44
use rustc_hir::intravisit::FnKind;
5-
use rustc_middle::hir::map::blocks::FnLikeNode;
65
use rustc_middle::mir::{BasicBlock, Body, Operand, TerminatorKind};
76
use rustc_middle::ty::subst::{GenericArg, InternalSubsts};
87
use rustc_middle::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt};
@@ -14,8 +13,8 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1413
let def_id = body.source.def_id().expect_local();
1514
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
1615

17-
if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) {
18-
if let FnKind::Closure = fn_like_node.kind() {
16+
if let Some(fn_kind) = tcx.hir().get(hir_id).fn_kind() {
17+
if let FnKind::Closure = fn_kind {
1918
// closures can't recur, so they don't matter.
2019
return;
2120
}

compiler/rustc_mir_transform/src/const_prop.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
6868
return;
6969
}
7070

71-
use rustc_middle::hir::map::blocks::FnLikeNode;
7271
let def_id = body.source.def_id().expect_local();
7372
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
7473

75-
let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some();
74+
let is_fn_like = tcx.hir().get(hir_id).fn_kind().is_some();
7675
let is_assoc_const = tcx.def_kind(def_id.to_def_id()) == DefKind::AssocConst;
7776

7877
// Only run const prop on functions, methods, closures and associated constants

compiler/rustc_mir_transform/src/coverage/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1919
use rustc_data_structures::sync::Lrc;
2020
use rustc_index::vec::IndexVec;
2121
use rustc_middle::hir;
22-
use rustc_middle::hir::map::blocks::FnLikeNode;
2322
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
2423
use rustc_middle::mir::coverage::*;
2524
use rustc_middle::mir::dump_enabled;
@@ -64,7 +63,7 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
6463
}
6564

6665
let hir_id = tcx.hir().local_def_id_to_hir_id(mir_source.def_id().expect_local());
67-
let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some();
66+
let is_fn_like = tcx.hir().get(hir_id).fn_kind().is_some();
6867

6968
// Only instrument functions, methods, and closures (not constants since they are evaluated
7069
// at compile time by Miri).
@@ -74,7 +73,7 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
7473
// be tricky if const expressions have no corresponding statements in the enclosing MIR.
7574
// Closures are carved out by their initial `Assign` statement.)
7675
if !is_fn_like {
77-
trace!("InstrumentCoverage skipped for {:?} (not an FnLikeNode)", mir_source.def_id());
76+
trace!("InstrumentCoverage skipped for {:?} (not an fn-like)", mir_source.def_id());
7877
return;
7978
}
8079

0 commit comments

Comments
 (0)