allow_internal_unstable(min_specialization) on newtype_index · rust-lang/rust@eb63d3a (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@ mod newtype;
36 36 feature = "nightly",
37 37 allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)
38 38 )]
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))]
39 42 pub fn newtype_index(input: TokenStream) -> TokenStream {
40 43 newtype::newtype(input)
41 44 }
Original file line number Diff line number Diff line change
@@ -142,23 +142,29 @@ pub fn translate_args_with_cause<'tcx>(
142 142 pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, DefId)) -> bool {
143 143 // The feature gate should prevent introducing new specializations, but not
144 144 // 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
145 149 let features = tcx.features();
146 150 let specialization_enabled = features.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 +}
153 159 }
154 -}
155 160
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 +}
162 168 }
163 169 }
164 170