Skip to content

Commit da9a85a

Browse files
committed
stabilize feature(trait_upcasting)
1 parent 942db67 commit da9a85a

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
@@ -634,9 +634,6 @@ declare_features! (
634634
(unstable, thread_local, "1.0.0", Some(29594)),
635635
/// Allows defining `trait X = A + B;` alias items.
636636
(unstable, trait_alias, "1.24.0", Some(41517)),
637-
/// Allows dyn upcasting trait objects via supertraits.
638-
/// Dyn upcasting is casting, e.g., `dyn Foo -> dyn Bar` where `Foo: Bar`.
639-
(unstable, trait_upcasting, "1.56.0", Some(65991)),
640637
/// Allows for transmuting between arrays with sizes that contain generic consts.
641638
(unstable, transmute_generic_consts, "1.70.0", Some(109929)),
642639
/// 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
@@ -605,7 +605,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
605605
)];
606606

607607
let mut has_unsized_tuple_coercion = false;
608-
let mut has_trait_upcasting_coercion = None;
609608

610609
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
611610
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
@@ -690,13 +689,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
690689
// these here and emit a feature error if coercion doesn't fail
691690
// due to another reason.
692691
match impl_source {
693-
traits::ImplSource::Builtin(
694-
BuiltinImplSource::TraitUpcasting { .. },
695-
_,
696-
) => {
697-
has_trait_upcasting_coercion =
698-
Some((trait_pred.self_ty(), trait_pred.trait_ref.args.type_at(1)));
699-
}
700692
traits::ImplSource::Builtin(BuiltinImplSource::TupleUnsizing, _) => {
701693
has_unsized_tuple_coercion = true;
702694
}
@@ -707,21 +699,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
707699
}
708700
}
709701

710-
if let Some((sub, sup)) = has_trait_upcasting_coercion
711-
&& !self.tcx().features().trait_upcasting()
712-
{
713-
// Renders better when we erase regions, since they're not really the point here.
714-
let (sub, sup) = self.tcx.erase_regions((sub, sup));
715-
let mut err = feature_err(
716-
&self.tcx.sess,
717-
sym::trait_upcasting,
718-
self.cause.span,
719-
format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"),
720-
);
721-
err.note(format!("required when coercing `{source}` into `{target}`"));
722-
err.emit();
723-
}
724-
725702
if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion() {
726703
feature_err(
727704
&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
@@ -29,6 +29,7 @@
2929
#![allow(rustc::diagnostic_outside_of_impl)]
3030
#![allow(rustc::potential_query_instability)]
3131
#![allow(rustc::untranslatable_diagnostic)]
32+
#![cfg_attr(bootstrap, feature(trait_upcasting))]
3233
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3334
#![doc(rust_logo)]
3435
#![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, 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> {
@@ -904,54 +900,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
904900
})
905901
}
906902

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