Skip to content

Commit 51b7837

Browse files
committed
stabilize feature(trait_upcasting)
1 parent 419b3e2 commit 51b7837

File tree

6 files changed

+6
-90
lines changed

6 files changed

+6
-90
lines changed

compiler/rustc_feature/src/accepted.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ declare_features! (
400400
/// Allows `#[track_caller]` to be used which provides
401401
/// accurate caller location reporting during panic (RFC 2091).
402402
(accepted, track_caller, "1.46.0", Some(47809)),
403+
/// Allows dyn upcasting trait objects via supertraits.
404+
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
405+
(accepted, trait_upcasting, "CURRENT_RUSTC_VERSION", Some(65991)),
403406
/// Allows #[repr(transparent)] on univariant enums (RFC 2645).
404407
(accepted, transparent_enums, "1.42.0", Some(60405)),
405408
/// Allows indexing tuples.

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,6 @@ declare_features! (
622622
(unstable, thread_local, "1.0.0", Some(29594)),
623623
/// Allows defining `trait X = A + B;` alias items.
624624
(unstable, trait_alias, "1.24.0", Some(41517)),
625-
/// Allows dyn upcasting trait objects via supertraits.
626-
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
627-
(unstable, trait_upcasting, "1.56.0", Some(65991)),
628625
/// Allows for transmuting between arrays with sizes that contain generic consts.
629626
(unstable, transmute_generic_consts, "1.70.0", Some(109929)),
630627
/// Allows #[repr(transparent)] on unions (RFC 2645).

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
598598
)];
599599

600600
let mut has_unsized_tuple_coercion = false;
601-
let mut has_trait_upcasting_coercion = None;
602601

603602
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
604603
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
@@ -683,13 +682,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
683682
// these here and emit a feature error if coercion doesn't fail
684683
// due to another reason.
685684
match impl_source {
686-
traits::ImplSource::Builtin(
687-
BuiltinImplSource::TraitUpcasting { .. },
688-
_,
689-
) => {
690-
has_trait_upcasting_coercion =
691-
Some((trait_pred.self_ty(), trait_pred.trait_ref.args.type_at(1)));
692-
}
693685
traits::ImplSource::Builtin(BuiltinImplSource::TupleUnsizing, _) => {
694686
has_unsized_tuple_coercion = true;
695687
}
@@ -700,21 +692,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
700692
}
701693
}
702694

703-
if let Some((sub, sup)) = has_trait_upcasting_coercion
704-
&& !self.tcx().features().trait_upcasting()
705-
{
706-
// Renders better when we erase regions, since they're not really the point here.
707-
let (sub, sup) = self.tcx.erase_regions((sub, sup));
708-
let mut err = feature_err(
709-
&self.tcx.sess,
710-
sym::trait_upcasting,
711-
self.cause.span,
712-
format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"),
713-
);
714-
err.note(format!("required when coercing `{source}` into `{target}`"));
715-
err.emit();
716-
}
717-
718695
if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion() {
719696
feature_err(
720697
&self.tcx.sess,

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
// tidy-alphabetical-start
2323
#![allow(internal_features)]
24+
#![cfg_attr(bootstrap, feature(trait_upcasting))]
2425
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2526
#![doc(rust_logo)]
2627
#![feature(array_windows)]
@@ -32,7 +33,6 @@
3233
#![feature(let_chains)]
3334
#![feature(rustc_attrs)]
3435
#![feature(rustdoc_internals)]
35-
#![feature(trait_upcasting)]
3636
#![warn(unreachable_pub)]
3737
// tidy-alphabetical-end
3838

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![allow(rustc::diagnostic_outside_of_impl)]
2929
#![allow(rustc::potential_query_instability)]
3030
#![allow(rustc::untranslatable_diagnostic)]
31+
#![cfg_attr(bootstrap, feature(trait_upcasting))]
3132
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3233
#![doc(rust_logo)]
3334
#![feature(allocator_api)]
@@ -56,7 +57,6 @@
5657
#![feature(ptr_alignment_type)]
5758
#![feature(rustc_attrs)]
5859
#![feature(rustdoc_internals)]
59-
#![feature(trait_upcasting)]
6060
#![feature(trusted_len)]
6161
#![feature(try_blocks)]
6262
#![feature(try_trait_v2)]

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

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use hir::LangItem;
1212
use hir::def_id::DefId;
1313
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
1414
use rustc_hir as hir;
15-
use rustc_infer::traits::{
16-
Obligation, ObligationCause, PolyTraitObligation, PredicateObligations, SelectionError,
17-
};
15+
use rustc_infer::traits::{Obligation, PolyTraitObligation, SelectionError};
1816
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
1917
use rustc_middle::ty::{self, ToPolyTraitRef, Ty, TypeVisitableExt, TypingMode};
2018
use rustc_middle::{bug, span_bug};
@@ -23,8 +21,6 @@ use tracing::{debug, instrument, trace};
2321

2422
use super::SelectionCandidate::*;
2523
use super::{BuiltinImplConditions, SelectionCandidateSet, SelectionContext, TraitObligationStack};
26-
use crate::traits;
27-
use crate::traits::query::evaluate_obligation::InferCtxtExt;
2824
use crate::traits::util;
2925

3026
impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
@@ -903,54 +899,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
903899
})
904900
}
905901

