1
Fork 0

Add captures flag to capture or not while lowering

This commit is contained in:
Santiago Pastorino 2022-07-20 12:58:48 -03:00
parent b14c9571fa
commit 0f11a0cd24
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
7 changed files with 209 additions and 109 deletions

View file

@ -69,6 +69,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ParamMode::Optional,
ParenthesizedGenericArgs::Err,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
));
let args = self.lower_exprs(args);
hir::ExprKind::MethodCall(hir_seg, args, self.lower_span(span))
@ -89,14 +90,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ExprKind::Cast(ref expr, ref ty) => {
let expr = self.lower_expr(expr);
let ty =
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
let ty = self.lower_ty(
ty,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
);
hir::ExprKind::Cast(expr, ty)
}
ExprKind::Type(ref expr, ref ty) => {
let expr = self.lower_expr(expr);
let ty =
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
let ty = self.lower_ty(
ty,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
);
hir::ExprKind::Type(expr, ty)
}
ExprKind::AddrOf(k, m, ref ohs) => {
@ -226,6 +233,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
hir::ExprKind::Path(qpath)
}
@ -264,6 +272,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&se.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
)),
self.arena
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
@ -561,9 +570,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
) -> hir::ExprKind<'hir> {
let output = match ret_ty {
Some(ty) => hir::FnRetTy::Return(
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)),
),
Some(ty) => hir::FnRetTy::Return(self.lower_ty(
&ty,
ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock),
true,
)),
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
};
@ -1167,6 +1178,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
// Destructure like a tuple struct.
let tuple_struct_pat =
@ -1183,6 +1195,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
// Destructure like a unit struct.
let unit_struct_pat = hir::PatKind::Path(qpath);
@ -1207,6 +1220,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&se.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
let fields_omitted = match &se.rest {
StructRest::Base(e) => {