Skip to content

Commit a4cec97

Browse files
committed
Auto merge of rust-lang#98131 - JohnTitor:rollup-c17vjdy, r=JohnTitor
Rollup of 3 pull requests Successful merges: - rust-lang#95118 (Implement stabilization of `#[feature(io_safety)]`.) - rust-lang#98110 (Make `ExprKind::Closure` a struct variant.) - rust-lang#98115 (Remove `rustc_deprecated` diagnostics) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ebe184a + b1e5472 commit a4cec97

File tree

96 files changed

+563
-537
lines changed

Some content is hidden

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

96 files changed

+563
-537
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
577577
};
578578

579579
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
580-
let decl = self.arena.alloc(hir::FnDecl {
580+
let fn_decl = self.arena.alloc(hir::FnDecl {
581581
inputs: arena_vec![self; input_ty],
582582
output,
583583
c_variadic: false,
@@ -598,7 +598,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
598598
};
599599
let params = arena_vec![self; param];
600600

601-
let body_id = self.lower_body(move |this| {
601+
let body = self.lower_body(move |this| {
602602
this.generator_kind = Some(hir::GeneratorKind::Async(async_gen_kind));
603603

604604
let old_ctx = this.task_context;
@@ -609,13 +609,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
609609
});
610610

611611
// `static |_task_context| -> <ret_ty> { body }`:
612-
let generator_kind = hir::ExprKind::Closure(
612+
let generator_kind = hir::ExprKind::Closure {
613613
capture_clause,
614-
decl,
615-
body_id,
616-
self.lower_span(span),
617-
Some(hir::Movability::Static),
618-
);
614+
fn_decl,
615+
body,
616+
fn_decl_span: self.lower_span(span),
617+
movability: Some(hir::Movability::Static),
618+
};
619619
let generator = hir::Expr {
620620
hir_id: self.lower_node_id(closure_node_id),
621621
kind: generator_kind,
@@ -840,7 +840,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
840840
body: &Expr,
841841
fn_decl_span: Span,
842842
) -> hir::ExprKind<'hir> {
843-
let (body_id, generator_option) = self.with_new_scopes(move |this| {
843+
let (body, generator_option) = self.with_new_scopes(move |this| {
844844
let prev = this.current_item;
845845
this.current_item = Some(fn_decl_span);
846846
let mut generator_kind = None;
@@ -858,13 +858,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
858858
// Lower outside new scope to preserve `is_in_loop_condition`.
859859
let fn_decl = self.lower_fn_decl(decl, None, FnDeclKind::Closure, None);
860860

861-
hir::ExprKind::Closure(
861+
hir::ExprKind::Closure {
862862
capture_clause,
863863
fn_decl,
864-
body_id,
865-
self.lower_span(fn_decl_span),
866-
generator_option,
867-
)
864+
body,
865+
fn_decl_span: self.lower_span(fn_decl_span),
866+
movability: generator_option,
867+
}
868868
}
869869

870870
fn generator_movability_for_fn(
@@ -911,7 +911,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
911911
let outer_decl =
912912
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
913913

914-
let body_id = self.with_new_scopes(|this| {
914+
let body = self.with_new_scopes(|this| {
915915
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
916916
if capture_clause == CaptureBy::Ref && !decl.inputs.is_empty() {
917917
struct_span_err!(
@@ -950,13 +950,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
950950
// closure argument types.
951951
let fn_decl = self.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);
952952

953-
hir::ExprKind::Closure(
953+
hir::ExprKind::Closure {
954954
capture_clause,
955955
fn_decl,
956-
body_id,
957-
self.lower_span(fn_decl_span),
958-
None,
959-
)
956+
body,
957+
fn_decl_span: self.lower_span(fn_decl_span),
958+
movability: None,
959+
}
960960
}
961961

962962
/// Destructure the LHS of complex assignments.

compiler/rustc_ast_passes/src/feature_gate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
406406

407407
// Emit errors for non-staged-api crates.
408408
if !self.features.staged_api {
409-
if attr.has_name(sym::rustc_deprecated)
410-
|| attr.has_name(sym::unstable)
409+
if attr.has_name(sym::unstable)
411410
|| attr.has_name(sym::stable)
412411
|| attr.has_name(sym::rustc_const_unstable)
413412
|| attr.has_name(sym::rustc_const_stable)

compiler/rustc_attr/src/builtin.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -720,18 +720,10 @@ where
720720
let is_rustc = sess.features_untracked().staged_api;
721721

722722
'outer: for attr in attrs_iter {
723-
if !(attr.has_name(sym::deprecated) || attr.has_name(sym::rustc_deprecated)) {
723+
if !attr.has_name(sym::deprecated) {
724724
continue;
725725
}
726726

727-
// FIXME(jhpratt) remove this eventually
728-
if attr.has_name(sym::rustc_deprecated) {
729-
diagnostic
730-
.struct_span_err(attr.span, "`#[rustc_deprecated]` has been removed")
731-
.help("use `#[deprecated]` instead")
732-
.emit();
733-
}
734-
735727
let Some(meta) = attr.meta() else {
736728
continue;
737729
};
@@ -787,25 +779,6 @@ where
787779
continue 'outer;
788780
}
789781
}
790-
// FIXME(jhpratt) remove this eventually
791-
sym::reason if attr.has_name(sym::rustc_deprecated) => {
792-
if !get(mi, &mut note) {
793-
continue 'outer;
794-
}
795-
796-
let mut diag = diagnostic
797-
.struct_span_err(mi.span, "`reason` has been renamed");
798-
match note {
799-
Some(note) => diag.span_suggestion(
800-
mi.span,
801-
"use `note` instead",
802-
format!("note = \"{note}\""),
803-
Applicability::MachineApplicable,
804-
),
805-
None => diag.span_help(mi.span, "use `note` instead"),
806-
};
807-
diag.emit();
808-
}
809782
sym::suggestion => {
810783
if !sess.features_untracked().deprecated_suggestion {
811784
let mut diag = sess.struct_span_err(

compiler/rustc_borrowck/src/diagnostics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
896896
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(local_did);
897897
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
898898
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr);
899-
if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr {
899+
if let hir::ExprKind::Closure { body, fn_decl_span, .. } = expr {
900900
for (captured_place, place) in self
901901
.infcx
902902
.tcx
@@ -909,11 +909,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
909909
if target_place == place.as_ref() =>
910910
{
911911
debug!("closure_span: found captured local {:?}", place);
912-
let body = self.infcx.tcx.hir().body(*body_id);
912+
let body = self.infcx.tcx.hir().body(*body);
913913
let generator_kind = body.generator_kind();
914914

915915
return Some((
916-
*args_span,
916+
*fn_decl_span,
917917
generator_kind,
918918
captured_place.get_capture_kind_span(self.infcx.tcx),
919919
captured_place.get_path_span(self.infcx.tcx),

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
311311
// Can't have BrEnv in functions, constants or generators.
312312
bug!("BrEnv outside of closure.");
313313
};
314-
let hir::ExprKind::Closure(_, _, _, args_span, _) =
315-
tcx.hir().expect_expr(self.mir_hir_id()).kind else {
314+
let hir::ExprKind::Closure { fn_decl_span, .. }
315+
= tcx.hir().expect_expr(self.mir_hir_id()).kind
316+
else {
316317
bug!("Closure is not defined by a closure expr");
317318
};
318319
let region_name = self.synthesize_region_name();
@@ -336,7 +337,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
336337
Some(RegionName {
337338
name: region_name,
338339
source: RegionNameSource::SynthesizedFreeEnvRegion(
339-
args_span,
340+
fn_decl_span,
340341
note.to_string(),
341342
),
342343
})
@@ -683,16 +684,16 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
683684

684685
let (return_span, mir_description, hir_ty) = match hir.get(mir_hir_id) {
685686
hir::Node::Expr(hir::Expr {
686-
kind: hir::ExprKind::Closure(_, return_ty, body_id, span, _),
687+
kind: hir::ExprKind::Closure { fn_decl, body, fn_decl_span, .. },
687688
..
688689
}) => {
689-
let (mut span, mut hir_ty) = match return_ty.output {
690+
let (mut span, mut hir_ty) = match fn_decl.output {
690691
hir::FnRetTy::DefaultReturn(_) => {
691-
(tcx.sess.source_map().end_point(*span), None)
692+
(tcx.sess.source_map().end_point(*fn_decl_span), None)
692693
}
693-
hir::FnRetTy::Return(hir_ty) => (return_ty.output.span(), Some(hir_ty)),
694+
hir::FnRetTy::Return(hir_ty) => (fn_decl.output.span(), Some(hir_ty)),
694695
};
695-
let mir_description = match hir.body(*body_id).generator_kind {
696+
let mir_description = match hir.body(*body).generator_kind {
696697
Some(hir::GeneratorKind::Async(gen)) => match gen {
697698
hir::AsyncGeneratorKind::Block => " of async block",
698699
hir::AsyncGeneratorKind::Closure => " of async closure",
@@ -822,8 +823,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
822823

823824
let yield_span = match tcx.hir().get(self.mir_hir_id()) {
824825
hir::Node::Expr(hir::Expr {
825-
kind: hir::ExprKind::Closure(_, _, _, span, _), ..
826-
}) => (tcx.sess.source_map().end_point(*span)),
826+
kind: hir::ExprKind::Closure { fn_decl_span, .. },
827+
..
828+
}) => (tcx.sess.source_map().end_point(*fn_decl_span)),
827829
_ => self.body.span,
828830
};
829831

compiler/rustc_feature/src/builtin_attrs.rs

-5
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
489489
// ==========================================================================
490490

491491
ungated!(feature, CrateLevel, template!(List: "name1, name2, ..."), DuplicatesOk),
492-
// FIXME(jhpratt) remove this eventually
493-
ungated!(
494-
rustc_deprecated, Normal,
495-
template!(List: r#"since = "version", note = "...""#), ErrorFollowing
496-
),
497492
// DuplicatesOk since it has its own validation
498493
ungated!(
499494
stable, Normal, template!(List: r#"feature = "name", since = "version""#), DuplicatesOk,

compiler/rustc_hir/src/hir.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ impl Expr<'_> {
16521652
ExprKind::Let(..) => ExprPrecedence::Let,
16531653
ExprKind::Loop(..) => ExprPrecedence::Loop,
16541654
ExprKind::Match(..) => ExprPrecedence::Match,
1655-
ExprKind::Closure(..) => ExprPrecedence::Closure,
1655+
ExprKind::Closure { .. } => ExprPrecedence::Closure,
16561656
ExprKind::Block(..) => ExprPrecedence::Block,
16571657
ExprKind::Assign(..) => ExprPrecedence::Assign,
16581658
ExprKind::AssignOp(..) => ExprPrecedence::AssignOp,
@@ -1712,7 +1712,7 @@ impl Expr<'_> {
17121712
| ExprKind::Tup(..)
17131713
| ExprKind::If(..)
17141714
| ExprKind::Match(..)
1715-
| ExprKind::Closure(..)
1715+
| ExprKind::Closure { .. }
17161716
| ExprKind::Block(..)
17171717
| ExprKind::Repeat(..)
17181718
| ExprKind::Array(..)
@@ -1795,7 +1795,7 @@ impl Expr<'_> {
17951795
| ExprKind::Match(..)
17961796
| ExprKind::MethodCall(..)
17971797
| ExprKind::Call(..)
1798-
| ExprKind::Closure(..)
1798+
| ExprKind::Closure { .. }
17991799
| ExprKind::Block(..)
18001800
| ExprKind::Repeat(..)
18011801
| ExprKind::Break(..)
@@ -1930,7 +1930,13 @@ pub enum ExprKind<'hir> {
19301930
///
19311931
/// This may also be a generator literal or an `async block` as indicated by the
19321932
/// `Option<Movability>`.
1933-
Closure(CaptureBy, &'hir FnDecl<'hir>, BodyId, Span, Option<Movability>),
1933+
Closure {
1934+
capture_clause: CaptureBy,
1935+
fn_decl: &'hir FnDecl<'hir>,
1936+
body: BodyId,
1937+
fn_decl_span: Span,
1938+
movability: Option<Movability>,
1939+
},
19341940
/// A block (e.g., `'label: { ... }`).
19351941
Block(&'hir Block<'hir>, Option<Label>),
19361942

@@ -3456,7 +3462,7 @@ impl<'hir> Node<'hir> {
34563462
_ => None,
34573463
},
34583464
Node::Expr(e) => match e.kind {
3459-
ExprKind::Closure(..) => Some(FnKind::Closure),
3465+
ExprKind::Closure { .. } => Some(FnKind::Closure),
34603466
_ => None,
34613467
},
34623468
_ => None,

compiler/rustc_hir/src/intravisit.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1168,14 +1168,13 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11681168
visitor.visit_expr(subexpression);
11691169
walk_list!(visitor, visit_arm, arms);
11701170
}
1171-
ExprKind::Closure(_, ref function_declaration, body, _fn_decl_span, _gen) => visitor
1172-
.visit_fn(
1173-
FnKind::Closure,
1174-
function_declaration,
1175-
body,
1176-
expression.span,
1177-
expression.hir_id,
1178-
),
1171+
ExprKind::Closure {
1172+
ref fn_decl,
1173+
body,
1174+
capture_clause: _,
1175+
fn_decl_span: _,
1176+
movability: _,
1177+
} => visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, expression.hir_id),
11791178
ExprKind::Block(ref block, ref opt_label) => {
11801179
walk_list!(visitor, visit_label, opt_label);
11811180
visitor.visit_block(block);

compiler/rustc_hir_pretty/src/lib.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,9 @@ impl<'a> State<'a> {
10781078
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
10791079
fn cond_needs_par(expr: &hir::Expr<'_>) -> bool {
10801080
match expr.kind {
1081-
hir::ExprKind::Break(..) | hir::ExprKind::Closure(..) | hir::ExprKind::Ret(..) => true,
1081+
hir::ExprKind::Break(..) | hir::ExprKind::Closure { .. } | hir::ExprKind::Ret(..) => {
1082+
true
1083+
}
10821084
_ => contains_exterior_struct_lit(expr),
10831085
}
10841086
}
@@ -1455,10 +1457,16 @@ impl<'a> State<'a> {
14551457
}
14561458
self.bclose(expr.span);
14571459
}
1458-
hir::ExprKind::Closure(capture_clause, ref decl, body, _fn_decl_span, _gen) => {
1460+
hir::ExprKind::Closure {
1461+
capture_clause,
1462+
ref fn_decl,
1463+
body,
1464+
fn_decl_span: _,
1465+
movability: _,
1466+
} => {
14591467
self.print_capture_clause(capture_clause);
14601468

1461-
self.print_closure_params(&decl, body);
1469+
self.print_closure_params(&fn_decl, body);
14621470
self.space();
14631471

14641472
// This is a bare expression.

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -988,22 +988,24 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
988988
}
989989

990990
if let Some(node_ty) = self.opt_node_type(expr.hir_id) {
991-
if let (&ExprKind::Closure(_, decl, body_id, span, _), ty::Closure(_, substs)) =
992-
(&expr.kind, node_ty.kind())
991+
if let (
992+
&ExprKind::Closure { fn_decl, body, fn_decl_span, .. },
993+
ty::Closure(_, substs),
994+
) = (&expr.kind, node_ty.kind())
993995
{
994996
let output = substs.as_closure().sig().output().skip_binder();
995997
if self.generic_arg_contains_target(output.into()) {
996-
let body = self.infcx.tcx.hir().body(body_id);
998+
let body = self.infcx.tcx.hir().body(body);
997999
let should_wrap_expr = if matches!(body.value.kind, ExprKind::Block(..)) {
9981000
None
9991001
} else {
10001002
Some(body.value.span.shrink_to_hi())
10011003
};
10021004
self.update_infer_source(InferSource {
1003-
span,
1005+
span: fn_decl_span,
10041006
kind: InferSourceKind::ClosureReturn {
10051007
ty: output,
1006-
data: &decl.output,
1008+
data: &fn_decl.output,
10071009
should_wrap_expr,
10081010
},
10091011
})

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn find_param_with_region<'tcx>(
5555

5656
// Don't perform this on closures
5757
match hir.get(hir_id) {
58-
hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => {
58+
hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => {
5959
return None;
6060
}
6161
_ => {}

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20272027
}
20282028

20292029
fn encode_info_for_expr(&mut self, expr: &hir::Expr<'_>) {
2030-
if let hir::ExprKind::Closure(..) = expr.kind {
2030+
if let hir::ExprKind::Closure { .. } = expr.kind {
20312031
self.encode_info_for_closure(expr.hir_id);
20322032
}
20332033
}

0 commit comments

Comments
 (0)