Skip to content

Commit

Permalink
Fix allow_internal_unstable for (min_)specialization
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Jan 14, 2024
1 parent 1d8d7b1 commit 0529ccf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
20 changes: 17 additions & 3 deletions compiler/rustc_trait_selection/src/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
use rustc_span::{sym, ErrorGuaranteed, Span, DUMMY_SP};

use super::util;
use super::SelectionContext;
Expand Down Expand Up @@ -144,8 +144,22 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
// taking advantage of upstream ones.
let features = tcx.features();
let specialization_enabled = features.specialization || features.min_specialization;
if !specialization_enabled && (impl1_def_id.is_local() || impl2_def_id.is_local()) {
return false;
if !specialization_enabled && impl1_def_id.is_local() {
let span = tcx.def_span(impl1_def_id);
if !span.allows_unstable(sym::specialization)
&& !span.allows_unstable(sym::min_specialization)
{
return false;
}
}

if !specialization_enabled && impl2_def_id.is_local() {
let span = tcx.def_span(impl2_def_id);
if !span.allows_unstable(sym::specialization)
&& !span.allows_unstable(sym::min_specialization)
{
return false;
}
}

// We determine whether there's a subset relationship by:
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/specialization/allow_internal_unstable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// check-pass
// test for #119950
// compile-flags: --crate-type lib

#![allow(internal_features)]
#![feature(allow_internal_unstable)]

#[allow_internal_unstable(min_specialization)]
macro_rules! test {
() => {
struct T<U>(U);
trait Tr {}
impl<U> Tr for T<U> {}
impl Tr for T<u8> {}
}
}

test! {}

0 comments on commit 0529ccf

Please sign in to comment.