Completely remove captures flag

This commit is contained in:
Santiago Pastorino 2022-07-26 15:50:25 -03:00
parent 20c88a2a30
commit 9f77688d17
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
8 changed files with 99 additions and 193 deletions

View File

@ -234,7 +234,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&sym.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
hir::InlineAsmOperand::SymStatic { path, def_id }
} else {

View File

@ -84,9 +84,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> {
let ty = l.ty.as_ref().map(|t| {
self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable), true)
});
let ty = l
.ty
.as_ref()
.map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
let init = l.kind.init().map(|init| self.lower_expr(init));
let hir_id = self.lower_node_id(l.id);
let pat = self.lower_pat(&l.pat);

View File

@ -69,7 +69,6 @@ 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))
@ -90,20 +89,14 @@ 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),
true,
);
let ty =
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
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),
true,
);
let ty =
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
hir::ExprKind::Type(expr, ty)
}
ExprKind::AddrOf(k, m, ref ohs) => {
@ -233,7 +226,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
hir::ExprKind::Path(qpath)
}
@ -272,7 +264,6 @@ 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))),
@ -570,11 +561,9 @@ 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),
true,
)),
Some(ty) => hir::FnRetTy::Return(
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)),
),
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
};
@ -1178,7 +1167,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
// Destructure like a tuple struct.
let tuple_struct_pat =
@ -1195,7 +1183,6 @@ 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);
@ -1220,7 +1207,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
&se.path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
let fields_omitted = match &se.rest {
StructRest::Base(e) => {

View File

@ -308,7 +308,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&generics,
id,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy, true),
|this| this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy),
);
hir::ItemKind::TyAlias(ty, generics)
}
@ -386,15 +386,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.lower_trait_ref(
trait_ref,
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
true,
)
});
let lowered_ty = this.lower_ty(
ty,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
);
let lowered_ty = this
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
(trait_ref, lowered_ty)
});
@ -438,7 +434,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
let bounds = this.lower_param_bounds(
bounds,
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
true,
);
let items = this.arena.alloc_from_iter(
items.iter().map(|item| this.lower_trait_item_ref(item)),
@ -458,7 +453,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.lower_param_bounds(
bounds,
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
true,
)
},
);
@ -481,7 +475,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span: Span,
body: Option<&Expr>,
) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
(ty, self.lower_const_body(span, body))
}
@ -667,11 +661,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
}
ForeignItemKind::Static(ref t, m, _) => {
let ty = self.lower_ty(
t,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
);
let ty =
self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
hir::ForeignItemKind::Static(ty, m)
}
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
@ -740,11 +731,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
path,
ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124)
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
self.arena.alloc(t)
} else {
self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true)
self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
};
let hir_id = self.lower_node_id(f.id);
self.lower_attrs(hir_id, &f.attrs);
@ -767,8 +757,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (generics, kind, has_default) = match i.kind {
AssocItemKind::Const(_, ref ty, ref default) => {
let ty =
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
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())
}
@ -806,17 +795,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
let ty = ty.as_ref().map(|x| {
this.lower_ty(
x,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
)
this.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
});
hir::TraitItemKind::Type(
this.lower_param_bounds(
bounds,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
true,
),
ty,
)
@ -869,8 +853,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (generics, kind) = match &i.kind {
AssocItemKind::Const(_, ty, expr) => {
let ty =
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
(
hir::Generics::empty(),
hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())),
@ -904,7 +887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ImplItemKind::TyAlias(ty)
}
Some(ty) => {
let ty = this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy, true);
let ty = this.lower_ty(ty, ImplTraitContext::TypeAliasesOpaqueTy);
hir::ImplItemKind::TyAlias(ty)
}
},
@ -1429,7 +1412,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
return None;
}
let bounds = self.lower_param_bounds(bounds, itctx, true);
let bounds = self.lower_param_bounds(bounds, itctx);
let ident = self.lower_ident(ident);
let param_span = ident.span;
@ -1475,8 +1458,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
panic!("Missing resolution for lifetime {:?} at {:?}", id, ident.span)
});
let lt_id = self.next_node_id();
let lifetime =
self.new_named_lifetime_with_res(lt_id, ident_span, ident, res, true);
let lifetime = self.new_named_lifetime_with_res(lt_id, ident_span, ident, res);
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
lifetime,
span,
@ -1496,16 +1478,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
span,
}) => hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
bound_generic_params: self.lower_generic_params(bound_generic_params),
bounded_ty: self.lower_ty(
bounded_ty,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
),
bounded_ty: self
.lower_ty(bounded_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
bounds: self.arena.alloc_from_iter(bounds.iter().map(|bound| {
self.lower_param_bound(
bound,
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
true,
)
})),
span: self.lower_span(span),
@ -1517,27 +1495,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
span,
}) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
span: self.lower_span(span),
lifetime: self.lower_lifetime(lifetime, true),
lifetime: self.lower_lifetime(lifetime),
bounds: self.lower_param_bounds(
bounds,
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
true,
),
in_where_clause: true,
}),
WherePredicate::EqPredicate(WhereEqPredicate { id, ref lhs_ty, ref rhs_ty, span }) => {
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
hir_id: self.lower_node_id(id),
lhs_ty: self.lower_ty(
lhs_ty,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
),
rhs_ty: self.lower_ty(
rhs_ty,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
),
lhs_ty: self
.lower_ty(lhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
rhs_ty: self
.lower_ty(rhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
span: self.lower_span(span),
})
}

