Skip to content

Commit

Permalink
Unrolled build for rust-lang#120870
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#120870 - Zalathar:allow-min-spec, r=oli-obk

Allow restricted trait impls under `#[allow_internal_unstable(min_specialization)]`

This is a follow-up to rust-lang#119963 and a companion to rust-lang#120866, though it can land independently from the latter.

---

We have several compiler crates that only enable `#[feature(min_specialization)]` because it is required by their expansions of `newtype_index!`, in order to implement traits marked with `#[rustc_specialization_trait]`.

This PR allows those traits to be implemented internally by macros with `#[allow_internal_unstable(min_specialization)]`, without needing specialization to be enabled in the enclosing crate.
  • Loading branch information
rust-timer authored Feb 10, 2024
2 parents 232919c + a2479a4 commit 84c3ce2
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(negative_impls)]
#![feature(stmt_expr_attributes)]

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(array_windows)]
Expand All @@ -16,7 +17,6 @@
#![feature(error_reporter)]
#![feature(extract_if)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(rustc_attrs)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![feature(associated_type_defaults)]
#![feature(closure_track_caller)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(never_type)]
#![feature(rustc_attrs)]
#![feature(variant_count)]
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_hir_analysis/src/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_errors::{codes::*, struct_span_code_err};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
use rustc_span::ErrorGuaranteed;
use rustc_span::{sym, ErrorGuaranteed};
use rustc_trait_selection::traits;

mod builtin;
Expand Down Expand Up @@ -70,7 +70,11 @@ fn enforce_trait_manually_implementable(
if let ty::trait_def::TraitSpecializationKind::AlwaysApplicable =
tcx.trait_def(trait_def_id).specialization_kind
{
if !tcx.features().specialization && !tcx.features().min_specialization {
if !tcx.features().specialization
&& !tcx.features().min_specialization
&& !impl_header_span.allows_unstable(sym::specialization)
&& !impl_header_span.allows_unstable(sym::min_specialization)
{
return Err(tcx.dcx().emit_err(errors::SpecializationTrait { span: impl_header_span }));
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ This API is completely unstable and subject to change.
#![feature(is_sorted)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(never_type)]
#![feature(lazy_cell)]
#![feature(slice_partition_dedup)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![feature(try_blocks)]
#![feature(never_type)]
#![feature(box_patterns)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(control_flow_enum)]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#![feature(let_chains)]
#![feature(if_let_guard)]
#![feature(iterator_try_collect)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(try_blocks)]
#![recursion_limit = "512"] // For rustdoc

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(try_blocks)]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_dataflow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(box_patterns)]
#![feature(exact_size_is_empty)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(try_blocks)]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![feature(is_sorted)]
#![feature(let_chains)]
#![feature(map_try_insert)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(never_type)]
#![feature(option_get_or_insert_default)]
#![feature(round_char_boundary)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#![feature(exhaustive_patterns)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(rustc_attrs)]
#![feature(step_trait)]
#![allow(internal_features)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#![feature(option_take_if)]
#![feature(never_type)]
#![feature(type_alias_impl_trait)]
#![feature(min_specialization)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![recursion_limit = "512"] // For rustdoc

#[macro_use]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
#![allow(internal_features)]
#![feature(allow_internal_unstable)]

// aux-build:specialization-trait.rs
extern crate specialization_trait;

#[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> {}
}

impl<U> specialization_trait::SpecTrait for T<U> {
fn method(&self) {}
}
};
}

test! {}

0 comments on commit 84c3ce2

Please sign in to comment.