906-
/// Temporary migration for #89190
907-
fn need_migrate_deref_output_trait_object(
908-
&mut self,
909-
ty: Ty<'tcx>,
910-
param_env: ty::ParamEnv<'tcx>,
911-
cause: &ObligationCause<'tcx>,
912-
) -> Option<ty::PolyExistentialTraitRef<'tcx>> {
913-
// Don't drop any candidates in intercrate mode, as it's incomplete.
914-
// (Not that it matters, since `Unsize` is not a stable trait.)
915-
//
916-
// FIXME(@lcnr): This should probably only trigger during analysis,
917-
// disabling candidates during codegen is also questionable.
918-
if let TypingMode::Coherence = self.infcx.typing_mode() {
919-
return None;
920-
}
921-
922-
let tcx = self.tcx();
923-
if tcx.features().trait_upcasting() {
924-
return None;
925-
}
926-
927-
// <ty as Deref>
928-
let trait_ref = ty::TraitRef::new(tcx, tcx.lang_items().deref_trait()?, [ty]);
929-
930-
let obligation =
931-
traits::Obligation::new(tcx, cause.clone(), param_env, ty::Binder::dummy(trait_ref));
932-
if !self.infcx.predicate_may_hold(&obligation) {
933-
return None;
934-
}
935-
936-
self.infcx.probe(|_| {
937-
let ty = traits::normalize_projection_ty(
938-
self,
939-
param_env,
940-
ty::AliasTy::new_from_args(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
941-
cause.clone(),
942-
0,
943-
// We're *intentionally* throwing these away,
944-
// since we don't actually use them.
945-
&mut PredicateObligations::new(),
946-
)
947-
.as_type()
948-
.unwrap();
949-
950-
if let ty::Dynamic(data, ..) = ty.kind() { data.principal() } else { None }
951-
})
952-
}
953-
954902
/// Searches for unsizing that might apply to `obligation`.
955903
fn assemble_candidates_for_unsizing(
956904
&mut self,
@@ -1019,15 +967,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1019967
let principal_a = a_data.principal().unwrap();
1020968
let target_trait_did = principal_def_id_b.unwrap();
1021969
let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
1022-
if let Some(deref_trait_ref) = self.need_migrate_deref_output_trait_object(
1023-
source,
1024-
obligation.param_env,
1025-
&obligation.cause,
1026-
) {
1027-
if deref_trait_ref.def_id() == target_trait_did {
1028-
return;
1029-
}
1030-
}
1031970

1032971
for (idx, upcast_trait_ref) in
1033972
util::supertraits(self.tcx(), source_trait_ref).enumerate()

0 commit comments

Comments
 (0)