Skip to content

Commit bd13c30

Browse files
committed
Remove QPath::LangItem from async
1 parent 7cbff63 commit bd13c30

File tree

7 files changed

+30
-27
lines changed

7 files changed

+30
-27
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
865865
};
866866

867867
let features = match await_kind {
868+
FutureKind::Future if is_async_gen => Some(Arc::clone(&self.allow_async_gen)),
868869
FutureKind::Future => None,
869870
FutureKind::AsyncIterator => Some(Arc::clone(&self.allow_for_await)),
870871
};
@@ -901,23 +902,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
901902

902903
let task_context = self.expr_ident_mut(span, task_context_ident, task_context_hid);
903904

904-
let new_unchecked = self.expr_call_lang_item_qpath_fn_mut(
905+
let new_unchecked = self.expr_call_lang_item_fn_mut(
905906
span,
906907
hir::LangItem::PinNewUnchecked,
907908
arena_vec![self; ref_mut_awaitee],
908909
);
909-
let get_context = self.expr_call_lang_item_qpath_fn_mut(
910+
let get_context = self.expr_call_lang_item_fn_mut(
910911
gen_future_span,
911912
hir::LangItem::GetContext,
912913
arena_vec![self; task_context],
913914
);
914915
let call = match await_kind {
915-
FutureKind::Future => self.expr_call_lang_item_qpath_fn(
916+
FutureKind::Future => self.expr_call_lang_item_fn(
916917
span,
917918
hir::LangItem::FuturePoll,
918919
arena_vec![self; new_unchecked, get_context],
919920
),
920-
FutureKind::AsyncIterator => self.expr_call_lang_item_qpath_fn(
921+
FutureKind::AsyncIterator => self.expr_call_lang_item_fn(
921922
span,
922923
hir::LangItem::AsyncIteratorPollNext,
923924
arena_vec![self; new_unchecked, get_context],
@@ -965,7 +966,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
965966
// async gen - task_context = yield ASYNC_GEN_PENDING;
966967
let yield_stmt = {
967968
let yielded = if is_async_gen {
968-
self.arena.alloc(self.expr_lang_item_qpath(span, hir::LangItem::AsyncGenPending))
969+
self.arena.alloc(self.expr_lang_item_path(span, hir::LangItem::AsyncGenPending))
969970
} else {
970971
self.expr_unit(span)
971972
};
@@ -1005,7 +1006,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10051006

10061007
// `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
10071008
let into_future_expr = match await_kind {
1008-
FutureKind::Future => self.expr_call_lang_item_qpath_fn(
1009+
FutureKind::Future => self.expr_call_lang_item_fn(
10091010
span,
10101011
hir::LangItem::IntoFutureIntoFuture,
10111012
arena_vec![self; *expr],
@@ -1720,8 +1721,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
17201721
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
17211722
// This ensures that we store our resumed `ResumeContext` correctly, and also that
17221723
// the apparent value of the `yield` expression is `()`.
1723-
let wrapped_yielded = self.expr_call_lang_item_qpath_fn(
1724-
span,
1724+
let wrapped_yielded = self.expr_call_lang_item_fn(
1725+
self.mark_span_with_reason(
1726+
DesugaringKind::Async,
1727+
span,
1728+
Some(Arc::clone(&self.allow_async_gen)),
1729+
),
17251730
hir::LangItem::AsyncGenReady,
17261731
std::slice::from_ref(yielded),
17271732
);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct LoweringContext<'a, 'hir> {
142142
allow_try_trait: Arc<[Symbol]>,
143143
allow_gen_future: Arc<[Symbol]>,
144144
allow_pattern_type: Arc<[Symbol]>,
145+
allow_async_gen: Arc<[Symbol]>,
145146
allow_async_iterator: Arc<[Symbol]>,
146147
allow_for_await: Arc<[Symbol]>,
147148
allow_async_fn_traits: Arc<[Symbol]>,
@@ -192,8 +193,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
192193
} else {
193194
[sym::gen_future].into()
194195
},
195-
allow_for_await: [sym::async_iterator].into(),
196+
allow_for_await: [sym::async_gen_internals, sym::async_iterator].into(),
196197
allow_async_fn_traits: [sym::async_fn_traits].into(),
198+
allow_async_gen: [sym::async_gen_internals].into(),
197199
// FIXME(gen_blocks): how does `closure_track_caller`/`async_fn_track_caller`
198200
// interact with `gen`/`async gen` blocks
199201
allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
764764
) -> Ty<'tcx> {
765765
let tcx = self.tcx;
766766

767-
if let Some((_, [_arg])) = call_expr_and_args
767+
if let Some((_, [arg])) = call_expr_and_args
768768
&& let QPath::Resolved(_, path) = qpath
769769
&& let Res::Def(_, def_id) = path.res
770770
&& let Some(lang_item) = tcx.lang_items().from_def_id(def_id)
771771
{
772772
let code = match lang_item {
773+
LangItem::IntoFutureIntoFuture
774+
if expr.span.is_desugaring(DesugaringKind::Await) =>
775+
{
776+
Some(ObligationCauseCode::AwaitableExpr(arg.hir_id))
777+
}
773778
LangItem::IntoIterIntoIter | LangItem::IteratorNext
774779
if expr.span.is_desugaring(DesugaringKind::ForLoop) =>
775780
{

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
712712
self.write_resolution(hir_id, Ok((def_kind, def_id)));
713713

714714
let code = match lang_item {
715-
hir::LangItem::IntoFutureIntoFuture => {
716-
if let hir::Node::Expr(into_future_call) = self.tcx.parent_hir_node(hir_id)
717-
&& let hir::ExprKind::Call(_, [arg0]) = &into_future_call.kind
718-
{
719-
Some(ObligationCauseCode::AwaitableExpr(arg0.hir_id))
720-
} else {
721-
None
722-
}
723-
}
724715
hir::LangItem::TryTraitFromOutput
725716
| hir::LangItem::TryTraitFromResidual
726717
| hir::LangItem::TryTraitBranch => Some(ObligationCauseCode::QuestionMark),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ symbols! {
517517
async_fn_track_caller,
518518
async_fn_traits,
519519
async_for_loop,
520+
async_gen_internals,
520521
async_iterator,
521522
async_iterator_poll_next,
522523
async_trait_bounds,

src/tools/clippy/clippy_lints/src/large_futures.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
44
use clippy_utils::ty::implements_trait;
55
use rustc_abi::Size;
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Expr, ExprKind, LangItem, MatchSource, QPath};
7+
use rustc_hir::{Expr, ExprKind, LangItem, MatchSource};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_session::impl_lint_pass;
1010

@@ -58,7 +58,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeFuture {
5858
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
5959
if let ExprKind::Match(scrutinee, _, MatchSource::AwaitDesugar) = expr.kind
6060
&& let ExprKind::Call(func, [arg]) = scrutinee.kind
61-
&& let ExprKind::Path(QPath::LangItem(LangItem::IntoFutureIntoFuture, ..)) = func.kind
61+
&& let ExprKind::Path(qpath) = func.kind
62+
&& cx.tcx.qpath_is_lang_item(qpath, LangItem::IntoFutureIntoFuture)
6263
&& !expr.span.from_expansion()
6364
&& let ty = cx.typeck_results().expr_ty(arg)
6465
&& let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait()

src/tools/clippy/clippy_lints/src/unused_io_amount.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn should_lint<'a>(cx: &LateContext<'a>, mut inner: &'a hir::Expr<'a>) -> Option
194194
inner = unpack_match(inner);
195195
inner = unpack_try(inner);
196196
inner = unpack_call_chain(inner);
197-
inner = unpack_await(inner);
197+
inner = unpack_await(cx, inner);
198198
// we type-check it to get whether it's a read/write or their vectorized forms
199199
// and keep only the ones that are produce io amount
200200
check_io_mode(cx, inner)
@@ -277,13 +277,11 @@ fn unpack_match<'a>(mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
277277

278278
/// If `expr` is an (e).await, return the inner expression "e" that's being
279279
/// waited on. Otherwise return None.
280-
fn unpack_await<'a>(expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
280+
fn unpack_await<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
281281
if let ExprKind::Match(expr, _, hir::MatchSource::AwaitDesugar) = expr.kind
282282
&& let ExprKind::Call(func, [arg_0]) = expr.kind
283-
&& matches!(
284-
func.kind,
285-
ExprKind::Path(hir::QPath::LangItem(hir::LangItem::IntoFutureIntoFuture, ..))
286-
)
283+
&& let ExprKind::Path(qpath) = func.kind
284+
&& cx.tcx.qpath_is_lang_item(qpath, hir::LangItem::IntoFutureIntoFuture)
287285
{
288286
return arg_0;
289287
}

0 commit comments

Comments
 (0)