Skip to content

Commit ccc9ba5

Browse files
committed
Auto merge of rust-lang#136225 - fmease:rollup-fm7m744, r=fmease
Rollup of 7 pull requests Successful merges: - rust-lang#135625 ([cfg_match] Document the use of expressions.) - rust-lang#135902 (Do not consider child bound assumptions for rigid alias) - rust-lang#135943 (Rename `Piece::String` to `Piece::Lit`) - rust-lang#136104 (Add mermaid graphs of NLL regions and SCCs to polonius MIR dump) - rust-lang#136143 (Update books) - rust-lang#136147 (ABI-required target features: warn when they are missing in base CPU) - rust-lang#136164 (Refactor FnKind variant to hold &Fn) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 122fb29 + 2839307 commit ccc9ba5

File tree

66 files changed

+563
-395
lines changed

Some content is hidden

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

66 files changed

+563
-395
lines changed

compiler/rustc_ast/src/mut_visit.rs

+14-22
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,14 @@ fn walk_coroutine_kind<T: MutVisitor>(vis: &mut T, coroutine_kind: &mut Coroutin
954954

955955
fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
956956
match kind {
957-
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, _visibility, generics, body) => {
957+
FnKind::Fn(
958+
_ctxt,
959+
_ident,
960+
_vis,
961+
Fn { defaultness, generics, body, sig: FnSig { header, decl, span } },
962+
) => {
958963
// Identifier and visibility are visited as a part of the item.
964+
visit_defaultness(vis, defaultness);
959965
vis.visit_fn_header(header);
960966
vis.visit_generics(generics);
961967
vis.visit_fn_decl(decl);
@@ -1205,13 +1211,8 @@ impl WalkItemKind for ItemKind {
12051211
ItemKind::Const(item) => {
12061212
visit_const_item(item, vis);
12071213
}
1208-
ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
1209-
visit_defaultness(vis, defaultness);
1210-
vis.visit_fn(
1211-
FnKind::Fn(FnCtxt::Free, ident, sig, visibility, generics, body),
1212-
span,
1213-
id,
1214-
);
1214+
ItemKind::Fn(func) => {
1215+
vis.visit_fn(FnKind::Fn(FnCtxt::Free, ident, visibility, &mut *func), span, id);
12151216
}
12161217
ItemKind::Mod(safety, mod_kind) => {
12171218
visit_safety(vis, safety);
@@ -1329,10 +1330,9 @@ impl WalkItemKind for AssocItemKind {
13291330
AssocItemKind::Const(item) => {
13301331
visit_const_item(item, visitor);
13311332
}
1332-
AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
1333-
visit_defaultness(visitor, defaultness);
1333+
AssocItemKind::Fn(func) => {
13341334
visitor.visit_fn(
1335-
FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, visibility, generics, body),
1335+
FnKind::Fn(FnCtxt::Assoc(ctxt), ident, visibility, &mut *func),
13361336
span,
13371337
id,
13381338
);
@@ -1476,10 +1476,9 @@ impl WalkItemKind for ForeignItemKind {
14761476
visitor.visit_ty(ty);
14771477
visit_opt(expr, |expr| visitor.visit_expr(expr));
14781478
}
1479-
ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
1480-
visit_defaultness(visitor, defaultness);
1479+
ForeignItemKind::Fn(func) => {
14811480
visitor.visit_fn(
1482-
FnKind::Fn(FnCtxt::Foreign, ident, sig, visibility, generics, body),
1481+
FnKind::Fn(FnCtxt::Foreign, ident, visibility, &mut *func),
14831482
span,
14841483
id,
14851484
);
@@ -1965,14 +1964,7 @@ impl<N: DummyAstNode, T: DummyAstNode> DummyAstNode for crate::ast_traits::AstNo
19651964
#[derive(Debug)]
19661965
pub enum FnKind<'a> {
19671966
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
1968-
Fn(
1969-
FnCtxt,
1970-
&'a mut Ident,
1971-
&'a mut FnSig,
1972-
&'a mut Visibility,
1973-
&'a mut Generics,
1974-
&'a mut Option<P<Block>>,
1975-
),
1967+
Fn(FnCtxt, &'a mut Ident, &'a mut Visibility, &'a mut Fn),
19761968

19771969
/// E.g., `|x, y| body`.
19781970
Closure(

compiler/rustc_ast/src/visit.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl BoundKind {
6565
#[derive(Copy, Clone, Debug)]
6666
pub enum FnKind<'a> {
6767
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
68-
Fn(FnCtxt, &'a Ident, &'a FnSig, &'a Visibility, &'a Generics, &'a Option<P<Block>>),
68+
Fn(FnCtxt, &'a Ident, &'a Visibility, &'a Fn),
6969

7070
/// E.g., `|x, y| body`.
7171
Closure(&'a ClosureBinder, &'a Option<CoroutineKind>, &'a FnDecl, &'a Expr),
@@ -74,7 +74,7 @@ pub enum FnKind<'a> {
7474
impl<'a> FnKind<'a> {
7575
pub fn header(&self) -> Option<&'a FnHeader> {
7676
match *self {
77-
FnKind::Fn(_, _, sig, _, _, _) => Some(&sig.header),
77+
FnKind::Fn(_, _, _, Fn { sig, .. }) => Some(&sig.header),
7878
FnKind::Closure(..) => None,
7979
}
8080
}
@@ -88,7 +88,7 @@ impl<'a> FnKind<'a> {
8888

8989
pub fn decl(&self) -> &'a FnDecl {
9090
match self {
91-
FnKind::Fn(_, _, sig, _, _, _) => &sig.decl,
91+
FnKind::Fn(_, _, _, Fn { sig, .. }) => &sig.decl,
9292
FnKind::Closure(_, _, decl, _) => decl,
9393
}
9494
}
@@ -374,8 +374,8 @@ impl WalkItemKind for ItemKind {
374374
try_visit!(visitor.visit_ty(ty));
375375
visit_opt!(visitor, visit_expr, expr);
376376
}
377-
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
378-
let kind = FnKind::Fn(FnCtxt::Free, ident, sig, vis, generics, body);
377+
ItemKind::Fn(func) => {
378+
let kind = FnKind::Fn(FnCtxt::Free, ident, vis, &*func);
379379
try_visit!(visitor.visit_fn(kind, span, id));
380380
}
381381
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
@@ -715,8 +715,8 @@ impl WalkItemKind for ForeignItemKind {
715715
try_visit!(visitor.visit_ty(ty));
716716
visit_opt!(visitor, visit_expr, expr);
717717
}
718-
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
719-
let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body);
718+
ForeignItemKind::Fn(func) => {
719+
let kind = FnKind::Fn(FnCtxt::Foreign, ident, vis, &*func);
720720
try_visit!(visitor.visit_fn(kind, span, id));
721721
}
722722
ForeignItemKind::TyAlias(box TyAlias {
@@ -858,7 +858,12 @@ pub fn walk_fn_decl<'a, V: Visitor<'a>>(
858858

859859
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
860860
match kind {
861-
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span: _ }, _vis, generics, body) => {
861+
FnKind::Fn(
862+
_ctxt,
863+
_ident,
864+
_vis,
865+
Fn { defaultness: _, sig: FnSig { header, decl, span: _ }, generics, body },
866+
) => {
862867
// Identifier and visibility are visited as a part of the item.
863868
try_visit!(visitor.visit_fn_header(header));
864869
try_visit!(visitor.visit_generics(generics));
@@ -892,8 +897,8 @@ impl WalkItemKind for AssocItemKind {
892897
try_visit!(visitor.visit_ty(ty));
893898
visit_opt!(visitor, visit_expr, expr);
894899
}
895-
AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
896-
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body);
900+
AssocItemKind::Fn(func) => {
901+
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, vis, &*func);
897902
try_visit!(visitor.visit_fn(kind, span, id));
898903
}
899904
AssocItemKind::Type(box TyAlias {

compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21252125
self.arena.alloc(self.expr_call_mut(span, e, args))
21262126
}
21272127

2128-
fn expr_call_lang_item_fn_mut(
2128+
pub(super) fn expr_call_lang_item_fn_mut(
21292129
&mut self,
21302130
span: Span,
21312131
lang_item: hir::LangItem,
@@ -2135,7 +2135,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21352135
self.expr_call_mut(span, path, args)
21362136
}
21372137

2138-
fn expr_call_lang_item_fn(
2138+
pub(super) fn expr_call_lang_item_fn(
21392139
&mut self,
21402140
span: Span,
21412141
lang_item: hir::LangItem,

compiler/rustc_ast_passes/src/ast_validation.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
917917
walk_list!(self, visit_attribute, &item.attrs);
918918
return; // Avoid visiting again.
919919
}
920-
ItemKind::Fn(box Fn { defaultness, sig, generics, body }) => {
920+
ItemKind::Fn(func @ box Fn { defaultness, generics: _, sig, body }) => {
921921
self.check_defaultness(item.span, *defaultness);
922922

923923
let is_intrinsic =
@@ -947,7 +947,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
947947

948948
self.visit_vis(&item.vis);
949949
self.visit_ident(&item.ident);
950-
let kind = FnKind::Fn(FnCtxt::Free, &item.ident, sig, &item.vis, generics, body);
950+
let kind = FnKind::Fn(FnCtxt::Free, &item.ident, &item.vis, &*func);
951951
self.visit_fn(kind, item.span, item.id);
952952
walk_list!(self, visit_attribute, &item.attrs);
953953
return; // Avoid visiting again.
@@ -1348,19 +1348,20 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13481348
}
13491349

13501350
if let FnKind::Fn(
1351-
_,
1352-
_,
1353-
FnSig { header: FnHeader { ext: Extern::Implicit(extern_span), .. }, .. },
13541351
_,
13551352
_,
13561353
_,
1354+
Fn {
1355+
sig: FnSig { header: FnHeader { ext: Extern::Implicit(extern_span), .. }, .. },
1356+
..
1357+
},
13571358
) = fk
13581359
{
13591360
self.maybe_lint_missing_abi(*extern_span, id);
13601361
}
13611362

13621363
// Functions without bodies cannot have patterns.
1363-
if let FnKind::Fn(ctxt, _, sig, _, _, None) = fk {
1364+
if let FnKind::Fn(ctxt, _, _, Fn { body: None, sig, .. }) = fk {
13641365
Self::check_decl_no_pat(&sig.decl, |span, ident, mut_ident| {
13651366
if mut_ident && matches!(ctxt, FnCtxt::Assoc(_)) {
13661367
if let Some(ident) = ident {
@@ -1394,7 +1395,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13941395
.is_some();
13951396

13961397
let disallowed = (!tilde_const_allowed).then(|| match fk {
1397-
FnKind::Fn(_, ident, _, _, _, _) => TildeConstReason::Function { ident: ident.span },
1398+
FnKind::Fn(_, ident, _, _) => TildeConstReason::Function { ident: ident.span },
13981399
FnKind::Closure(..) => TildeConstReason::Closure,
13991400
});
14001401
self.with_tilde_const(disallowed, |this| visit::walk_fn(this, fk));
@@ -1470,15 +1471,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14701471
self.outer_trait_or_trait_impl.as_ref().and_then(TraitOrTraitImpl::constness).is_some();
14711472

14721473
match &item.kind {
1473-
AssocItemKind::Fn(box Fn { sig, generics, body, .. })
1474+
AssocItemKind::Fn(func)
14741475
if parent_is_const
14751476
|| ctxt == AssocCtxt::Trait
1476-
|| matches!(sig.header.constness, Const::Yes(_)) =>
1477+
|| matches!(func.sig.header.constness, Const::Yes(_)) =>
14771478
{
14781479
self.visit_vis(&item.vis);
14791480
self.visit_ident(&item.ident);
1480-
let kind =
1481-
FnKind::Fn(FnCtxt::Assoc(ctxt), &item.ident, sig, &item.vis, generics, body);
1481+
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), &item.ident, &item.vis, &*func);
14821482
walk_list!(self, visit_attribute, &item.attrs);
14831483
self.visit_fn(kind, item.span, item.id);
14841484
}

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl<'a> State<'a> {
3434
self.maybe_print_comment(span.lo());
3535
self.print_outer_attributes(attrs);
3636
match kind {
37-
ast::ForeignItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
38-
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
37+
ast::ForeignItemKind::Fn(func) => {
38+
self.print_fn_full(ident, vis, attrs, &*func);
3939
}
4040
ast::ForeignItemKind::Static(box ast::StaticItem { ty, mutability, expr, safety }) => {
4141
self.print_item_const(
@@ -199,16 +199,8 @@ impl<'a> State<'a> {
199199
*defaultness,
200200
);
201201
}
202-
ast::ItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
203-
self.print_fn_full(
204-
sig,
205-
item.ident,
206-
generics,
207-
&item.vis,
208-
*defaultness,
209-
body.as_deref(),
210-
&item.attrs,
211-
);
202+
ast::ItemKind::Fn(func) => {
203+
self.print_fn_full(item.ident, &item.vis, &item.attrs, &*func);
212204
}
213205
ast::ItemKind::Mod(safety, mod_kind) => {
214206
self.head(Self::to_string(|s| {
@@ -542,8 +534,8 @@ impl<'a> State<'a> {
542534
self.maybe_print_comment(span.lo());
543535
self.print_outer_attributes(attrs);
544536
match kind {
545-
ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
546-
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
537+
ast::AssocItemKind::Fn(func) => {
538+
self.print_fn_full(ident, vis, attrs, &*func);
547539
}
548540
ast::AssocItemKind::Const(box ast::ConstItem { defaultness, generics, ty, expr }) => {
549541
self.print_item_const(
@@ -653,19 +645,17 @@ impl<'a> State<'a> {
653645

654646
fn print_fn_full(
655647
&mut self,
656-
sig: &ast::FnSig,
657648
name: Ident,
658-
generics: &ast::Generics,
659649
vis: &ast::Visibility,
660-
defaultness: ast::Defaultness,
661-
body: Option<&ast::Block>,
662650
attrs: &[ast::Attribute],
651+
func: &ast::Fn,
663652
) {
653+
let ast::Fn { defaultness, generics, sig, body } = func;
664654
if body.is_some() {
665655
self.head("");
666656
}
667657
self.print_visibility(vis);
668-
self.print_defaultness(defaultness);
658+
self.print_defaultness(*defaultness);
669659
self.print_fn(&sig.decl, sig.header, Some(name), generics);
670660
if let Some(body) = body {
671661
self.nbsp();

0 commit comments

Comments
 (0)