Skip to content

Commit eb63d3a

Browse files
committed
allow_internal_unstable(min_specialization) on newtype_index
1 parent 0529ccf commit eb63d3a

File tree

2 files changed

+22
-13
lines changed
  • compiler
    • rustc_index_macros/src
    • rustc_trait_selection/src/traits/specialize

2 files changed

+22
-13
lines changed

compiler/rustc_index_macros/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ mod newtype;
3636
feature = "nightly",
3737
allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)
3838
)]
39+
// FIXME: Remove the above comment about `min_specialization` once bootstrap is bumped,
40+
// and the corresponding one on SpecOptionPartialEq
41+
#[cfg_attr(all(feature = "nightly", not(bootstrap)), allow_internal_unstable(min_specialization))]
3942
pub fn newtype_index(input: TokenStream) -> TokenStream {
4043
newtype::newtype(input)
4144
}

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,29 @@ pub fn translate_args_with_cause<'tcx>(
142142
pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, DefId)) -> bool {
143143
// The feature gate should prevent introducing new specializations, but not
144144
// taking advantage of upstream ones.
145+
// If specialization is enabled for this crate then no extra checks are needed.
146+
// If it's not, and either of the `impl`s is local to this crate, then this definitely
147+
// isn't specializing - unless specialization is enabled for the `impl` span,
148+
// e.g. if it comes from an `allow_internal_unstable` macro
145149
let features = tcx.features();
146150
let specialization_enabled = features.specialization || features.min_specialization;
147-
if !specialization_enabled && impl1_def_id.is_local() {
148-
let span = tcx.def_span(impl1_def_id);
149-
if !span.allows_unstable(sym::specialization)
150-
&& !span.allows_unstable(sym::min_specialization)
151-
{
152-
return false;
151+
if !specialization_enabled {
152+
if impl1_def_id.is_local() {
153+
let span = tcx.def_span(impl1_def_id);
154+
if !span.allows_unstable(sym::specialization)
155+
&& !span.allows_unstable(sym::min_specialization)
156+
{
157+
return false;
158+
}
153159
}
154-
}
155160

156-
if !specialization_enabled && impl2_def_id.is_local() {
157-
let span = tcx.def_span(impl2_def_id);
158-
if !span.allows_unstable(sym::specialization)
159-
&& !span.allows_unstable(sym::min_specialization)
160-
{
161-
return false;
161+
if impl2_def_id.is_local() {
162+
let span = tcx.def_span(impl2_def_id);
163+
if !span.allows_unstable(sym::specialization)
164+
&& !span.allows_unstable(sym::min_specialization)
165+
{
166+
return false;
167+
}
162168
}
163169
}
164170

0 commit comments

Comments
 (0)