Skip to content

Commit 130a33a

Browse files
authored
Unrolled build for rust-lang#138670
Rollup merge of rust-lang#138670 - compiler-errors:remove-afidt, r=oli-obk Remove existing AFIDT implementation This experiment will need to be reworked differently; I don't think we'll be going with the `dyn* Future` approach that is currently implemented. r? oli-obk Fixes rust-lang#136286 Fixes rust-lang#137706 Fixes rust-lang#137895 Tracking: * rust-lang#133119
2 parents c4b38a5 + 93b31d9 commit 130a33a

File tree

18 files changed

+177
-301
lines changed

18 files changed

+177
-301
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
176176
.in_definition_order()
177177
// We only care about associated types.
178178
.filter(|item| item.kind == ty::AssocKind::Type)
179-
// No RPITITs -- even with `async_fn_in_dyn_trait`, they are implicit.
179+
// No RPITITs -- they're not dyn-compatible for now.
180180
.filter(|item| !item.is_impl_trait_in_trait())
181181
// If the associated type has a `where Self: Sized` bound,
182182
// we do not need to constrain the associated type.

compiler/rustc_middle/src/ty/instance.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,7 @@ impl<'tcx> Instance<'tcx> {
712712
..
713713
})
714714
);
715-
// We also need to generate a shim if this is an AFIT.
716-
let needs_rpitit_shim =
717-
tcx.return_position_impl_trait_in_trait_shim_data(def).is_some();
718-
if needs_track_caller_shim || needs_rpitit_shim {
715+
if needs_track_caller_shim {
719716
if tcx.is_closure_like(def) {
720717
debug!(
721718
" => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",

compiler/rustc_middle/src/ty/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ mod opaque_types;
149149
mod parameterized;
150150
mod predicate;
151151
mod region;
152-
mod return_position_impl_trait_in_trait;
153152
mod rvalue_scopes;
154153
mod structural_impls;
155154
#[allow(hidden_glob_reexports)]

compiler/rustc_middle/src/ty/return_position_impl_trait_in_trait.rs

-95
This file was deleted.

compiler/rustc_mir_transform/src/shim.rs

+2-48
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_hir::lang_items::LangItem;
88
use rustc_index::{Idx, IndexVec};
99
use rustc_middle::mir::*;
1010
use rustc_middle::query::Providers;
11-
use rustc_middle::ty::adjustment::PointerCoercion;
1211
use rustc_middle::ty::{
1312
self, CoroutineArgs, CoroutineArgsExt, EarlyBinder, GenericArgs, Ty, TyCtxt,
1413
};
@@ -718,12 +717,6 @@ fn build_call_shim<'tcx>(
718717

719718
let def_id = instance.def_id();
720719

721-
let rpitit_shim = if let ty::InstanceKind::ReifyShim(..) = instance {
722-
tcx.return_position_impl_trait_in_trait_shim_data(def_id)
723-
} else {
724-
None
725-
};
726-
727720
let sig = tcx.fn_sig(def_id);
728721
let sig = sig.map_bound(|sig| tcx.instantiate_bound_regions_with_erased(sig));
729722

@@ -779,30 +772,7 @@ fn build_call_shim<'tcx>(
779772
let mut local_decls = local_decls_for_sig(&sig, span);
780773
let source_info = SourceInfo::outermost(span);
781774

782-
let mut destination = Place::return_place();
783-
if let Some((rpitit_def_id, fn_args)) = rpitit_shim {
784-
let rpitit_args =
785-
fn_args.instantiate_identity().extend_to(tcx, rpitit_def_id, |param, _| {
786-
match param.kind {
787-
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
788-
ty::GenericParamDefKind::Type { .. }
789-
| ty::GenericParamDefKind::Const { .. } => {
790-
unreachable!("rpitit should have no addition ty/ct")
791-
}
792-
}
793-
});
794-
let dyn_star_ty = Ty::new_dynamic(
795-
tcx,
796-
tcx.item_bounds_to_existential_predicates(rpitit_def_id, rpitit_args),
797-
tcx.lifetimes.re_erased,
798-
ty::DynStar,
799-
);
800-
destination = local_decls.push(local_decls[RETURN_PLACE].clone()).into();
801-
local_decls[RETURN_PLACE].ty = dyn_star_ty;
802-
let mut inputs_and_output = sig.inputs_and_output.to_vec();
803-
*inputs_and_output.last_mut().unwrap() = dyn_star_ty;
804-
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
805-
}
775+
let destination = Place::return_place();
806776

807777
let rcvr_place = || {
808778
assert!(rcvr_adjustment.is_some());
@@ -921,23 +891,7 @@ fn build_call_shim<'tcx>(
921891
);
922892
}
923893
// BB #1/#2 - return
924-
// NOTE: If this is an RPITIT in dyn, we also want to coerce
925-
// the return type of the function into a `dyn*`.
926-
let stmts = if rpitit_shim.is_some() {
927-
vec![Statement {
928-
source_info,
929-
kind: StatementKind::Assign(Box::new((
930-
Place::return_place(),
931-
Rvalue::Cast(
932-
CastKind::PointerCoercion(PointerCoercion::DynStar, CoercionSource::Implicit),
933-
Operand::Move(destination),
934-
sig.output(),
935-
),
936-
))),
937-
}]
938-
} else {
939-
vec![]
940-
};
894+
let stmts = vec![];
941895
block(&mut blocks, stmts, TerminatorKind::Return, false);
942896
if let Some(Adjustment::RefMut) = rcvr_adjustment {
943897
// BB #3 - drop if closure panics

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+2-26
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::ops::ControlFlow;
99
use rustc_errors::FatalError;
1010
use rustc_hir as hir;
1111
use rustc_hir::def_id::DefId;
12-
use rustc_middle::bug;
1312
use rustc_middle::query::Providers;
1413
use rustc_middle::ty::{
1514
self, EarlyBinder, GenericArgs, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
@@ -807,31 +806,8 @@ fn contains_illegal_impl_trait_in_trait<'tcx>(
807806
let ty = tcx.liberate_late_bound_regions(fn_def_id, ty);
808807

809808
if tcx.asyncness(fn_def_id).is_async() {
810-
// FIXME(async_fn_in_dyn_trait): Think of a better way to unify these code paths
811-
// to issue an appropriate feature suggestion when users try to use AFIDT.
812-
// Obviously we must only do this once AFIDT is finished enough to actually be usable.
813-
if tcx.features().async_fn_in_dyn_trait() {
814-
let ty::Alias(ty::Projection, proj) = *ty.kind() else {
815-
bug!("expected async fn in trait to return an RPITIT");
816-
};
817-
assert!(tcx.is_impl_trait_in_trait(proj.def_id));
818-
819-
// FIXME(async_fn_in_dyn_trait): We should check that this bound is legal too,
820-
// and stop relying on `async fn` in the definition.
821-
for bound in tcx.item_bounds(proj.def_id).instantiate(tcx, proj.args) {
822-
if let Some(violation) = bound
823-
.visit_with(&mut IllegalRpititVisitor { tcx, allowed: Some(proj) })
824-
.break_value()
825-
{
826-
return Some(violation);
827-
}
828-
}
829-
830-
None
831-
} else {
832-
// Rendering the error as a separate `async-specific` message is better.
833-
Some(MethodViolationCode::AsyncFn)
834-
}
809+
// Rendering the error as a separate `async-specific` message is better.
810+
Some(MethodViolationCode::AsyncFn)
835811
} else {
836812
ty.visit_with(&mut IllegalRpititVisitor { tcx, allowed: None }).break_value()
837813
}

compiler/rustc_trait_selection/src/traits/project.rs

+1-57
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
77
use rustc_errors::ErrorGuaranteed;
88
use rustc_hir::def::DefKind;
99
use rustc_hir::lang_items::LangItem;
10+
use rustc_infer::infer::DefineOpaqueTypes;
1011
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
11-
use rustc_infer::infer::{DefineOpaqueTypes, RegionVariableOrigin};
1212
use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
1313
use rustc_middle::traits::select::OverflowError;
1414
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ImplSourceUserDefinedData};
@@ -18,8 +18,6 @@ use rustc_middle::ty::{
1818
};
1919
use rustc_middle::{bug, span_bug};
2020
use rustc_span::sym;
21-
use rustc_type_ir::elaborate;
22-
use thin_vec::thin_vec;
2321
use tracing::{debug, instrument};
2422

2523
use super::{
@@ -63,9 +61,6 @@ enum ProjectionCandidate<'tcx> {
6361
/// Bounds specified on an object type
6462
Object(ty::PolyProjectionPredicate<'tcx>),
6563

66-
/// Built-in bound for a dyn async fn in trait
67-
ObjectRpitit,
68-
6964
/// From an "impl" (or a "pseudo-impl" returned by select)
7065
Select(Selection<'tcx>),
7166
}
@@ -832,16 +827,6 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
832827
env_predicates,
833828
false,
834829
);
835-
836-
// `dyn Trait` automagically project their AFITs to `dyn* Future`.
837-
if tcx.is_impl_trait_in_trait(obligation.predicate.def_id)
838-
&& let Some(out_trait_def_id) = data.principal_def_id()
839-
&& let rpitit_trait_def_id = tcx.parent(obligation.predicate.def_id)
840-
&& elaborate::supertrait_def_ids(tcx, out_trait_def_id)
841-
.any(|trait_def_id| trait_def_id == rpitit_trait_def_id)
842-
{
843-
candidate_set.push_candidate(ProjectionCandidate::ObjectRpitit);
844-
}
845830
}
846831

847832
#[instrument(
@@ -1273,8 +1258,6 @@ fn confirm_candidate<'cx, 'tcx>(
12731258
ProjectionCandidate::Select(impl_source) => {
12741259
confirm_select_candidate(selcx, obligation, impl_source)
12751260
}
1276-
1277-
ProjectionCandidate::ObjectRpitit => confirm_object_rpitit_candidate(selcx, obligation),
12781261
};
12791262

12801263
// When checking for cycle during evaluation, we compare predicates with
@@ -2070,45 +2053,6 @@ fn confirm_impl_candidate<'cx, 'tcx>(
20702053
}
20712054
}
20722055

2073-
fn confirm_object_rpitit_candidate<'cx, 'tcx>(
2074-
selcx: &mut SelectionContext<'cx, 'tcx>,
2075-
obligation: &ProjectionTermObligation<'tcx>,
2076-
) -> Progress<'tcx> {
2077-
let tcx = selcx.tcx();
2078-
let mut obligations = thin_vec![];
2079-
2080-
// Compute an intersection lifetime for all the input components of this GAT.
2081-
let intersection =
2082-
selcx.infcx.next_region_var(RegionVariableOrigin::MiscVariable(obligation.cause.span));
2083-
for component in obligation.predicate.args {
2084-
match component.unpack() {
2085-
ty::GenericArgKind::Lifetime(lt) => {
2086-
obligations.push(obligation.with(tcx, ty::OutlivesPredicate(lt, intersection)));
2087-
}
2088-
ty::GenericArgKind::Type(ty) => {
2089-
obligations.push(obligation.with(tcx, ty::OutlivesPredicate(ty, intersection)));
2090-
}
2091-
ty::GenericArgKind::Const(_ct) => {
2092-
// Consts have no outlives...
2093-
}
2094-
}
2095-
}
2096-
2097-
Progress {
2098-
term: Ty::new_dynamic(
2099-
tcx,
2100-
tcx.item_bounds_to_existential_predicates(
2101-
obligation.predicate.def_id,
2102-
obligation.predicate.args,
2103-
),
2104-
intersection,
2105-
ty::DynStar,
2106-
)
2107-
.into(),
2108-
obligations,
2109-
}
2110-
}
2111-
21122056
// Get obligations corresponding to the predicates from the where-clause of the
21132057
// associated type itself.
21142058
fn assoc_ty_own_obligations<'cx, 'tcx>(

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

-6
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
616616
for assoc_type in assoc_types {
617617
let defs: &ty::Generics = tcx.generics_of(assoc_type);
618618

619-
// When `async_fn_in_dyn_trait` is enabled, we don't need to check the
620-
// RPITIT for compatibility, since it's not provided by the user.
621-
if tcx.features().async_fn_in_dyn_trait() && tcx.is_impl_trait_in_trait(assoc_type) {
622-
continue;
623-
}
624-
625619
if !defs.own_params.is_empty() {
626620
tcx.dcx().span_delayed_bug(
627621
obligation.cause.span,

compiler/rustc_ty_utils/src/abi.rs

-25
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,6 @@ fn fn_sig_for_fn_abi<'tcx>(
5555
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
5656
}
5757

58-
// Modify `fn() -> impl Future` to `fn() -> dyn* Future`.
59-
if let ty::InstanceKind::ReifyShim(def_id, _) = instance.def
60-
&& let Some((rpitit_def_id, fn_args)) =
61-
tcx.return_position_impl_trait_in_trait_shim_data(def_id)
62-
{
63-
let fn_args = fn_args.instantiate(tcx, args);
64-
let rpitit_args =
65-
fn_args.extend_to(tcx, rpitit_def_id, |param, _| match param.kind {
66-
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
67-
ty::GenericParamDefKind::Type { .. }
68-
| ty::GenericParamDefKind::Const { .. } => {
69-
unreachable!("rpitit should have no addition ty/ct")
70-
}
71-
});
72-
let dyn_star_ty = Ty::new_dynamic(
73-
tcx,
74-
tcx.item_bounds_to_existential_predicates(rpitit_def_id, rpitit_args),
75-
tcx.lifetimes.re_erased,
76-
ty::DynStar,
77-
);
78-
let mut inputs_and_output = sig.inputs_and_output.to_vec();
79-
*inputs_and_output.last_mut().unwrap() = dyn_star_ty;
80-
sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output);
81-
}
82-
8358
sig
8459
}
8560
ty::Closure(def_id, args) => {

tests/crashes/136286.rs

-7
This file was deleted.

0 commit comments

Comments
 (0)