Skip to content

Commit c032527

Browse files
committed
stabilize feature(trait_upcasting)
1 parent c26db43 commit c032527

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
@@ -398,6 +398,9 @@ declare_features! (
398398
/// Allows `#[track_caller]` to be used which provides
399399
/// accurate caller location reporting during panic (RFC 2091).
400400
(accepted, track_caller, "1.46.0", Some(47809)),
401+
/// Allows dyn upcasting trait objects via supertraits.
402+
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
403+
(accepted, trait_upcasting, "CURRENT_RUSTC_VERSION", Some(65991)),
401404
/// Allows #[repr(transparent)] on univariant enums (RFC 2645).
402405
(accepted, transparent_enums, "1.42.0", Some(60405)),
403406
/// Allows indexing tuples.

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,6 @@ declare_features! (
623623
(unstable, thread_local, "1.0.0", Some(29594)),
624624
/// Allows defining `trait X = A + B;` alias items.
625625
(unstable, trait_alias, "1.24.0", Some(41517)),
626-
/// Allows dyn upcasting trait objects via supertraits.
627-
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
628-
(unstable, trait_upcasting, "1.56.0", Some(65991)),
629626
/// Allows for transmuting between arrays with sizes that contain generic consts.
630627
(unstable, transmute_generic_consts, "1.70.0", Some(109929)),
631628
/// 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
@@ -602,7 +602,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
602602
)];
603603

604604
let mut has_unsized_tuple_coercion = false;
605-
let mut has_trait_upcasting_coercion = None;
606605

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

702-
if let Some((sub, sup)) = has_trait_upcasting_coercion
703-
&& !self.tcx().features().trait_upcasting()
704-
{
705-
// Renders better when we erase regions, since they're not really the point here.
706-
let (sub, sup) = self.tcx.erase_regions((sub, sup));
707-
let mut err = feature_err(
708-
&self.tcx.sess,
709-
sym::trait_upcasting,
710-
self.cause.span,
711-
format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"),
712-
);
713-
err.note(format!("required when coercing `{source}` into `{target}`"));
714-
err.emit();
715-
}
716-
717694
if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion() {
718695
feature_err(
719696
&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> {
@@ -898,54 +894,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
898894
})
899895
}
900896

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

1027966
for (idx, upcast_trait_ref) in
1028967
util::supertraits(self.tcx(), source_trait_ref).enumerate()

0 commit comments

Comments
 (0)