1
Fork 0

Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011

Make `ExprKind::Closure` a struct variant.

Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`.

r? ``@Aaron1011``
This commit is contained in:
Yuki Okushi 2022-06-15 19:37:14 +09:00 committed by GitHub
commit 87e373e82f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
75 changed files with 251 additions and 216 deletions

View file

@ -1084,11 +1084,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let hir = self.tcx.hir();
Some(match node {
Node::Expr(&hir::Expr {
kind: hir::ExprKind::Closure(_, ref _decl, id, span, _),
kind: hir::ExprKind::Closure { body, fn_decl_span, .. },
..
}) => (
sm.guess_head_span(span),
hir.body(id)
sm.guess_head_span(fn_decl_span),
hir.body(body)
.params
.iter()
.map(|arg| {

View file

@ -103,10 +103,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
})
}),
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_is_move, _, body_id, _, gen_movability),
kind: hir::ExprKind::Closure { body, movability, .. },
..
}) => self.describe_generator(*body_id).or_else(|| {
Some(if gen_movability.is_some() { "an async closure" } else { "a closure" })
}) => self.describe_generator(*body).or_else(|| {
Some(if movability.is_some() { "an async closure" } else { "a closure" })
}),
hir::Node::Expr(hir::Expr { .. }) => {
let parent_hid = hir.get_parent_node(hir_id);

View file

@ -785,14 +785,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// Get the name of the callable and the arguments to be used in the suggestion.
let (snippet, sugg) = match hir.get_if_local(def_id) {
Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_, decl, _, span, ..),
kind: hir::ExprKind::Closure { fn_decl, fn_decl_span, .. },
..
})) => {
err.span_label(*span, "consider calling this closure");
err.span_label(*fn_decl_span, "consider calling this closure");
let Some(name) = self.get_closure_name(def_id, err, &msg) else {
return false;
};
let args = decl.inputs.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
let args = fn_decl.inputs.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
let sugg = format!("({})", args);
(format!("{}{}", name, sugg), sugg)
}