Skip to content

Commit 7e51a76

Browse files
committed
Prefactor LangItem::QPath lowering functions
Get ready to incrementally remove LangItem::QPath.
1 parent 6f3d0f7 commit 7e51a76

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

compiler/rustc_ast_lowering/src/contract.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
120120
lowered_req.span,
121121
None,
122122
);
123-
let precond = self.expr_call_lang_item_fn_mut(
123+
let precond = self.expr_call_lang_item_qpath_fn_mut(
124124
req_span,
125125
rustc_hir::LangItem::ContractCheckRequires,
126126
&*arena_vec![self; lowered_req],
@@ -136,7 +136,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
136136
let ens_span =
137137
self.mark_span_with_reason(rustc_span::DesugaringKind::Contract, ens_span, None);
138138
let lowered_ens = self.lower_expr_mut(&ens);
139-
self.expr_call_lang_item_fn(
139+
self.expr_call_lang_item_qpath_fn(
140140
ens_span,
141141
rustc_hir::LangItem::ContractBuildCheckEnsures,
142142
&*arena_vec![self; lowered_ens],
@@ -291,7 +291,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
291291
let ret = self.expr_ident(span, ret_ident, ret_hir_id);
292292

293293
let cond_fn = self.expr_ident(span, cond_ident, cond_hir_id);
294-
let contract_check = self.expr_call_lang_item_fn_mut(
294+
let contract_check = self.expr_call_lang_item_qpath_fn_mut(
295295
span,
296296
rustc_hir::LangItem::ContractCheckEnsures,
297297
arena_vec![self; *cond_fn, *ret],

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
609609
expr: &'hir hir::Expr<'hir>,
610610
overall_span: Span,
611611
) -> &'hir hir::Expr<'hir> {
612-
let constructor = self.arena.alloc(self.expr_lang_item_path(method_span, lang_item));
612+
let constructor = self.arena.alloc(self.expr_lang_item_qpath(method_span, lang_item));
613613
self.expr_call(overall_span, constructor, std::slice::from_ref(expr))
614614
}
615615

@@ -901,23 +901,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
901901

902902
let task_context = self.expr_ident_mut(span, task_context_ident, task_context_hid);
903903

904-
let new_unchecked = self.expr_call_lang_item_fn_mut(
904+
let new_unchecked = self.expr_call_lang_item_qpath_fn_mut(
905905
span,
906906
hir::LangItem::PinNewUnchecked,
907907
arena_vec![self; ref_mut_awaitee],
908908
);
909-
let get_context = self.expr_call_lang_item_fn_mut(
909+
let get_context = self.expr_call_lang_item_qpath_fn_mut(
910910
gen_future_span,
911911
hir::LangItem::GetContext,
912912
arena_vec![self; task_context],
913913
);
914914
let call = match await_kind {
915-
FutureKind::Future => self.expr_call_lang_item_fn(
915+
FutureKind::Future => self.expr_call_lang_item_qpath_fn(
916916
span,
917917
hir::LangItem::FuturePoll,
918918
arena_vec![self; new_unchecked, get_context],
919919
),
920-
FutureKind::AsyncIterator => self.expr_call_lang_item_fn(
920+
FutureKind::AsyncIterator => self.expr_call_lang_item_qpath_fn(
921921
span,
922922
hir::LangItem::AsyncIteratorPollNext,
923923
arena_vec![self; new_unchecked, get_context],
@@ -965,7 +965,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
965965
// async gen - task_context = yield ASYNC_GEN_PENDING;
966966
let yield_stmt = {
967967
let yielded = if is_async_gen {
968-
self.arena.alloc(self.expr_lang_item_path(span, hir::LangItem::AsyncGenPending))
968+
self.arena.alloc(self.expr_lang_item_qpath(span, hir::LangItem::AsyncGenPending))
969969
} else {
970970
self.expr_unit(span)
971971
};
@@ -1005,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10051005

10061006
// `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
10071007
let into_future_expr = match await_kind {
1008-
FutureKind::Future => self.expr_call_lang_item_fn(
1008+
FutureKind::Future => self.expr_call_lang_item_qpath_fn(
10091009
span,
10101010
hir::LangItem::IntoFutureIntoFuture,
10111011
arena_vec![self; *expr],
@@ -1720,7 +1720,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17201720
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
17211721
// This ensures that we store our resumed `ResumeContext` correctly, and also that
17221722
// the apparent value of the `yield` expression is `()`.
1723-
let wrapped_yielded = self.expr_call_lang_item_fn(
1723+
let wrapped_yielded = self.expr_call_lang_item_qpath_fn(
17241724
span,
17251725
hir::LangItem::AsyncGenReady,
17261726
std::slice::from_ref(yielded),
@@ -1804,7 +1804,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18041804
ForLoopKind::For => {
18051805
// `Iterator::next(&mut iter)`
18061806
let ref_mut_iter = self.expr_mut_addr_of(head_span, iter);
1807-
self.expr_call_lang_item_fn(
1807+
self.expr_call_lang_item_qpath_fn(
18081808
head_span,
18091809
hir::LangItem::IteratorNext,
18101810
arena_vec![self; ref_mut_iter],
@@ -1819,7 +1819,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18191819
// `&mut iter`
18201820
let iter = self.expr_mut_addr_of(head_span, iter);
18211821
// `Pin::new_unchecked(...)`
1822-
let iter = self.arena.alloc(self.expr_call_lang_item_fn_mut(
1822+
let iter = self.arena.alloc(self.expr_call_lang_item_qpath_fn_mut(
18231823
head_span,
18241824
hir::LangItem::PinNewUnchecked,
18251825
arena_vec![self; iter],
@@ -1854,7 +1854,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18541854
let match_expr = match loop_kind {
18551855
ForLoopKind::For => {
18561856
// `::std::iter::IntoIterator::into_iter(<head>)`
1857-
let into_iter_expr = self.expr_call_lang_item_fn(
1857+
let into_iter_expr = self.expr_call_lang_item_qpath_fn(
18581858
head_span,
18591859
hir::LangItem::IntoIterIntoIter,
18601860
arena_vec![self; head],
@@ -1874,7 +1874,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18741874
self.pat_ident_binding_mode(head_span, iter_ident, hir::BindingMode::REF_MUT);
18751875
let iter = self.expr_ident_mut(head_span, iter_ident, async_iter_pat_id);
18761876
// `Pin::new_unchecked(...)`
1877-
let iter = self.arena.alloc(self.expr_call_lang_item_fn_mut(
1877+
let iter = self.arena.alloc(self.expr_call_lang_item_qpath_fn_mut(
18781878
head_span,
18791879
hir::LangItem::PinNewUnchecked,
18801880
arena_vec![self; iter],
@@ -1889,7 +1889,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18891889
));
18901890

18911891
// `::core::async_iter::IntoAsyncIterator::into_async_iter(<head>)`
1892-
let iter = self.expr_call_lang_item_fn(
1892+
let iter = self.expr_call_lang_item_qpath_fn(
18931893
head_span,
18941894
hir::LangItem::IntoAsyncIterIntoIter,
18951895
arena_vec![self; head],
@@ -1945,7 +1945,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19451945
// expand <expr>
19461946
let sub_expr = self.lower_expr_mut(sub_expr);
19471947

1948-
self.expr_call_lang_item_fn(
1948+
self.expr_call_lang_item_qpath_fn(
19491949
unstable_span,
19501950
hir::LangItem::TryTraitBranch,
19511951
arena_vec![self; sub_expr],
@@ -2166,7 +2166,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21662166
lang_item: hir::LangItem,
21672167
fields: &'hir [hir::Expr<'hir>],
21682168
) -> hir::Expr<'hir> {
2169-
let path = self.arena.alloc(self.lang_item_path(span, lang_item));
2169+
let path = self.arena.alloc(self.lang_item_qpath(span, lang_item));
21702170
self.expr_enum_variant(span, path, fields)
21712171
}
21722172

@@ -2198,20 +2198,40 @@ impl<'hir> LoweringContext<'_, 'hir> {
21982198
self.arena.alloc(self.expr_call_lang_item_fn_mut(span, lang_item, args))
21992199
}
22002200

2201-
pub(super) fn expr_lang_item_path(
2201+
// TEMPORARY - will be replaced with expr_call_lang_item_fn_mut
2202+
pub(super) fn expr_call_lang_item_qpath_fn_mut(
22022203
&mut self,
22032204
span: Span,
22042205
lang_item: hir::LangItem,
2206+
args: &'hir [hir::Expr<'hir>],
22052207
) -> hir::Expr<'hir> {
2206-
let path = self.lang_item_path(span, lang_item);
2207-
self.expr(span, hir::ExprKind::Path(path))
2208+
let path = self.arena.alloc(self.expr_lang_item_qpath(span, lang_item));
2209+
self.expr_call_mut(span, path, args)
22082210
}
22092211

2210-
pub(super) fn lang_item_path(
2212+
// TEMPORARY - will be replaced with expr_call_lang_item_fn
2213+
pub(super) fn expr_call_lang_item_qpath_fn(
22112214
&mut self,
22122215
span: Span,
22132216
lang_item: hir::LangItem,
2214-
) -> hir::QPath<'hir> {
2217+
args: &'hir [hir::Expr<'hir>],
2218+
) -> &'hir hir::Expr<'hir> {
2219+
self.arena.alloc(self.expr_call_lang_item_qpath_fn_mut(span, lang_item, args))
2220+
}
2221+
2222+
fn expr_lang_item_path(&mut self, span: Span, lang_item: hir::LangItem) -> hir::Expr<'hir> {
2223+
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
2224+
self.expr(span, hir::ExprKind::Path(qpath))
2225+
}
2226+
2227+
// TEMPORARY - will be replaced with expr_lang_item_path
2228+
fn expr_lang_item_qpath(&mut self, span: Span, lang_item: hir::LangItem) -> hir::Expr<'hir> {
2229+
let qpath = self.lang_item_qpath(span, lang_item);
2230+
self.expr(span, hir::ExprKind::Path(qpath))
2231+
}
2232+
2233+
// TEMPORARY - will be replaced with expr_lang_item_path
2234+
fn lang_item_qpath(&mut self, span: Span, lang_item: hir::LangItem) -> hir::QPath<'hir> {
22152235
hir::QPath::LangItem(lang_item, self.lower_span(span))
22162236
}
22172237

0 commit comments

Comments
 (0)