Skip to content

Commit 5c680e1

Browse files
committed
Remove unnecessary Option from LoweringContext::allow_{try_trait,gen_future}.
Also remove some unnecessary slicing.
1 parent 3bae927 commit 5c680e1

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
524524
this.mark_span_with_reason(
525525
DesugaringKind::TryBlock,
526526
expr.span,
527-
this.allow_try_trait.clone(),
527+
Some(this.allow_try_trait.clone()),
528528
),
529529
expr,
530530
)
531531
} else {
532532
let try_span = this.mark_span_with_reason(
533533
DesugaringKind::TryBlock,
534534
this.tcx.sess.source_map().end_point(body.span),
535-
this.allow_try_trait.clone(),
535+
Some(this.allow_try_trait.clone()),
536536
);
537537

538538
(try_span, this.expr_unit(try_span))
@@ -612,8 +612,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
612612
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
613613

614614
// Resume argument type: `ResumeTy`
615-
let unstable_span =
616-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
615+
let unstable_span = self.mark_span_with_reason(
616+
DesugaringKind::Async,
617+
span,
618+
Some(self.allow_gen_future.clone()),
619+
);
617620
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
618621
let input_ty = hir::Ty {
619622
hir_id: self.next_id(),
@@ -735,7 +738,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
735738
let unstable_span = self.mark_span_with_reason(
736739
DesugaringKind::Async,
737740
span,
738-
self.allow_gen_future.clone(),
741+
Some(self.allow_gen_future.clone()),
739742
);
740743
self.lower_attrs(
741744
inner_hir_id,
@@ -782,7 +785,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
782785
let gen_future_span = self.mark_span_with_reason(
783786
DesugaringKind::Await,
784787
full_span,
785-
self.allow_gen_future.clone(),
788+
Some(self.allow_gen_future.clone()),
786789
);
787790
let expr = self.lower_expr_mut(expr);
788791
let expr_hir_id = expr.hir_id;
@@ -1640,13 +1643,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
16401643
let unstable_span = self.mark_span_with_reason(
16411644
DesugaringKind::QuestionMark,
16421645
span,
1643-
self.allow_try_trait.clone(),
1646+
Some(self.allow_try_trait.clone()),
16441647
);
16451648
let try_span = self.tcx.sess.source_map().end_point(span);
16461649
let try_span = self.mark_span_with_reason(
16471650
DesugaringKind::QuestionMark,
16481651
try_span,
1649-
self.allow_try_trait.clone(),
1652+
Some(self.allow_try_trait.clone()),
16501653
);
16511654

16521655
// `Try::branch(<expr>)`
@@ -1739,7 +1742,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17391742
let unstable_span = self.mark_span_with_reason(
17401743
DesugaringKind::YeetExpr,
17411744
span,
1742-
self.allow_try_trait.clone(),
1745+
Some(self.allow_try_trait.clone()),
17431746
);
17441747

17451748
let from_yeet_expr = self.wrap_in_try_constructor(

compiler/rustc_ast_lowering/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ struct LoweringContext<'a, 'hir> {
132132
/// NodeIds that are lowered inside the current HIR owner.
133133
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
134134

135-
allow_try_trait: Option<Lrc<[Symbol]>>,
136-
allow_gen_future: Option<Lrc<[Symbol]>>,
135+
allow_try_trait: Lrc<[Symbol]>,
136+
allow_gen_future: Lrc<[Symbol]>,
137137

138138
/// Mapping from generics `def_id`s to TAIT generics `def_id`s.
139139
/// 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> {
172172
current_item: None,
173173
impl_trait_defs: Vec::new(),
174174
impl_trait_bounds: Vec::new(),
175-
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
176-
allow_gen_future: Some(if tcx.features().async_fn_track_caller {
177-
[sym::gen_future, sym::closure_track_caller][..].into()
175+
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
176+
allow_gen_future: if tcx.features().async_fn_track_caller {
177+
[sym::gen_future, sym::closure_track_caller].into()
178178
} else {
179-
[sym::gen_future][..].into()
180-
}),
179+
[sym::gen_future].into()
180+
},
181181
generics_def_id_map: Default::default(),
182182
host_param_id: None,
183183
}

0 commit comments

Comments
 (0)