Rollup merge of #119963 - clubby789:spec-allow-internal-unstable, r=compiler-errors
Fix `allow_internal_unstable` for `(min_)specialization` Fixes #119950 Blocked on #119949 (comment doesn't make sense until that merges) I'd like to follow this up and look for more instances of not properly checking spans for features but I wanted to fix the motivating issue.
This commit is contained in:
commit
0891cb4d81
@ -39,6 +39,9 @@ mod newtype;
|
|||||||
feature = "nightly",
|
feature = "nightly",
|
||||||
allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)
|
allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)
|
||||||
)]
|
)]
|
||||||
|
// FIXME: Remove the above comment about `min_specialization` once bootstrap is bumped,
|
||||||
|
// and the corresponding one on SpecOptionPartialEq
|
||||||
|
#[cfg_attr(all(feature = "nightly", not(bootstrap)), allow_internal_unstable(min_specialization))]
|
||||||
pub fn newtype_index(input: TokenStream) -> TokenStream {
|
pub fn newtype_index(input: TokenStream) -> TokenStream {
|
||||||
newtype::newtype(input)
|
newtype::newtype(input)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
|
|||||||
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
|
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
|
||||||
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
|
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
|
||||||
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
|
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::util;
|
||||||
use super::SelectionContext;
|
use super::SelectionContext;
|
||||||
@ -142,10 +142,30 @@ pub fn translate_args_with_cause<'tcx>(
|
|||||||
pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, DefId)) -> bool {
|
pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, DefId)) -> bool {
|
||||||
// The feature gate should prevent introducing new specializations, but not
|
// The feature gate should prevent introducing new specializations, but not
|
||||||
// taking advantage of upstream ones.
|
// taking advantage of upstream ones.
|
||||||
|
// If specialization is enabled for this crate then no extra checks are needed.
|
||||||
|
// If it's not, and either of the `impl`s is local to this crate, then this definitely
|
||||||
|
// isn't specializing - unless specialization is enabled for the `impl` span,
|
||||||
|
// e.g. if it comes from an `allow_internal_unstable` macro
|
||||||
let features = tcx.features();
|
let features = tcx.features();
|
||||||
let specialization_enabled = features.specialization || features.min_specialization;
|
let specialization_enabled = features.specialization || features.min_specialization;
|
||||||
if !specialization_enabled && (impl1_def_id.is_local() || impl2_def_id.is_local()) {
|
if !specialization_enabled {
|
||||||
return false;
|
if 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 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:
|
// We determine whether there's a subset relationship by:
|
||||||
|
18
tests/ui/specialization/allow_internal_unstable.rs
Normal file
18
tests/ui/specialization/allow_internal_unstable.rs
Normal file
@ -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! {}
|
Loading…
x
Reference in New Issue
Block a user