Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c89bff2

Browse files
authored
Rollup merge of rust-lang#104199 - SarthakSingh31:issue-97417-1, r=cjgillot
Keep track of the start of the argument block of a closure This removes a call to `tcx.sess.source_map()` from [compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs](https://github.com/rust-lang/rust/compare/master...SarthakSingh31:issue-97417-1?expand=1#diff-8406bbc0d0b43d84c91b1933305df896ecdba0d1f9269e6744f13d87a2ab268a) as required by rust-lang#97417. VsCode automatically applied `rustfmt` to the files I edited under `src/tools`. I can undo that if its a problem. r? `@cjgillot`
2 parents 4bb1575 + 8f705e2 commit c89bff2

File tree

15 files changed

+53
-29
lines changed

15 files changed

+53
-29
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,8 +1312,10 @@ pub struct Closure {
13121312
pub movability: Movability,
13131313
pub fn_decl: P<FnDecl>,
13141314
pub body: P<Expr>,
1315-
/// The span of the argument block `|...|`.
1315+
/// The span of the declaration block: 'move |...| -> ...'
13161316
pub fn_decl_span: Span,
1317+
/// The span of the argument block `|...|`
1318+
pub fn_arg_span: Span,
13171319
}
13181320

13191321
/// Limit types of a range (inclusive or exclusive)

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
13681368
fn_decl,
13691369
body,
13701370
fn_decl_span,
1371+
fn_arg_span: _,
13711372
}) => {
13721373
vis.visit_closure_binder(binder);
13731374
vis.visit_asyncness(asyncness);

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
840840
fn_decl,
841841
body,
842842
fn_decl_span: _,
843+
fn_arg_span: _,
843844
}) => {
844845
visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), expression.span, expression.id)
845846
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
176176
fn_decl,
177177
body,
178178
fn_decl_span,
179+
fn_arg_span,
179180
}) => {
180181
if let Async::Yes { closure_id, .. } = asyncness {
181182
self.lower_expr_async_closure(
@@ -186,6 +187,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
186187
fn_decl,
187188
body,
188189
*fn_decl_span,
190+
*fn_arg_span,
189191
)
190192
} else {
191193
self.lower_expr_closure(
@@ -196,6 +198,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
196198
fn_decl,
197199
body,
198200
*fn_decl_span,
201+
*fn_arg_span,
199202
)
200203
}
201204
}
@@ -642,6 +645,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
642645
fn_decl,
643646
body,
644647
fn_decl_span: self.lower_span(span),
648+
fn_arg_span: None,
645649
movability: Some(hir::Movability::Static),
646650
});
647651

@@ -898,6 +902,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
898902
decl: &FnDecl,
899903
body: &Expr,
900904
fn_decl_span: Span,
905+
fn_arg_span: Span,
901906
) -> hir::ExprKind<'hir> {
902907
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
903908

@@ -928,6 +933,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
928933
fn_decl,
929934
body: body_id,
930935
fn_decl_span: self.lower_span(fn_decl_span),
936+
fn_arg_span: Some(self.lower_span(fn_arg_span)),
931937
movability: generator_option,
932938
});
933939

@@ -984,6 +990,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
984990
decl: &FnDecl,
985991
body: &Expr,
986992
fn_decl_span: Span,
993+
fn_arg_span: Span,
987994
) -> hir::ExprKind<'hir> {
988995
if let &ClosureBinder::For { span, .. } = binder {
989996
self.tcx.sess.emit_err(NotSupportedForLifetimeBinderAsyncClosure { span });
@@ -1038,6 +1045,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10381045
fn_decl,
10391046
body,
10401047
fn_decl_span: self.lower_span(fn_decl_span),
1048+
fn_arg_span: Some(self.lower_span(fn_arg_span)),
10411049
movability: None,
10421050
});
10431051
hir::ExprKind::Closure(c)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ impl<'a> State<'a> {
402402
fn_decl,
403403
body,
404404
fn_decl_span: _,
405+
fn_arg_span: _,
405406
}) => {
406407
self.print_closure_binder(binder);
407408
self.print_movability(*movability);

compiler/rustc_expand/src/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ impl<'a> ExtCtxt<'a> {
539539
fn_decl,
540540
body,
541541
fn_decl_span: span,
542+
// FIXME(SarthakSingh31): This points to the start of the declaration block and
543+
// not the span of the argument block.
544+
fn_arg_span: span,
542545
})),
543546
)
544547
}

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,10 @@ pub struct Closure<'hir> {
943943
pub bound_generic_params: &'hir [GenericParam<'hir>],
944944
pub fn_decl: &'hir FnDecl<'hir>,
945945
pub body: BodyId,
946+
/// The span of the declaration block: 'move |...| -> ...'
946947
pub fn_decl_span: Span,
948+
/// The span of the argument block `|...|`
949+
pub fn_arg_span: Option<Span>,
947950
pub movability: Option<Movability>,
948951
}
949952

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
740740
body,
741741
capture_clause: _,
742742
fn_decl_span: _,
743+
fn_arg_span: _,
743744
movability: _,
744745
}) => {
745746
walk_list!(visitor, visit_generic_param, bound_generic_params);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ impl<'a> State<'a> {
14801480
fn_decl,
14811481
body,
14821482
fn_decl_span: _,
1483+
fn_arg_span: _,
14831484
movability: _,
14841485
def_id: _,
14851486
}) => {

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
456456
.iter()
457457
.map(|ty| ArgKind::from_expected_ty(*ty, None))
458458
.collect();
459-
let (closure_span, found_args) = match self.get_fn_like_arguments(expr_map_node) {
460-
Some((sp, args)) => (Some(sp), args),
461-
None => (None, Vec::new()),
462-
};
459+
let (closure_span, closure_arg_span, found_args) =
460+
match self.get_fn_like_arguments(expr_map_node) {
461+
Some((sp, arg_sp, args)) => (Some(sp), arg_sp, args),
462+
None => (None, None, Vec::new()),
463+
};
463464
let expected_span =
464465
expected_sig.cause_span.unwrap_or_else(|| self.tcx.def_span(expr_def_id));
465466
self.report_arg_count_mismatch(
@@ -468,6 +469,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
468469
expected_args,
469470
found_args,
470471
true,
472+
closure_arg_span,
471473
)
472474
.emit();
473475

0 commit comments

Comments
 (0)