Remove unnecessary Option from LoweringContext::allow_{try_trait,gen_future}.

Also remove some unnecessary slicing.
This commit is contained in:
Nicholas Nethercote 2023-11-28 12:29:21 +11:00
parent 3bae9276fa
commit 5c680e1bcb
2 changed files with 19 additions and 16 deletions

View File

@ -524,7 +524,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.mark_span_with_reason( this.mark_span_with_reason(
DesugaringKind::TryBlock, DesugaringKind::TryBlock,
expr.span, expr.span,
this.allow_try_trait.clone(), Some(this.allow_try_trait.clone()),
), ),
expr, expr,
) )
@ -532,7 +532,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let try_span = this.mark_span_with_reason( let try_span = this.mark_span_with_reason(
DesugaringKind::TryBlock, DesugaringKind::TryBlock,
this.tcx.sess.source_map().end_point(body.span), this.tcx.sess.source_map().end_point(body.span),
this.allow_try_trait.clone(), Some(this.allow_try_trait.clone()),
); );
(try_span, this.expr_unit(try_span)) (try_span, this.expr_unit(try_span))
@ -612,8 +612,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span))); let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
// Resume argument type: `ResumeTy` // Resume argument type: `ResumeTy`
let unstable_span = let unstable_span = self.mark_span_with_reason(
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone()); DesugaringKind::Async,
span,
Some(self.allow_gen_future.clone()),
);
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span); let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
let input_ty = hir::Ty { let input_ty = hir::Ty {
hir_id: self.next_id(), hir_id: self.next_id(),
@ -735,7 +738,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unstable_span = self.mark_span_with_reason( let unstable_span = self.mark_span_with_reason(
DesugaringKind::Async, DesugaringKind::Async,
span, span,
self.allow_gen_future.clone(), Some(self.allow_gen_future.clone()),
); );
self.lower_attrs( self.lower_attrs(
inner_hir_id, inner_hir_id,
@ -782,7 +785,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let gen_future_span = self.mark_span_with_reason( let gen_future_span = self.mark_span_with_reason(
DesugaringKind::Await, DesugaringKind::Await,
full_span, full_span,
self.allow_gen_future.clone(), Some(self.allow_gen_future.clone()),
); );
let expr = self.lower_expr_mut(expr); let expr = self.lower_expr_mut(expr);
let expr_hir_id = expr.hir_id; let expr_hir_id = expr.hir_id;
@ -1640,13 +1643,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unstable_span = self.mark_span_with_reason( let unstable_span = self.mark_span_with_reason(
DesugaringKind::QuestionMark, DesugaringKind::QuestionMark,
span, span,
self.allow_try_trait.clone(), Some(self.allow_try_trait.clone()),
); );
let try_span = self.tcx.sess.source_map().end_point(span); let try_span = self.tcx.sess.source_map().end_point(span);
let try_span = self.mark_span_with_reason( let try_span = self.mark_span_with_reason(
DesugaringKind::QuestionMark, DesugaringKind::QuestionMark,
try_span, try_span,
self.allow_try_trait.clone(), Some(self.allow_try_trait.clone()),
); );
// `Try::branch(<expr>)` // `Try::branch(<expr>)`
@ -1739,7 +1742,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unstable_span = self.mark_span_with_reason( let unstable_span = self.mark_span_with_reason(
DesugaringKind::YeetExpr, DesugaringKind::YeetExpr,
span, span,
self.allow_try_trait.clone(), Some(self.allow_try_trait.clone()),
); );
let from_yeet_expr = self.wrap_in_try_constructor( let from_yeet_expr = self.wrap_in_try_constructor(

View File

@ -132,8 +132,8 @@ struct LoweringContext<'a, 'hir> {
/// NodeIds that are lowered inside the current HIR owner. /// NodeIds that are lowered inside the current HIR owner.
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>, node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
allow_try_trait: Option<Lrc<[Symbol]>>, allow_try_trait: Lrc<[Symbol]>,
allow_gen_future: Option<Lrc<[Symbol]>>, allow_gen_future: Lrc<[Symbol]>,
/// Mapping from generics `def_id`s to TAIT generics `def_id`s. /// Mapping from generics `def_id`s to TAIT generics `def_id`s.
/// For each captured lifetime (e.g., 'a), we create a new lifetime parameter that is a generic /// For each captured lifetime (e.g., 'a), we create a new lifetime parameter that is a generic
@ -172,12 +172,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
current_item: None, current_item: None,
impl_trait_defs: Vec::new(), impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(), impl_trait_bounds: Vec::new(),
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()), allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
allow_gen_future: Some(if tcx.features().async_fn_track_caller { allow_gen_future: if tcx.features().async_fn_track_caller {
[sym::gen_future, sym::closure_track_caller][..].into() [sym::gen_future, sym::closure_track_caller].into()
} else { } else {
[sym::gen_future][..].into() [sym::gen_future].into()
}), },
generics_def_id_map: Default::default(), generics_def_id_map: Default::default(),
host_param_id: None, host_param_id: None,
} }