Skip to content

Commit

Permalink
Add min_specialization feature
Browse files Browse the repository at this point in the history
Currently the only difference between it and `specialization` is that
it only allows specializing functions.
  • Loading branch information
matthewjasper committed Mar 15, 2020
1 parent 7cdbc87 commit a62dd0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/librustc_ast_passes/feature_gate.rs
Expand Up @@ -542,15 +542,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
if let ast::Defaultness::Default(_) = i.kind.defaultness() {
gate_feature_post!(&self, specialization, i.span, "specialization is unstable");
}

match i.kind {
let is_fn = match i.kind {
ast::AssocItemKind::Fn(_, ref sig, _, _) => {
if let (ast::Const::Yes(_), AssocCtxt::Trait) = (sig.header.constness, ctxt) {
gate_feature_post!(&self, const_fn, i.span, "const fn is unstable");
}
true
}
ast::AssocItemKind::TyAlias(_, ref generics, _, ref ty) => {
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
Expand All @@ -565,8 +562,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
self.check_impl_trait(ty);
}
self.check_gat(generics, i.span);
false
}
_ => {}
_ => false,
};
if let ast::Defaultness::Default(_) = i.kind.defaultness() {
// Limit `min_specialization` to only specializing functions.
gate_feature_fn!(
&self,
|x: &Features| x.specialization || (is_fn && x.min_specialization),
i.span,
sym::specialization,
"specialization is unstable"
);
}
visit::walk_assoc_item(self, i, ctxt)
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_feature/active.rs
Expand Up @@ -301,6 +301,11 @@ declare_features! (
/// Allows specialization of implementations (RFC 1210).
(active, specialization, "1.7.0", Some(31844), None),

/// A minimal, sound subset of specialization intended to be used by the
/// standard library until the soundness issues with specialization
/// are fixed.
(active, min_specialization, "1.7.0", Some(31844), None),

/// Allows using `#[naked]` on functions.
(active, naked_functions, "1.9.0", Some(32408), None),

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_trait_selection/traits/specialize/mod.rs
Expand Up @@ -161,7 +161,9 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,

// The feature gate should prevent introducing new specializations, but not
// taking advantage of upstream ones.
if !tcx.features().specialization && (impl1_def_id.is_local() || impl2_def_id.is_local()) {
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;
}

Expand Down

0 comments on commit a62dd0e

Please sign in to comment.