View File

@ -932,7 +932,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let kind = match constraint.kind {
AssocConstraintKind::Equality { ref term } => {
let term = match term {
Term::Ty(ref ty) => self.lower_ty(ty, itctx, true).into(),
Term::Ty(ref ty) => self.lower_ty(ty, itctx).into(),
Term::Const(ref c) => self.lower_anon_const(c).into(),
};
hir::TypeBindingKind::Equality { term }
@ -997,7 +997,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
tokens: None,
},
itctx,
true,
);
hir::TypeBindingKind::Equality { term: ty.into() }
@ -1005,7 +1004,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
// Desugar `AssocTy: Bounds` into a type binding where the
// later desugars into a trait predicate.
let bounds = self.lower_param_bounds(bounds, itctx, true);
let bounds = self.lower_param_bounds(bounds, itctx);
hir::TypeBindingKind::Constraint { bounds }
}
@ -1064,7 +1063,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
itctx: ImplTraitContext,
) -> hir::GenericArg<'hir> {
match arg {
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt, true)),
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt)),
ast::GenericArg::Type(ty) => {
match ty.kind {
TyKind::Infer if self.tcx.features().generic_arg_infer => {
@ -1113,7 +1112,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
_ => {}
}
GenericArg::Type(self.lower_ty_direct(&ty, itctx, true))
GenericArg::Type(self.lower_ty_direct(&ty, itctx))
}
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
value: self.lower_anon_const(&ct),
@ -1123,8 +1122,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
#[instrument(level = "debug", skip(self))]
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext, captures: bool) -> &'hir hir::Ty<'hir> {
self.arena.alloc(self.lower_ty_direct(t, itctx, captures))
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
self.arena.alloc(self.lower_ty_direct(t, itctx))
}
fn lower_path_ty(
@ -1134,7 +1133,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
path: &Path,
param_mode: ParamMode,
itctx: ImplTraitContext,
captures: bool,
) -> hir::Ty<'hir> {
// 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
@ -1154,7 +1152,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: t.span
},
itctx,
captures,
);
let bounds = this.arena.alloc_from_iter([bound]);
let lifetime_bound = this.elided_dyn_bound(t.span);
@ -1165,7 +1162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
let id = self.lower_node_id(t.id);
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx, true);
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx);
self.ty_path(id, t.span, qpath)
}
@ -1177,16 +1174,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.ty(span, hir::TyKind::Tup(tys))
}
fn lower_ty_direct(
&mut self,
t: &Ty,
itctx: ImplTraitContext,
captures: bool,
) -> hir::Ty<'hir> {
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
let kind = match t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => hir::TyKind::Err,
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx, captures)),
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
TyKind::Rptr(ref region, ref mt) => {
let region = region.unwrap_or_else(|| {
@ -1201,7 +1193,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
});
let lifetime = self.lower_lifetime(&region, captures);
let lifetime = self.lower_lifetime(&region);
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
}
TyKind::BareFn(ref f) => {
@ -1216,16 +1208,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
})
}
TyKind::Never => hir::TyKind::Never,
TyKind::Tup(ref tys) => {
hir::TyKind::Tup(self.arena.alloc_from_iter(
tys.iter().map(|ty| self.lower_ty_direct(ty, itctx, captures)),
))
}
TyKind::Tup(ref tys) => hir::TyKind::Tup(
self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty_direct(ty, itctx))),
),
TyKind::Paren(ref ty) => {
return self.lower_ty_direct(ty, itctx, captures);
return self.lower_ty_direct(ty, itctx);
}
TyKind::Path(ref qself, ref path) => {
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx, captures);
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
}
TyKind::ImplicitSelf => {
let res = self.expect_full_res(t.id);
@ -1241,10 +1231,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}),
))
}
TyKind::Array(ref ty, ref length) => hir::TyKind::Array(
self.lower_ty(ty, itctx, captures),
self.lower_array_length(length),
),
TyKind::Array(ref ty, ref length) => {
hir::TyKind::Array(self.lower_ty(ty, itctx), self.lower_array_length(length))
}
TyKind::Typeof(ref expr) => hir::TyKind::Typeof(self.lower_anon_const(expr)),
TyKind::TraitObject(ref bounds, kind) => {
let mut lifetime_bound = None;
@ -1255,7 +1244,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
GenericBound::Trait(
ref ty,
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
) => Some(this.lower_poly_trait_ref(ty, itctx, captures)),
) => Some(this.lower_poly_trait_ref(ty, itctx)),
// `~const ?Bound` will cause an error during AST validation
// anyways, so treat it like `?Bound` as compilation proceeds.
GenericBound::Trait(
@ -1264,7 +1253,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) => None,
GenericBound::Outlives(ref lifetime) => {
if lifetime_bound.is_none() {
lifetime_bound = Some(this.lower_lifetime(lifetime, true));
lifetime_bound = Some(this.lower_lifetime(lifetime));
}
None
}
@ -1350,7 +1339,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let mut collected_lifetimes = FxHashMap::default();
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
let hir_bounds = if origin == hir::OpaqueTyOrigin::TyAlias {
lctx.lower_param_bounds(bounds, itctx, true)
lctx.lower_param_bounds(bounds, itctx)
} else {
debug!(?lctx.captured_lifetimes);
@ -1369,7 +1358,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
lctx.create_and_capture_lifetime_defs(&lifetimes_in_bounds, &binders_to_ignore);
let ret = lctx.lower_param_bounds(bounds, itctx, false);
let ret = lctx.lower_param_bounds(bounds, itctx);
let ctxt = std::mem::replace(&mut lctx.captured_lifetimes, lifetime_stash).unwrap();
@ -1423,7 +1412,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|(_, (span, _, p_name, res))| {
let id = self.next_node_id();
let ident = Ident::new(p_name.ident().name, span);
let l = self.new_named_lifetime_with_res(id, span, ident, res, false);
let l = self.new_named_lifetime_with_res(id, span, ident, res);
hir::GenericArg::Lifetime(l)
},
));
@ -1579,7 +1568,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
if fn_node_id.is_some() {
self.lower_ty_direct(&param.ty, ImplTraitContext::Universal, true)
self.lower_ty_direct(&param.ty, ImplTraitContext::Universal)
} else {
self.lower_ty_direct(
&param.ty,
@ -1593,7 +1582,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
FnDeclKind::Trait => ImplTraitPosition::TraitParam,
FnDeclKind::Impl => ImplTraitPosition::ImplParam,
}),
true,
)
}
}));
@ -1625,7 +1613,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
}),
};
hir::FnRetTy::Return(self.lower_ty(ty, context, true))
hir::FnRetTy::Return(self.lower_ty(ty, context))
}
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
}
@ -1847,7 +1835,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.arena.alloc_from_iter(captures.into_iter().map(|(_, (span, _, p_name, res))| {
let id = self.next_node_id();
let ident = Ident::new(p_name.ident().name, span);
let l = self.new_named_lifetime_with_res(id, span, ident, res, true);
let l = self.new_named_lifetime_with_res(id, span, ident, res);
hir::GenericArg::Lifetime(l)
}));
@ -1877,7 +1865,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let context = ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
};
self.lower_ty(ty, context, false)
self.lower_ty(ty, context)
}
FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
};
@ -1904,24 +1892,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
tpb: &GenericBound,
itctx: ImplTraitContext,
captures: bool,
) -> hir::GenericBound<'hir> {
match tpb {
GenericBound::Trait(p, modifier) => hir::GenericBound::Trait(
self.lower_poly_trait_ref(p, itctx, captures),
self.lower_poly_trait_ref(p, itctx),
self.lower_trait_bound_modifier(*modifier),
),
GenericBound::Outlives(lifetime) => {
hir::GenericBound::Outlives(self.lower_lifetime(lifetime, captures))
hir::GenericBound::Outlives(self.lower_lifetime(lifetime))
}
}
}
fn lower_lifetime(&mut self, l: &Lifetime, captures: bool) -> hir::Lifetime {
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
let span = self.lower_span(l.ident.span);
let ident = self.lower_ident(l.ident);
let res = self.resolver.get_lifetime_res(l.id).unwrap_or(LifetimeRes::Error);
self.new_named_lifetime_with_res(l.id, span, ident, res, captures)
self.new_named_lifetime_with_res(l.id, span, ident, res)
}
#[tracing::instrument(level = "debug", skip(self))]
@ -1931,7 +1918,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span,
ident: Ident,
res: LifetimeRes,
captures: bool,
) -> hir::Lifetime {
debug!(?self.captured_lifetimes);
@ -1939,7 +1925,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
LifetimeRes::Param { mut param, binder } => {
let p_name = ParamName::Plain(ident);
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
if captures {
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
match captured_lifetimes.captures.entry(param) {
Entry::Occupied(o) => param = self.local_def_id(o.get().1),
@ -1957,11 +1942,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
}
} else {
if let Entry::Occupied(o) = captured_lifetimes.captures.entry(param) {
param = self.local_def_id(o.get().1);
}
}
self.captured_lifetimes = Some(captured_lifetimes);
}
@ -2054,11 +2035,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
GenericParamKind::Type { ref default, .. } => {
let kind = hir::GenericParamKind::Type {
default: default.as_ref().map(|x| {
self.lower_ty(
x,
ImplTraitContext::Disallowed(ImplTraitPosition::Type),
true,
)
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type))
}),
synthetic: false,
};
@ -2066,8 +2043,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
}
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
let ty =
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type), true);
let ty = self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
let default = default.as_ref().map(|def| self.lower_anon_const(def));
(
hir::ParamName::Plain(self.lower_ident(param.ident)),
@ -2077,20 +2053,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
fn lower_trait_ref(
&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,
) {
fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext) -> hir::TraitRef<'hir> {
let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) {
hir::QPath::Resolved(None, path) => path,
qpath => panic!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
};
@ -2102,38 +2066,35 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
p: &PolyTraitRef,
itctx: ImplTraitContext,
captures: bool,
) -> hir::PolyTraitRef<'hir> {
self.with_lifetime_binder(
p.trait_ref.ref_id,
&p.bound_generic_params,
|this, bound_generic_params| {
let trait_ref = this.lower_trait_ref(&p.trait_ref, itctx, captures);
let trait_ref = this.lower_trait_ref(&p.trait_ref, itctx);
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> {
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx, true), mutbl: mt.mutbl }
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl }
}
fn lower_param_bounds(
&mut self,
bounds: &[GenericBound],
itctx: ImplTraitContext,
captures: bool,
) -> hir::GenericBounds<'hir> {
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx, captures))
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx))
}
fn lower_param_bounds_mut<'s>(
&'s mut self,
bounds: &'s [GenericBound],
itctx: ImplTraitContext,
captures: bool,
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx, captures))
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
}
fn lower_generic_and_bounds(

View File

@ -36,7 +36,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
break hir::PatKind::TupleStruct(qpath, pats, ddpos);
@ -53,7 +52,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
break hir::PatKind::Path(qpath);
}
@ -64,7 +62,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
path,
ParamMode::Optional,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
);
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {

View File

@ -24,10 +24,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
p: &Path,
param_mode: ParamMode,
itctx: ImplTraitContext,
captures: bool,
) -> hir::QPath<'hir> {
let qself_position = qself.as_ref().map(|q| q.position);
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx, captures));
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));
let partial_res =
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
@ -73,7 +72,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
param_mode,
parenthesized_generic_args,
itctx,
captures,
)
},
)),
@ -120,7 +118,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
param_mode,
ParenthesizedGenericArgs::Err,
itctx,
captures,
));
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
@ -161,7 +158,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
param_mode,
ParenthesizedGenericArgs::Err,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
true,
)
})),
span: self.lower_span(p.span),
@ -186,7 +182,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
param_mode: ParamMode,
parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: ImplTraitContext,
captures: bool,
) -> hir::PathSegment<'hir> {
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment,);
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
@ -259,7 +254,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
segment.id,
segment.ident.span,
&mut generic_args,
captures,
);
}
@ -289,7 +283,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
segment_id: NodeId,
segment_ident_span: Span,
generic_args: &mut GenericArgsCtor<'hir>,
captures: bool,
) {
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
@ -318,13 +311,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
0,
(start.as_u32()..end.as_u32()).map(|i| {
let id = NodeId::from_u32(i);
let l = self.lower_lifetime(
&Lifetime {
let l = self.lower_lifetime(&Lifetime {
id,
ident: Ident::new(kw::UnderscoreLifetime, elided_lifetime_span),
},
captures,
);
});
GenericArg::Lifetime(l)
}),
);
@ -368,18 +358,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// we generally don't permit such things (see #51008).
let ParenthesizedArgs { span, inputs, inputs_span, output } = data;
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|ty| {
self.lower_ty_direct(
ty,
ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam),
true,
)
self.lower_ty_direct(ty, ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam))
}));
let output_ty = match output {
FnRetTy::Ty(ty) => self.lower_ty(
&ty,
ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn),
true,
),
FnRetTy::Ty(ty) => {
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))
}
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
};
let args = smallvec![GenericArg::Type(self.ty_tup(*inputs_span, inputs))];

View File

@ -0,0 +1,7 @@
// check-pass
pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &u32)> {
v.into_iter()
}
fn main() {}