Skip to content

Commit 5591336

Browse files
authored
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.
2 parents ed3b049 + a2479a4 commit 5591336

File tree

13 files changed

+25
-14
lines changed

13 files changed

+25
-14
lines changed

compiler/rustc_ast/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![feature(box_patterns)]
1616
#![feature(if_let_guard)]
1717
#![feature(let_chains)]
18-
#![feature(min_specialization)]
18+
#![cfg_attr(bootstrap, feature(min_specialization))]
1919
#![feature(negative_impls)]
2020
#![feature(stmt_expr_attributes)]
2121

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![allow(internal_features)]
88
#![allow(rustc::diagnostic_outside_of_impl)]
99
#![allow(rustc::untranslatable_diagnostic)]
10+
#![cfg_attr(bootstrap, feature(min_specialization))]
1011
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1112
#![doc(rust_logo)]
1213
#![feature(array_windows)]
@@ -16,7 +17,6 @@
1617
#![feature(error_reporter)]
1718
#![feature(extract_if)]
1819
#![feature(let_chains)]
19-
#![feature(min_specialization)]
2020
#![feature(negative_impls)]
2121
#![feature(never_type)]
2222
#![feature(rustc_attrs)]

compiler/rustc_hir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(associated_type_defaults)]
66
#![feature(closure_track_caller)]
77
#![feature(let_chains)]
8-
#![feature(min_specialization)]
8+
#![cfg_attr(bootstrap, feature(min_specialization))]
99
#![feature(never_type)]
1010
#![feature(rustc_attrs)]
1111
#![feature(variant_count)]

compiler/rustc_hir_analysis/src/coherence/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_errors::{codes::*, struct_span_code_err};
1010
use rustc_hir::def_id::{DefId, LocalDefId};
1111
use rustc_middle::query::Providers;
1212
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
13-
use rustc_span::ErrorGuaranteed;
13+
use rustc_span::{sym, ErrorGuaranteed};
1414
use rustc_trait_selection::traits;
1515

1616
mod builtin;
@@ -70,7 +70,11 @@ fn enforce_trait_manually_implementable(
7070
if let ty::trait_def::TraitSpecializationKind::AlwaysApplicable =
7171
tcx.trait_def(trait_def_id).specialization_kind
7272
{
73-
if !tcx.features().specialization && !tcx.features().min_specialization {
73+
if !tcx.features().specialization
74+
&& !tcx.features().min_specialization
75+
&& !impl_header_span.allows_unstable(sym::specialization)
76+
&& !impl_header_span.allows_unstable(sym::min_specialization)
77+
{
7478
return Err(tcx.dcx().emit_err(errors::SpecializationTrait { span: impl_header_span }));
7579
}
7680
}

compiler/rustc_hir_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ This API is completely unstable and subject to change.
6767
#![feature(is_sorted)]
6868
#![feature(iter_intersperse)]
6969
#![feature(let_chains)]
70-
#![feature(min_specialization)]
70+
#![cfg_attr(bootstrap, feature(min_specialization))]
7171
#![feature(never_type)]
7272
#![feature(lazy_cell)]
7373
#![feature(slice_partition_dedup)]

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(try_blocks)]
66
#![feature(never_type)]
77
#![feature(box_patterns)]
8-
#![feature(min_specialization)]
8+
#![cfg_attr(bootstrap, feature(min_specialization))]
99
#![feature(control_flow_enum)]
1010

1111
#[macro_use]

compiler/rustc_infer/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#![feature(let_chains)]
2525
#![feature(if_let_guard)]
2626
#![feature(iterator_try_collect)]
27-
#![feature(min_specialization)]
27+
#![cfg_attr(bootstrap, feature(min_specialization))]
2828
#![feature(try_blocks)]
2929
#![recursion_limit = "512"] // For rustdoc
3030

compiler/rustc_mir_build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#![feature(box_patterns)]
1010
#![feature(if_let_guard)]
1111
#![feature(let_chains)]
12-
#![feature(min_specialization)]
12+
#![cfg_attr(bootstrap, feature(min_specialization))]
1313
#![feature(try_blocks)]
1414

1515
#[macro_use]

compiler/rustc_mir_dataflow/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(box_patterns)]
33
#![feature(exact_size_is_empty)]
44
#![feature(let_chains)]
5-
#![feature(min_specialization)]
5+
#![cfg_attr(bootstrap, feature(min_specialization))]
66
#![feature(try_blocks)]
77

88
#[macro_use]

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![feature(is_sorted)]
99
#![feature(let_chains)]
1010
#![feature(map_try_insert)]
11-
#![feature(min_specialization)]
11+
#![cfg_attr(bootstrap, feature(min_specialization))]
1212
#![feature(never_type)]
1313
#![feature(option_get_or_insert_default)]
1414
#![feature(round_char_boundary)]

compiler/rustc_target/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![feature(exhaustive_patterns)]
1515
#![feature(iter_intersperse)]
1616
#![feature(let_chains)]
17-
#![feature(min_specialization)]
17+
#![cfg_attr(bootstrap, feature(min_specialization))]
1818
#![feature(rustc_attrs)]
1919
#![feature(step_trait)]
2020
#![allow(internal_features)]

compiler/rustc_trait_selection/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#![feature(option_take_if)]
2525
#![feature(never_type)]
2626
#![feature(type_alias_impl_trait)]
27-
#![feature(min_specialization)]
27+
#![cfg_attr(bootstrap, feature(min_specialization))]
2828
#![recursion_limit = "512"] // For rustdoc
2929

3030
#[macro_use]

tests/ui/specialization/allow_internal_unstable.rs tests/ui/specialization/min_specialization/allow_internal_unstable.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
#![allow(internal_features)]
66
#![feature(allow_internal_unstable)]
77

8+
// aux-build:specialization-trait.rs
9+
extern crate specialization_trait;
10+
811
#[allow_internal_unstable(min_specialization)]
912
macro_rules! test {
1013
() => {
1114
struct T<U>(U);
1215
trait Tr {}
1316
impl<U> Tr for T<U> {}
1417
impl Tr for T<u8> {}
15-
}
18+
19+
impl<U> specialization_trait::SpecTrait for T<U> {
20+
fn method(&self) {}
21+
}
22+
};
1623
}
1724

1825
test! {}

0 commit comments

Comments
 (0)