Add captures flag to capture or not while lowering
This commit is contained in:
parent
b14c9571fa
commit
0f11a0cd24
7 changed files with 209 additions and 109 deletions
|
@ -234,6 +234,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
&sym.path,
|
&sym.path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
hir::InlineAsmOperand::SymStatic { path, def_id }
|
hir::InlineAsmOperand::SymStatic { path, def_id }
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -84,10 +84,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> {
|
fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> {
|
||||||
let ty = l
|
let ty = l.ty.as_ref().map(|t| {
|
||||||
.ty
|
self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable), true)
|
||||||
.as_ref()
|
});
|
||||||
.map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
|
|
||||||
let init = l.kind.init().map(|init| self.lower_expr(init));
|
let init = l.kind.init().map(|init| self.lower_expr(init));
|
||||||
let hir_id = self.lower_node_id(l.id);
|
let hir_id = self.lower_node_id(l.id);
|
||||||
let pat = self.lower_pat(&l.pat);
|
let pat = self.lower_pat(&l.pat);
|
||||||
|
|
|
@ -69,6 +69,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ParenthesizedGenericArgs::Err,
|
ParenthesizedGenericArgs::Err,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
));
|
));
|
||||||
let args = self.lower_exprs(args);
|
let args = self.lower_exprs(args);
|
||||||
hir::ExprKind::MethodCall(hir_seg, args, self.lower_span(span))
|
hir::ExprKind::MethodCall(hir_seg, args, self.lower_span(span))
|
||||||
|
@ -89,14 +90,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
}
|
}
|
||||||
ExprKind::Cast(ref expr, ref ty) => {
|
ExprKind::Cast(ref expr, ref ty) => {
|
||||||
let expr = self.lower_expr(expr);
|
let expr = self.lower_expr(expr);
|
||||||
let ty =
|
let ty = self.lower_ty(
|
||||||
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
ty,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
);
|
||||||
hir::ExprKind::Cast(expr, ty)
|
hir::ExprKind::Cast(expr, ty)
|
||||||
}
|
}
|
||||||
ExprKind::Type(ref expr, ref ty) => {
|
ExprKind::Type(ref expr, ref ty) => {
|
||||||
let expr = self.lower_expr(expr);
|
let expr = self.lower_expr(expr);
|
||||||
let ty =
|
let ty = self.lower_ty(
|
||||||
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
ty,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
);
|
||||||
hir::ExprKind::Type(expr, ty)
|
hir::ExprKind::Type(expr, ty)
|
||||||
}
|
}
|
||||||
ExprKind::AddrOf(k, m, ref ohs) => {
|
ExprKind::AddrOf(k, m, ref ohs) => {
|
||||||
|
@ -226,6 +233,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
path,
|
path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
hir::ExprKind::Path(qpath)
|
hir::ExprKind::Path(qpath)
|
||||||
}
|
}
|
||||||
|
@ -264,6 +272,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
&se.path,
|
&se.path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
)),
|
)),
|
||||||
self.arena
|
self.arena
|
||||||
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
|
.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>,
|
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
|
||||||
) -> hir::ExprKind<'hir> {
|
) -> hir::ExprKind<'hir> {
|
||||||
let output = match ret_ty {
|
let output = match ret_ty {
|
||||||
Some(ty) => hir::FnRetTy::Return(
|
Some(ty) => hir::FnRetTy::Return(self.lower_ty(
|
||||||
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)),
|
&ty,
|
||||||
),
|
ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock),
|
||||||
|
true,
|
||||||
|
)),
|
||||||
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
|
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1167,6 +1178,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
path,
|
path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
// Destructure like a tuple struct.
|
// Destructure like a tuple struct.
|
||||||
let tuple_struct_pat =
|
let tuple_struct_pat =
|
||||||
|
@ -1183,6 +1195,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
path,
|
path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
// Destructure like a unit struct.
|
// Destructure like a unit struct.
|
||||||
let unit_struct_pat = hir::PatKind::Path(qpath);
|
let unit_struct_pat = hir::PatKind::Path(qpath);
|
||||||
|
@ -1207,6 +1220,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
&se.path,
|
&se.path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
let fields_omitted = match &se.rest {
|
let fields_omitted = match &se.rest {
|
||||||
StructRest::Base(e) => {
|
StructRest::Base(e) => {
|
||||||
|
|
|
@ -308,7 +308,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
&generics,
|
&generics,
|
||||||
id,
|
id,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||||
|this| this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy),
|
|this| this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy, true),
|
||||||
);
|
);
|
||||||
hir::ItemKind::TyAlias(ty, generics)
|
hir::ItemKind::TyAlias(ty, generics)
|
||||||
}
|
}
|
||||||
|
@ -386,11 +386,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
this.lower_trait_ref(
|
this.lower_trait_ref(
|
||||||
trait_ref,
|
trait_ref,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let lowered_ty = this
|
let lowered_ty = this.lower_ty(
|
||||||
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
ty,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
(trait_ref, lowered_ty)
|
(trait_ref, lowered_ty)
|
||||||
});
|
});
|
||||||
|
@ -434,6 +438,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let bounds = this.lower_param_bounds(
|
let bounds = this.lower_param_bounds(
|
||||||
bounds,
|
bounds,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
let items = this.arena.alloc_from_iter(
|
let items = this.arena.alloc_from_iter(
|
||||||
items.iter().map(|item| this.lower_trait_item_ref(item)),
|
items.iter().map(|item| this.lower_trait_item_ref(item)),
|
||||||
|
@ -453,6 +458,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
this.lower_param_bounds(
|
this.lower_param_bounds(
|
||||||
bounds,
|
bounds,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -475,7 +481,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
span: Span,
|
span: Span,
|
||||||
body: Option<&Expr>,
|
body: Option<&Expr>,
|
||||||
) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
|
) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
|
||||||
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
|
||||||
(ty, self.lower_const_body(span, body))
|
(ty, self.lower_const_body(span, body))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -661,8 +667,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
|
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
|
||||||
}
|
}
|
||||||
ForeignItemKind::Static(ref t, m, _) => {
|
ForeignItemKind::Static(ref t, m, _) => {
|
||||||
let ty =
|
let ty = self.lower_ty(
|
||||||
self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
t,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
);
|
||||||
hir::ForeignItemKind::Static(ty, m)
|
hir::ForeignItemKind::Static(ty, m)
|
||||||
}
|
}
|
||||||
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
|
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
|
||||||
|
@ -731,10 +740,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
path,
|
path,
|
||||||
ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124)
|
ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124)
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
self.arena.alloc(t)
|
self.arena.alloc(t)
|
||||||
} else {
|
} else {
|
||||||
self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
|
self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true)
|
||||||
};
|
};
|
||||||
let hir_id = self.lower_node_id(f.id);
|
let hir_id = self.lower_node_id(f.id);
|
||||||
self.lower_attrs(hir_id, &f.attrs);
|
self.lower_attrs(hir_id, &f.attrs);
|
||||||
|
@ -757,7 +767,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
|
|
||||||
let (generics, kind, has_default) = match i.kind {
|
let (generics, kind, has_default) = match i.kind {
|
||||||
AssocItemKind::Const(_, ref ty, ref default) => {
|
AssocItemKind::Const(_, ref ty, ref default) => {
|
||||||
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
let ty =
|
||||||
|
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
|
||||||
let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
|
let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
|
||||||
(hir::Generics::empty(), hir::TraitItemKind::Const(ty, body), body.is_some())
|
(hir::Generics::empty(), hir::TraitItemKind::Const(ty, body), body.is_some())
|
||||||
}
|
}
|
||||||
|
@ -795,12 +806,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||||
|this| {
|
|this| {
|
||||||
let ty = ty.as_ref().map(|x| {
|
let ty = ty.as_ref().map(|x| {
|
||||||
this.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
|
this.lower_ty(
|
||||||
|
x,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
hir::TraitItemKind::Type(
|
hir::TraitItemKind::Type(
|
||||||
this.lower_param_bounds(
|
this.lower_param_bounds(
|
||||||
bounds,
|
bounds,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||||
|
true,
|
||||||
),
|
),
|
||||||
ty,
|
ty,
|
||||||
)
|
)
|
||||||
|
@ -853,7 +869,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
|
|
||||||
let (generics, kind) = match &i.kind {
|
let (generics, kind) = match &i.kind {
|
||||||
AssocItemKind::Const(_, ty, expr) => {
|
AssocItemKind::Const(_, ty, expr) => {
|
||||||
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
let ty =
|
||||||
|
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
|
||||||
(
|
(
|
||||||
hir::Generics::empty(),
|
hir::Generics::empty(),
|
||||||
hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())),
|
hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())),
|
||||||
|
@ -887,7 +904,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
hir::ImplItemKind::TyAlias(ty)
|
hir::ImplItemKind::TyAlias(ty)
|
||||||
}
|
}
|
||||||
Some(ty) => {
|
Some(ty) => {
|
||||||
let ty = this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy);
|
let ty = this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy, true);
|
||||||
hir::ImplItemKind::TyAlias(ty)
|
hir::ImplItemKind::TyAlias(ty)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1412,7 +1429,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let bounds = self.lower_param_bounds(bounds, itctx);
|
let bounds = self.lower_param_bounds(bounds, itctx, true);
|
||||||
|
|
||||||
let ident = self.lower_ident(ident);
|
let ident = self.lower_ident(ident);
|
||||||
let param_span = ident.span;
|
let param_span = ident.span;
|
||||||
|
@ -1458,7 +1475,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
panic!("Missing resolution for lifetime {:?} at {:?}", id, ident.span)
|
panic!("Missing resolution for lifetime {:?} at {:?}", id, ident.span)
|
||||||
});
|
});
|
||||||
let lt_id = self.next_node_id();
|
let lt_id = self.next_node_id();
|
||||||
let lifetime = self.new_named_lifetime_with_res(lt_id, ident_span, ident, res);
|
let lifetime =
|
||||||
|
self.new_named_lifetime_with_res(lt_id, ident_span, ident, res, true);
|
||||||
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||||
lifetime,
|
lifetime,
|
||||||
span,
|
span,
|
||||||
|
@ -1478,12 +1496,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
span,
|
span,
|
||||||
}) => hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
|
}) => hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
|
||||||
bound_generic_params: self.lower_generic_params(bound_generic_params),
|
bound_generic_params: self.lower_generic_params(bound_generic_params),
|
||||||
bounded_ty: self
|
bounded_ty: self.lower_ty(
|
||||||
.lower_ty(bounded_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
|
bounded_ty,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
),
|
||||||
bounds: self.arena.alloc_from_iter(bounds.iter().map(|bound| {
|
bounds: self.arena.alloc_from_iter(bounds.iter().map(|bound| {
|
||||||
self.lower_param_bound(
|
self.lower_param_bound(
|
||||||
bound,
|
bound,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
})),
|
})),
|
||||||
span: self.lower_span(span),
|
span: self.lower_span(span),
|
||||||
|
@ -1495,20 +1517,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
span,
|
span,
|
||||||
}) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
}) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||||
span: self.lower_span(span),
|
span: self.lower_span(span),
|
||||||
lifetime: self.lower_lifetime(lifetime),
|
lifetime: self.lower_lifetime(lifetime, true),
|
||||||
bounds: self.lower_param_bounds(
|
bounds: self.lower_param_bounds(
|
||||||
bounds,
|
bounds,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
|
||||||
|
true,
|
||||||
),
|
),
|
||||||
in_where_clause: true,
|
in_where_clause: true,
|
||||||
}),
|
}),
|
||||||
WherePredicate::EqPredicate(WhereEqPredicate { id, ref lhs_ty, ref rhs_ty, span }) => {
|
WherePredicate::EqPredicate(WhereEqPredicate { id, ref lhs_ty, ref rhs_ty, span }) => {
|
||||||
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
||||||
hir_id: self.lower_node_id(id),
|
hir_id: self.lower_node_id(id),
|
||||||
lhs_ty: self
|
lhs_ty: self.lower_ty(
|
||||||
.lower_ty(lhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
|
lhs_ty,
|
||||||
rhs_ty: self
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
.lower_ty(rhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
|
true,
|
||||||
|
),
|
||||||
|
rhs_ty: self.lower_ty(
|
||||||
|
rhs_ty,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
),
|
||||||
span: self.lower_span(span),
|
span: self.lower_span(span),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -957,7 +957,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let kind = match constraint.kind {
|
let kind = match constraint.kind {
|
||||||
AssocConstraintKind::Equality { ref term } => {
|
AssocConstraintKind::Equality { ref term } => {
|
||||||
let term = match term {
|
let term = match term {
|
||||||
Term::Ty(ref ty) => self.lower_ty(ty, itctx).into(),
|
Term::Ty(ref ty) => self.lower_ty(ty, itctx, true).into(),
|
||||||
Term::Const(ref c) => self.lower_anon_const(c).into(),
|
Term::Const(ref c) => self.lower_anon_const(c).into(),
|
||||||
};
|
};
|
||||||
hir::TypeBindingKind::Equality { term }
|
hir::TypeBindingKind::Equality { term }
|
||||||
|
@ -1022,6 +1022,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
tokens: None,
|
tokens: None,
|
||||||
},
|
},
|
||||||
itctx,
|
itctx,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
hir::TypeBindingKind::Equality { term: ty.into() }
|
hir::TypeBindingKind::Equality { term: ty.into() }
|
||||||
|
@ -1029,7 +1030,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
} else {
|
} else {
|
||||||
// Desugar `AssocTy: Bounds` into a type binding where the
|
// Desugar `AssocTy: Bounds` into a type binding where the
|
||||||
// later desugars into a trait predicate.
|
// later desugars into a trait predicate.
|
||||||
let bounds = self.lower_param_bounds(bounds, itctx);
|
let bounds = self.lower_param_bounds(bounds, itctx, true);
|
||||||
|
|
||||||
hir::TypeBindingKind::Constraint { bounds }
|
hir::TypeBindingKind::Constraint { bounds }
|
||||||
}
|
}
|
||||||
|
@ -1088,7 +1089,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
) -> hir::GenericArg<'hir> {
|
) -> hir::GenericArg<'hir> {
|
||||||
match arg {
|
match arg {
|
||||||
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)),
|
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<, true)),
|
||||||
ast::GenericArg::Type(ty) => {
|
ast::GenericArg::Type(ty) => {
|
||||||
match ty.kind {
|
match ty.kind {
|
||||||
TyKind::Infer if self.tcx.features().generic_arg_infer => {
|
TyKind::Infer if self.tcx.features().generic_arg_infer => {
|
||||||
|
@ -1137,7 +1138,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
GenericArg::Type(self.lower_ty_direct(&ty, itctx))
|
GenericArg::Type(self.lower_ty_direct(&ty, itctx, true))
|
||||||
}
|
}
|
||||||
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
|
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
|
||||||
value: self.lower_anon_const(&ct),
|
value: self.lower_anon_const(&ct),
|
||||||
|
@ -1147,8 +1148,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
|
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext, captures: bool) -> &'hir hir::Ty<'hir> {
|
||||||
self.arena.alloc(self.lower_ty_direct(t, itctx))
|
self.arena.alloc(self.lower_ty_direct(t, itctx, captures))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_path_ty(
|
fn lower_path_ty(
|
||||||
|
@ -1158,6 +1159,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
path: &Path,
|
path: &Path,
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
) -> hir::Ty<'hir> {
|
) -> hir::Ty<'hir> {
|
||||||
// Check whether we should interpret this as a bare trait object.
|
// Check whether we should interpret this as a bare trait object.
|
||||||
// This check mirrors the one in late resolution. We only introduce this special case in
|
// This check mirrors the one in late resolution. We only introduce this special case in
|
||||||
|
@ -1177,6 +1179,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
span: t.span
|
span: t.span
|
||||||
},
|
},
|
||||||
itctx,
|
itctx,
|
||||||
|
captures,
|
||||||
);
|
);
|
||||||
let bounds = this.arena.alloc_from_iter([bound]);
|
let bounds = this.arena.alloc_from_iter([bound]);
|
||||||
let lifetime_bound = this.elided_dyn_bound(t.span);
|
let lifetime_bound = this.elided_dyn_bound(t.span);
|
||||||
|
@ -1187,7 +1190,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = self.lower_node_id(t.id);
|
let id = self.lower_node_id(t.id);
|
||||||
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx);
|
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx, true);
|
||||||
self.ty_path(id, t.span, qpath)
|
self.ty_path(id, t.span, qpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1199,11 +1202,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.ty(span, hir::TyKind::Tup(tys))
|
self.ty(span, hir::TyKind::Tup(tys))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
|
fn lower_ty_direct(
|
||||||
|
&mut self,
|
||||||
|
t: &Ty,
|
||||||
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
|
) -> hir::Ty<'hir> {
|
||||||
let kind = match t.kind {
|
let kind = match t.kind {
|
||||||
TyKind::Infer => hir::TyKind::Infer,
|
TyKind::Infer => hir::TyKind::Infer,
|
||||||
TyKind::Err => hir::TyKind::Err,
|
TyKind::Err => hir::TyKind::Err,
|
||||||
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
|
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx, captures)),
|
||||||
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
|
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
|
||||||
TyKind::Rptr(ref region, ref mt) => {
|
TyKind::Rptr(ref region, ref mt) => {
|
||||||
let region = region.unwrap_or_else(|| {
|
let region = region.unwrap_or_else(|| {
|
||||||
|
@ -1218,7 +1226,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
|
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
|
||||||
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
|
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
|
||||||
});
|
});
|
||||||
let lifetime = self.lower_lifetime(®ion);
|
let lifetime = self.lower_lifetime(®ion, captures);
|
||||||
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
|
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
|
||||||
}
|
}
|
||||||
TyKind::BareFn(ref f) => {
|
TyKind::BareFn(ref f) => {
|
||||||
|
@ -1233,14 +1241,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
TyKind::Never => hir::TyKind::Never,
|
TyKind::Never => hir::TyKind::Never,
|
||||||
TyKind::Tup(ref tys) => hir::TyKind::Tup(
|
TyKind::Tup(ref tys) => {
|
||||||
self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty_direct(ty, itctx))),
|
hir::TyKind::Tup(self.arena.alloc_from_iter(
|
||||||
),
|
tys.iter().map(|ty| self.lower_ty_direct(ty, itctx, captures)),
|
||||||
|
))
|
||||||
|
}
|
||||||
TyKind::Paren(ref ty) => {
|
TyKind::Paren(ref ty) => {
|
||||||
return self.lower_ty_direct(ty, itctx);
|
return self.lower_ty_direct(ty, itctx, captures);
|
||||||
}
|
}
|
||||||
TyKind::Path(ref qself, ref path) => {
|
TyKind::Path(ref qself, ref path) => {
|
||||||
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
|
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx, captures);
|
||||||
}
|
}
|
||||||
TyKind::ImplicitSelf => {
|
TyKind::ImplicitSelf => {
|
||||||
let res = self.expect_full_res(t.id);
|
let res = self.expect_full_res(t.id);
|
||||||
|
@ -1256,9 +1266,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
TyKind::Array(ref ty, ref length) => {
|
TyKind::Array(ref ty, ref length) => hir::TyKind::Array(
|
||||||
hir::TyKind::Array(self.lower_ty(ty, itctx), self.lower_array_length(length))
|
self.lower_ty(ty, itctx, captures),
|
||||||
}
|
self.lower_array_length(length),
|
||||||
|
),
|
||||||
TyKind::Typeof(ref expr) => hir::TyKind::Typeof(self.lower_anon_const(expr)),
|
TyKind::Typeof(ref expr) => hir::TyKind::Typeof(self.lower_anon_const(expr)),
|
||||||
TyKind::TraitObject(ref bounds, kind) => {
|
TyKind::TraitObject(ref bounds, kind) => {
|
||||||
let mut lifetime_bound = None;
|
let mut lifetime_bound = None;
|
||||||
|
@ -1269,7 +1280,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
GenericBound::Trait(
|
GenericBound::Trait(
|
||||||
ref ty,
|
ref ty,
|
||||||
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
|
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
|
||||||
) => Some(this.lower_poly_trait_ref(ty, itctx)),
|
) => Some(this.lower_poly_trait_ref(ty, itctx, captures)),
|
||||||
// `~const ?Bound` will cause an error during AST validation
|
// `~const ?Bound` will cause an error during AST validation
|
||||||
// anyways, so treat it like `?Bound` as compilation proceeds.
|
// anyways, so treat it like `?Bound` as compilation proceeds.
|
||||||
GenericBound::Trait(
|
GenericBound::Trait(
|
||||||
|
@ -1278,7 +1289,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
) => None,
|
) => None,
|
||||||
GenericBound::Outlives(ref lifetime) => {
|
GenericBound::Outlives(ref lifetime) => {
|
||||||
if lifetime_bound.is_none() {
|
if lifetime_bound.is_none() {
|
||||||
lifetime_bound = Some(this.lower_lifetime(lifetime));
|
lifetime_bound = Some(this.lower_lifetime(lifetime, true));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -1295,7 +1306,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
match itctx {
|
match itctx {
|
||||||
ImplTraitContext::ReturnPositionOpaqueTy { origin } => self
|
ImplTraitContext::ReturnPositionOpaqueTy { origin } => self
|
||||||
.lower_opaque_impl_trait(span, origin, def_node_id, |this| {
|
.lower_opaque_impl_trait(span, origin, def_node_id, |this| {
|
||||||
this.lower_param_bounds(bounds, itctx)
|
this.lower_param_bounds(bounds, itctx, true)
|
||||||
}),
|
}),
|
||||||
ImplTraitContext::TypeAliasesOpaqueTy => {
|
ImplTraitContext::TypeAliasesOpaqueTy => {
|
||||||
let nested_itctx = ImplTraitContext::TypeAliasesOpaqueTy;
|
let nested_itctx = ImplTraitContext::TypeAliasesOpaqueTy;
|
||||||
|
@ -1303,7 +1314,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
span,
|
span,
|
||||||
hir::OpaqueTyOrigin::TyAlias,
|
hir::OpaqueTyOrigin::TyAlias,
|
||||||
def_node_id,
|
def_node_id,
|
||||||
|this| this.lower_param_bounds(bounds, nested_itctx),
|
|this| this.lower_param_bounds(bounds, nested_itctx, true),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ImplTraitContext::Universal => {
|
ImplTraitContext::Universal => {
|
||||||
|
@ -1417,7 +1428,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|(_, (span, _, p_name, res))| {
|
|(_, (span, _, p_name, res))| {
|
||||||
let id = self.next_node_id();
|
let id = self.next_node_id();
|
||||||
let ident = Ident::new(p_name.ident().name, span);
|
let ident = Ident::new(p_name.ident().name, span);
|
||||||
let l = self.new_named_lifetime_with_res(id, span, ident, res);
|
let l = self.new_named_lifetime_with_res(id, span, ident, res, true);
|
||||||
hir::GenericArg::Lifetime(l)
|
hir::GenericArg::Lifetime(l)
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
@ -1495,7 +1506,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
|
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
|
||||||
if fn_node_id.is_some() {
|
if fn_node_id.is_some() {
|
||||||
self.lower_ty_direct(¶m.ty, ImplTraitContext::Universal)
|
self.lower_ty_direct(¶m.ty, ImplTraitContext::Universal, true)
|
||||||
} else {
|
} else {
|
||||||
self.lower_ty_direct(
|
self.lower_ty_direct(
|
||||||
¶m.ty,
|
¶m.ty,
|
||||||
|
@ -1509,6 +1520,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
FnDeclKind::Trait => ImplTraitPosition::TraitParam,
|
FnDeclKind::Trait => ImplTraitPosition::TraitParam,
|
||||||
FnDeclKind::Impl => ImplTraitPosition::ImplParam,
|
FnDeclKind::Impl => ImplTraitPosition::ImplParam,
|
||||||
}),
|
}),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -1540,7 +1552,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
|
FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
hir::FnRetTy::Return(self.lower_ty(ty, context))
|
hir::FnRetTy::Return(self.lower_ty(ty, context, true))
|
||||||
}
|
}
|
||||||
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
|
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
|
||||||
}
|
}
|
||||||
|
@ -1746,7 +1758,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.arena.alloc_from_iter(captures.into_iter().map(|(_, (span, _, p_name, res))| {
|
self.arena.alloc_from_iter(captures.into_iter().map(|(_, (span, _, p_name, res))| {
|
||||||
let id = self.next_node_id();
|
let id = self.next_node_id();
|
||||||
let ident = Ident::new(p_name.ident().name, span);
|
let ident = Ident::new(p_name.ident().name, span);
|
||||||
let l = self.new_named_lifetime_with_res(id, span, ident, res);
|
let l = self.new_named_lifetime_with_res(id, span, ident, res, true);
|
||||||
hir::GenericArg::Lifetime(l)
|
hir::GenericArg::Lifetime(l)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -1776,7 +1788,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let context = ImplTraitContext::ReturnPositionOpaqueTy {
|
let context = ImplTraitContext::ReturnPositionOpaqueTy {
|
||||||
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
|
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
|
||||||
};
|
};
|
||||||
self.lower_ty(ty, context)
|
self.lower_ty(ty, context, true)
|
||||||
}
|
}
|
||||||
FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
|
FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
|
||||||
};
|
};
|
||||||
|
@ -1803,23 +1815,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
&mut self,
|
&mut self,
|
||||||
tpb: &GenericBound,
|
tpb: &GenericBound,
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
) -> hir::GenericBound<'hir> {
|
) -> hir::GenericBound<'hir> {
|
||||||
match tpb {
|
match tpb {
|
||||||
GenericBound::Trait(p, modifier) => hir::GenericBound::Trait(
|
GenericBound::Trait(p, modifier) => hir::GenericBound::Trait(
|
||||||
self.lower_poly_trait_ref(p, itctx),
|
self.lower_poly_trait_ref(p, itctx, captures),
|
||||||
self.lower_trait_bound_modifier(*modifier),
|
self.lower_trait_bound_modifier(*modifier),
|
||||||
),
|
),
|
||||||
GenericBound::Outlives(lifetime) => {
|
GenericBound::Outlives(lifetime) => {
|
||||||
hir::GenericBound::Outlives(self.lower_lifetime(lifetime))
|
hir::GenericBound::Outlives(self.lower_lifetime(lifetime, captures))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
|
fn lower_lifetime(&mut self, l: &Lifetime, captures: bool) -> hir::Lifetime {
|
||||||
let span = self.lower_span(l.ident.span);
|
let span = self.lower_span(l.ident.span);
|
||||||
let ident = self.lower_ident(l.ident);
|
let ident = self.lower_ident(l.ident);
|
||||||
let res = self.resolver.get_lifetime_res(l.id).unwrap_or(LifetimeRes::Error);
|
let res = self.resolver.get_lifetime_res(l.id).unwrap_or(LifetimeRes::Error);
|
||||||
self.new_named_lifetime_with_res(l.id, span, ident, res)
|
self.new_named_lifetime_with_res(l.id, span, ident, res, captures)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip(self))]
|
#[tracing::instrument(level = "debug", skip(self))]
|
||||||
|
@ -1829,11 +1842,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
span: Span,
|
span: Span,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
res: LifetimeRes,
|
res: LifetimeRes,
|
||||||
|
captures: bool,
|
||||||
) -> hir::Lifetime {
|
) -> hir::Lifetime {
|
||||||
debug!(?self.captured_lifetimes);
|
debug!(?self.captured_lifetimes);
|
||||||
let name = match res {
|
let name = match res {
|
||||||
LifetimeRes::Param { mut param, binder } => {
|
LifetimeRes::Param { mut param, binder } => {
|
||||||
let p_name = ParamName::Plain(ident);
|
let p_name = ParamName::Plain(ident);
|
||||||
|
if captures {
|
||||||
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
||||||
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
||||||
match captured_lifetimes.captures.entry(param) {
|
match captured_lifetimes.captures.entry(param) {
|
||||||
|
@ -1854,11 +1869,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|
|
||||||
self.captured_lifetimes = Some(captured_lifetimes);
|
self.captured_lifetimes = Some(captured_lifetimes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
hir::LifetimeName::Param(param, p_name)
|
hir::LifetimeName::Param(param, p_name)
|
||||||
}
|
}
|
||||||
LifetimeRes::Fresh { param, binder } => {
|
LifetimeRes::Fresh { param, binder } => {
|
||||||
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
|
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
|
||||||
let mut param = self.local_def_id(param);
|
let mut param = self.local_def_id(param);
|
||||||
|
if captures {
|
||||||
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
||||||
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
||||||
match captured_lifetimes.captures.entry(param) {
|
match captured_lifetimes.captures.entry(param) {
|
||||||
|
@ -1879,6 +1896,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|
|
||||||
self.captured_lifetimes = Some(captured_lifetimes);
|
self.captured_lifetimes = Some(captured_lifetimes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
hir::LifetimeName::Param(param, ParamName::Fresh)
|
hir::LifetimeName::Param(param, ParamName::Fresh)
|
||||||
}
|
}
|
||||||
LifetimeRes::Infer => hir::LifetimeName::Infer,
|
LifetimeRes::Infer => hir::LifetimeName::Infer,
|
||||||
|
@ -1941,7 +1959,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
GenericParamKind::Type { ref default, .. } => {
|
GenericParamKind::Type { ref default, .. } => {
|
||||||
let kind = hir::GenericParamKind::Type {
|
let kind = hir::GenericParamKind::Type {
|
||||||
default: default.as_ref().map(|x| {
|
default: default.as_ref().map(|x| {
|
||||||
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
|
self.lower_ty(
|
||||||
|
x,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
|
||||||
|
true,
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
synthetic: false,
|
synthetic: false,
|
||||||
};
|
};
|
||||||
|
@ -1949,7 +1971,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
|
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
|
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
|
||||||
let ty = self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
|
let ty =
|
||||||
|
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
|
||||||
let default = default.as_ref().map(|def| self.lower_anon_const(def));
|
let default = default.as_ref().map(|def| self.lower_anon_const(def));
|
||||||
(
|
(
|
||||||
hir::ParamName::Plain(self.lower_ident(param.ident)),
|
hir::ParamName::Plain(self.lower_ident(param.ident)),
|
||||||
|
@ -1959,8 +1982,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext) -> hir::TraitRef<'hir> {
|
fn lower_trait_ref(
|
||||||
let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) {
|
&mut self,
|
||||||
|
p: &TraitRef,
|
||||||
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
|
) -> hir::TraitRef<'hir> {
|
||||||
|
let path = match self.lower_qpath(
|
||||||
|
p.ref_id,
|
||||||
|
&None,
|
||||||
|
&p.path,
|
||||||
|
ParamMode::Explicit,
|
||||||
|
itctx,
|
||||||
|
captures,
|
||||||
|
) {
|
||||||
hir::QPath::Resolved(None, path) => path,
|
hir::QPath::Resolved(None, path) => path,
|
||||||
qpath => panic!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
|
qpath => panic!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
|
||||||
};
|
};
|
||||||
|
@ -1972,35 +2007,38 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
&mut self,
|
&mut self,
|
||||||
p: &PolyTraitRef,
|
p: &PolyTraitRef,
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
) -> hir::PolyTraitRef<'hir> {
|
) -> hir::PolyTraitRef<'hir> {
|
||||||
self.with_lifetime_binder(
|
self.with_lifetime_binder(
|
||||||
p.trait_ref.ref_id,
|
p.trait_ref.ref_id,
|
||||||
&p.bound_generic_params,
|
&p.bound_generic_params,
|
||||||
|this, bound_generic_params| {
|
|this, bound_generic_params| {
|
||||||
let trait_ref = this.lower_trait_ref(&p.trait_ref, itctx);
|
let trait_ref = this.lower_trait_ref(&p.trait_ref, itctx, captures);
|
||||||
hir::PolyTraitRef { bound_generic_params, trait_ref, span: this.lower_span(p.span) }
|
hir::PolyTraitRef { bound_generic_params, trait_ref, span: this.lower_span(p.span) }
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
|
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
|
||||||
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl }
|
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx, true), mutbl: mt.mutbl }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_param_bounds(
|
fn lower_param_bounds(
|
||||||
&mut self,
|
&mut self,
|
||||||
bounds: &[GenericBound],
|
bounds: &[GenericBound],
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
) -> hir::GenericBounds<'hir> {
|
) -> hir::GenericBounds<'hir> {
|
||||||
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx))
|
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx, captures))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_param_bounds_mut<'s>(
|
fn lower_param_bounds_mut<'s>(
|
||||||
&'s mut self,
|
&'s mut self,
|
||||||
bounds: &'s [GenericBound],
|
bounds: &'s [GenericBound],
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
|
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
|
||||||
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
|
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx, captures))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_generic_and_bounds(
|
fn lower_generic_and_bounds(
|
||||||
|
|
|
@ -36,6 +36,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
path,
|
path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
|
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
|
||||||
break hir::PatKind::TupleStruct(qpath, pats, ddpos);
|
break hir::PatKind::TupleStruct(qpath, pats, ddpos);
|
||||||
|
@ -52,6 +53,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
path,
|
path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
break hir::PatKind::Path(qpath);
|
break hir::PatKind::Path(qpath);
|
||||||
}
|
}
|
||||||
|
@ -62,6 +64,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
path,
|
path,
|
||||||
ParamMode::Optional,
|
ParamMode::Optional,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {
|
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {
|
||||||
|
|
|
@ -24,9 +24,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
p: &Path,
|
p: &Path,
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
) -> hir::QPath<'hir> {
|
) -> hir::QPath<'hir> {
|
||||||
let qself_position = qself.as_ref().map(|q| q.position);
|
let qself_position = qself.as_ref().map(|q| q.position);
|
||||||
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));
|
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx, captures));
|
||||||
|
|
||||||
let partial_res =
|
let partial_res =
|
||||||
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
|
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
|
||||||
|
@ -72,6 +73,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
param_mode,
|
param_mode,
|
||||||
parenthesized_generic_args,
|
parenthesized_generic_args,
|
||||||
itctx,
|
itctx,
|
||||||
|
captures,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
|
@ -118,6 +120,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
param_mode,
|
param_mode,
|
||||||
ParenthesizedGenericArgs::Err,
|
ParenthesizedGenericArgs::Err,
|
||||||
itctx,
|
itctx,
|
||||||
|
captures,
|
||||||
));
|
));
|
||||||
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
|
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
|
||||||
|
|
||||||
|
@ -158,6 +161,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
param_mode,
|
param_mode,
|
||||||
ParenthesizedGenericArgs::Err,
|
ParenthesizedGenericArgs::Err,
|
||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
})),
|
})),
|
||||||
span: self.lower_span(p.span),
|
span: self.lower_span(p.span),
|
||||||
|
@ -182,6 +186,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
parenthesized_generic_args: ParenthesizedGenericArgs,
|
parenthesized_generic_args: ParenthesizedGenericArgs,
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
|
captures: bool,
|
||||||
) -> hir::PathSegment<'hir> {
|
) -> hir::PathSegment<'hir> {
|
||||||
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment,);
|
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment,);
|
||||||
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
|
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
|
||||||
|
@ -254,6 +259,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
segment.id,
|
segment.id,
|
||||||
segment.ident.span,
|
segment.ident.span,
|
||||||
&mut generic_args,
|
&mut generic_args,
|
||||||
|
captures,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +289,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
segment_id: NodeId,
|
segment_id: NodeId,
|
||||||
segment_ident_span: Span,
|
segment_ident_span: Span,
|
||||||
generic_args: &mut GenericArgsCtor<'hir>,
|
generic_args: &mut GenericArgsCtor<'hir>,
|
||||||
|
captures: bool,
|
||||||
) {
|
) {
|
||||||
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
|
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
|
||||||
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
|
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
|
||||||
|
@ -311,10 +318,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
0,
|
0,
|
||||||
(start.as_u32()..end.as_u32()).map(|i| {
|
(start.as_u32()..end.as_u32()).map(|i| {
|
||||||
let id = NodeId::from_u32(i);
|
let id = NodeId::from_u32(i);
|
||||||
let l = self.lower_lifetime(&Lifetime {
|
let l = self.lower_lifetime(
|
||||||
|
&Lifetime {
|
||||||
id,
|
id,
|
||||||
ident: Ident::new(kw::UnderscoreLifetime, elided_lifetime_span),
|
ident: Ident::new(kw::UnderscoreLifetime, elided_lifetime_span),
|
||||||
});
|
},
|
||||||
|
captures,
|
||||||
|
);
|
||||||
GenericArg::Lifetime(l)
|
GenericArg::Lifetime(l)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -358,12 +368,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// we generally don't permit such things (see #51008).
|
// we generally don't permit such things (see #51008).
|
||||||
let ParenthesizedArgs { span, inputs, inputs_span, output } = data;
|
let ParenthesizedArgs { span, inputs, inputs_span, output } = data;
|
||||||
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|ty| {
|
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|ty| {
|
||||||
self.lower_ty_direct(ty, ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam))
|
self.lower_ty_direct(
|
||||||
|
ty,
|
||||||
|
ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam),
|
||||||
|
true,
|
||||||
|
)
|
||||||
}));
|
}));
|
||||||
let output_ty = match output {
|
let output_ty = match output {
|
||||||
FnRetTy::Ty(ty) => {
|
FnRetTy::Ty(ty) => self.lower_ty(
|
||||||
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))
|
&ty,
|
||||||
}
|
ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn),
|
||||||
|
true,
|
||||||
|
),
|
||||||
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
|
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
|
||||||
};
|
};
|
||||||
let args = smallvec![GenericArg::Type(self.ty_tup(*inputs_span, inputs))];
|
let args = smallvec![GenericArg::Type(self.ty_tup(*inputs_span, inputs))];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue