Skip to content

Commit c35e984

Browse files
Relax CallOnceFuture/CallRefFuture bound from Future to IntoFuture
1 parent cf2df68 commit c35e984

File tree

10 files changed

+28
-15
lines changed

10 files changed

+28
-15
lines changed

Diff for: compiler/rustc_hir/src/lang_items.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ language_item_table! {
241241
FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
242242
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
243243
FutureOutput, sym::future_output, future_output, Target::AssocTy, GenericRequirement::Exact(0);
244+
IntoFuture, sym::into_future, into_future_trait, Target::Trait, GenericRequirement::Exact(0);
245+
IntoFutureOutput, sym::into_future_output, into_future_output, Target::AssocTy, GenericRequirement::Exact(0);
246+
IntoFutureIntoFuture, sym::into_future_into_future, into_future_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
244247
AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
245248

246249
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
@@ -377,7 +380,6 @@ language_item_table! {
377380
ControlFlowContinue, sym::Continue, cf_continue_variant, Target::Variant, GenericRequirement::None;
378381
ControlFlowBreak, sym::Break, cf_break_variant, Target::Variant, GenericRequirement::None;
379382

380-
IntoFutureIntoFuture, sym::into_future, into_future_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
381383
IntoIterIntoIter, sym::into_iter, into_iter_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
382384
IteratorNext, sym::next, next_fn, Target::Method(MethodKind::Trait { body: false}), GenericRequirement::None;
383385

Diff for: compiler/rustc_middle/src/ty/context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ fn trait_lang_item_to_lang_item(lang_item: TraitSolverLangItem) -> LangItem {
610610
TraitSolverLangItem::FusedIterator => LangItem::FusedIterator,
611611
TraitSolverLangItem::Future => LangItem::Future,
612612
TraitSolverLangItem::FutureOutput => LangItem::FutureOutput,
613+
TraitSolverLangItem::IntoFuture => LangItem::IntoFuture,
614+
TraitSolverLangItem::IntoFutureOutput => LangItem::IntoFutureOutput,
613615
TraitSolverLangItem::Iterator => LangItem::Iterator,
614616
TraitSolverLangItem::Metadata => LangItem::Metadata,
615617
TraitSolverLangItem::Option => LangItem::Option,

Diff for: compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
//! However, what happens when we call `closure` with `AsyncFnOnce` (or `FnOnce`,
3232
//! since all async closures implement that too)? Well, recall the signature:
3333
//! ```
34-
//! use std::future::Future;
34+
//! use std::future::IntoFuture;
3535
//! pub trait AsyncFnOnce<Args>
3636
//! {
37-
//! type CallOnceFuture: Future<Output = Self::Output>;
37+
//! type CallOnceFuture: IntoFuture<Output = Self::Output>;
3838
//! type Output;
3939
//! fn async_call_once(
4040
//! self,

Diff for: compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,15 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
458458
ty::FnDef(..) | ty::FnPtr(..) => {
459459
let bound_sig = self_ty.fn_sig(cx);
460460
let sig = bound_sig.skip_binder();
461-
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
461+
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::IntoFuture);
462462
// `FnDef` and `FnPtr` only implement `AsyncFn*` when their
463463
// return type implements `Future`.
464464
let nested = vec![
465465
bound_sig
466466
.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()]))
467467
.upcast(cx),
468468
];
469-
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
469+
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::IntoFutureOutput);
470470
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
471471
Ok((
472472
bound_sig.rebind(AsyncCallableRelevantTypes {
@@ -481,7 +481,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
481481
let args = args.as_closure();
482482
let bound_sig = args.sig();
483483
let sig = bound_sig.skip_binder();
484-
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
484+
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::IntoFuture);
485485
// `Closure`s only implement `AsyncFn*` when their return type
486486
// implements `Future`.
487487
let mut nested = vec![
@@ -517,7 +517,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
517517
);
518518
}
519519

520-
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
520+
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::IntoFutureOutput);
521521
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
522522
Ok((
523523
bound_sig.rebind(AsyncCallableRelevantTypes {

Diff for: compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ symbols! {
10421042
integral,
10431043
into_async_iter_into_iter,
10441044
into_future,
1045+
into_future_into_future,
1046+
into_future_output,
10451047
into_iter,
10461048
intra_doc_pointers,
10471049
intrinsics,

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,8 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
18771877
let term = match item_name {
18781878
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
18791879
sym::Output => {
1880-
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
1880+
let future_output_def_id =
1881+
tcx.require_lang_item(LangItem::IntoFutureOutput, None);
18811882
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
18821883
}
18831884
name => bug!("no such associated type: {name}"),
@@ -1910,7 +1911,8 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
19101911
let term = match item_name {
19111912
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
19121913
sym::Output => {
1913-
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
1914+
let future_output_def_id =
1915+
tcx.require_lang_item(LangItem::IntoFutureOutput, None);
19141916
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
19151917
}
19161918
name => bug!("no such associated type: {name}"),

Diff for: compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
951951
// traits expressly allow the user to write. To fix this correctly,
952952
// we'd need to instantiate trait bounds before we get to selection,
953953
// like the new trait solver does.
954-
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
954+
let future_trait_def_id = tcx.require_lang_item(LangItem::IntoFuture, None);
955955
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
956956
nested.push(obligation.with(
957957
tcx,
@@ -973,7 +973,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
973973

974974
// We must additionally check that the return type impls `Future`.
975975
// See FIXME in last branch for why we instantiate the binder eagerly.
976-
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
976+
let future_trait_def_id = tcx.require_lang_item(LangItem::IntoFuture, None);
977977
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
978978
nested.push(obligation.with(
979979
tcx,

Diff for: compiler/rustc_type_ir/src/lang_items.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub enum TraitSolverLangItem {
2626
FusedIterator,
2727
Future,
2828
FutureOutput,
29+
IntoFuture,
30+
IntoFutureOutput,
2931
Iterator,
3032
Metadata,
3133
Option,

Diff for: library/core/src/future/into_future.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ use crate::future::Future;
105105
message = "`{Self}` is not a future",
106106
note = "{Self} must be a future or must implement `IntoFuture` to be awaited"
107107
)]
108+
#[cfg_attr(not(bootstrap), lang = "into_future")]
108109
pub trait IntoFuture {
109110
/// The output that the future will produce on completion.
110111
#[stable(feature = "into_future", since = "1.64.0")]
112+
#[cfg_attr(not(bootstrap), lang = "into_future_output")]
111113
type Output;
112114

113115
/// Which kind of future are we turning this into?
@@ -130,7 +132,8 @@ pub trait IntoFuture {
130132
/// # }
131133
/// ```
132134
#[stable(feature = "into_future", since = "1.64.0")]
133-
#[lang = "into_future"]
135+
#[cfg_attr(not(bootstrap), lang = "into_future_into_future")]
136+
#[cfg_attr(bootstrap, lang = "into_future")]
134137
fn into_future(self) -> Self::IntoFuture;
135138
}
136139

Diff for: library/core/src/ops/async_function.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::future::Future;
1+
use crate::future::IntoFuture;
22
use crate::marker::Tuple;
33

44
/// An async-aware version of the [`Fn`](crate::ops::Fn) trait.
@@ -27,7 +27,7 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
2727
/// Future returned by [`AsyncFnMut::async_call_mut`] and [`AsyncFn::async_call`].
2828
#[unstable(feature = "async_fn_traits", issue = "none")]
2929
#[lang = "call_ref_future"]
30-
type CallRefFuture<'a>: Future<Output = Self::Output>
30+
type CallRefFuture<'a>: IntoFuture<Output = Self::Output>
3131
where
3232
Self: 'a;
3333

@@ -48,7 +48,7 @@ pub trait AsyncFnOnce<Args: Tuple> {
4848
/// Future returned by [`AsyncFnOnce::async_call_once`].
4949
#[unstable(feature = "async_fn_traits", issue = "none")]
5050
#[lang = "call_once_future"]
51-
type CallOnceFuture: Future<Output = Self::Output>;
51+
type CallOnceFuture: IntoFuture<Output = Self::Output>;
5252

5353
/// Output type of the called closure's future.
5454
#[unstable(feature = "async_fn_traits", issue = "none")]

0 commit comments

Comments
 (0)