-
Notifications
You must be signed in to change notification settings - Fork 13.4k
WIP: Unstable impls #140399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
WIP: Unstable impls #140399
Changes from all commits
54b0b68
fc9a0e6
1ca27cc
a7c61c0
3b5713c
0da5266
25cfd96
3ca0475
4ba8acb
9e24e10
9583e1f
c6976b2
bd1072b
e88370f
fc2926f
cdb2773
788d9be
b2eabf2
4e816e1
6e4c902
b6bfa2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,22 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser { | |||||
} | ||||||
} | ||||||
|
||||||
pub(crate) struct AllowUnstableFeatureParser; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
impl<S: Stage> CombineAttributeParser<S> for AllowUnstableFeatureParser { | ||||||
const PATH: &'static [rustc_span::Symbol] = &[sym::unstable_feature_bound]; | ||||||
type Item = (Symbol, Span); | ||||||
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowUnstableFeature; | ||||||
|
||||||
fn extend<'c>( | ||||||
cx: &'c mut AcceptContext<'_, '_, S>, | ||||||
args: &'c ArgParser<'_>, | ||||||
) -> impl IntoIterator<Item = Self::Item> { | ||||||
parse_unstable(cx, args, <Self as CombineAttributeParser<S>>::PATH[0]) | ||||||
.into_iter() | ||||||
.zip(iter::repeat(cx.attr_span)) | ||||||
} | ||||||
} | ||||||
|
||||||
pub(crate) struct AllowConstFnUnstableParser; | ||||||
impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser { | ||||||
const PATH: &[Symbol] = &[sym::rustc_allow_const_fn_unstable]; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -213,6 +213,8 @@ declare_features! ( | |||||
(internal, custom_mir, "1.65.0", None), | ||||||
/// Outputs useful `assert!` messages | ||||||
(unstable, generic_assert, "1.63.0", None), | ||||||
/// Allow declaring an impl as unstable. | ||||||
(internal, impl_stability, "CURRENT_RUSTC_VERSION", None), | ||||||
Comment on lines
+216
to
+217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think that unstable feature bounds should just live under the |
||||||
/// Allows using the #[rustc_intrinsic] attribute. | ||||||
(internal, intrinsics, "1.0.0", None), | ||||||
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic. | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2368,9 +2368,12 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { | |||||||||
// We lower empty bounds like `Vec<dyn Copy>:` as | ||||||||||
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by | ||||||||||
// regular WF checking | ||||||||||
if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() { | ||||||||||
continue; | ||||||||||
|
||||||||||
match pred.kind().skip_binder() { | ||||||||||
ty::ClauseKind::WellFormed(..) | ty::ClauseKind::UnstableFeature(..) => continue, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and then can u move the comment about |
||||||||||
_ => {} | ||||||||||
} | ||||||||||
|
||||||||||
// Match the existing behavior. | ||||||||||
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) { | ||||||||||
let pred = self.normalize(span, None, pred); | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||
use std::assert_matches::assert_matches; | ||||||||||||
|
||||||||||||
use hir::Node; | ||||||||||||
use rustc_attr_data_structures::{AttributeKind, find_attr}; | ||||||||||||
use rustc_data_structures::fx::FxIndexSet; | ||||||||||||
use rustc_hir as hir; | ||||||||||||
use rustc_hir::def::DefKind; | ||||||||||||
|
@@ -318,6 +319,16 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen | |||||||||||
predicates.extend(const_evaluatable_predicates_of(tcx, def_id, &predicates)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id)); | ||||||||||||
let allow_unstable_feature_attr = | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
find_attr!(attrs, AttributeKind::AllowUnstableFeature(i) => i) | ||||||||||||
.map(|i| i.as_slice()) | ||||||||||||
.unwrap_or_default(); | ||||||||||||
|
||||||||||||
for (feat_name, span) in allow_unstable_feature_attr { | ||||||||||||
predicates.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
let mut predicates: Vec<_> = predicates.into_iter().collect(); | ||||||||||||
|
||||||||||||
// Subtle: before we store the predicates into the tcx, we | ||||||||||||
|
@@ -747,6 +758,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>( | |||||||||||
ty::ClauseKind::RegionOutlives(_) | ||||||||||||
| ty::ClauseKind::ConstArgHasType(_, _) | ||||||||||||
| ty::ClauseKind::WellFormed(_) | ||||||||||||
| ty::ClauseKind::UnstableFeature(_) | ||||||||||||
| ty::ClauseKind::ConstEvaluatable(_) => { | ||||||||||||
bug!( | ||||||||||||
"unexpected non-`Self` predicate when computing \ | ||||||||||||
|
@@ -774,6 +786,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>( | |||||||||||
| ty::ClauseKind::ConstArgHasType(_, _) | ||||||||||||
| ty::ClauseKind::WellFormed(_) | ||||||||||||
| ty::ClauseKind::ConstEvaluatable(_) | ||||||||||||
| ty::ClauseKind::UnstableFeature(_) | ||||||||||||
| ty::ClauseKind::HostEffect(..) => { | ||||||||||||
bug!( | ||||||||||||
"unexpected non-`Self` predicate when computing \ | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -136,6 +136,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | |||||||||||||||||||
type FnInputTys = &'tcx [Ty<'tcx>]; | ||||||||||||||||||||
type ParamTy = ParamTy; | ||||||||||||||||||||
type BoundTy = ty::BoundTy; | ||||||||||||||||||||
type Symbol = Symbol; | ||||||||||||||||||||
|
||||||||||||||||||||
type PlaceholderTy = ty::PlaceholderType; | ||||||||||||||||||||
type ErrorGuaranteed = ErrorGuaranteed; | ||||||||||||||||||||
|
@@ -831,6 +832,14 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu | |||||||||||||||||||
fn associated_const_equality(self) -> bool { | ||||||||||||||||||||
self.associated_const_equality() | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
fn impl_stability(self) -> bool { | ||||||||||||||||||||
self.impl_stability() | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
fn enabled(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool { | ||||||||||||||||||||
self.enabled(symbol) | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+840
to
+842
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span { | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -148,6 +148,40 @@ where | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn compute_unstable_feature_goal( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&mut self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
param_env: <I as Interner>::ParamEnv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
symbol: <I as Interner>::Symbol, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> QueryResult<I> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Iterate through all goals in param_env to find the one that has the same symbol. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for pred in param_env.caller_bounds().iter() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if let ty::ClauseKind::UnstableFeature(sym) = pred.kind().skip_binder() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if sym == symbol { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if self.cx().features().impl_stability() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If we are in std/core, and the feature is not enabled through #[unstable_feature_bound(..)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MaybeCause::Ambiguity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Outside of std/core, check if feature is enabled at crate level with #[feature(..)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// or if we are currently in codegen. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if self.cx().features().enabled(symbol) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|| (self.typing_mode() == TypingMode::PostAnalysis) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MaybeCause::Ambiguity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+165
to
+182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Minor structural change here. Moving the "are we in std/core" check to within the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[instrument(level = "trace", skip(self))] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn compute_const_evaluatable_goal( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&mut self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -142,6 +142,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | |||||||||
} | ||||||||||
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */ | ||||||||||
} | ||||||||||
Attribute::Parsed(AttributeKind::AllowUnstableFeature(syms)) => { | ||||||||||
self.check_unstable_feature_bound(syms.first().unwrap().1, span, target) | ||||||||||
} | ||||||||||
Attribute::Parsed( | ||||||||||
AttributeKind::BodyStability { .. } | ||||||||||
| AttributeKind::ConstStabilityIndirect | ||||||||||
|
@@ -2274,6 +2277,45 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
fn check_unstable_feature_bound(&self, attr_span: Span, span: Span, target: Target) { | ||||||||||
match target { | ||||||||||
Target::Fn | Target::Impl => {} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
Target::ExternCrate | ||||||||||
| Target::Use | ||||||||||
| Target::Static | ||||||||||
| Target::Const | ||||||||||
| Target::Closure | ||||||||||
| Target::Mod | ||||||||||
| Target::ForeignMod | ||||||||||
| Target::GlobalAsm | ||||||||||
| Target::TyAlias | ||||||||||
| Target::Enum | ||||||||||
| Target::Variant | ||||||||||
| Target::Struct | ||||||||||
| Target::Field | ||||||||||
| Target::Union | ||||||||||
| Target::Trait | ||||||||||
| Target::TraitAlias | ||||||||||
| Target::Expression | ||||||||||
| Target::Statement | ||||||||||
| Target::Arm | ||||||||||
| Target::AssocConst | ||||||||||
| Target::Method(_) | ||||||||||
| Target::AssocTy | ||||||||||
| Target::ForeignFn | ||||||||||
| Target::ForeignStatic | ||||||||||
| Target::ForeignTy | ||||||||||
| Target::GenericParam(_) | ||||||||||
| Target::MacroDef | ||||||||||
| Target::Param | ||||||||||
| Target::PatField | ||||||||||
| Target::ExprField | ||||||||||
| Target::WherePredicate => { | ||||||||||
self.tcx.dcx().emit_err(errors::RustcUnstableFeatureBound { attr_span, span }); | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
fn check_rustc_std_internal_symbol(&self, attr: &Attribute, span: Span, target: Target) { | ||||||||||
match target { | ||||||||||
Target::Fn | Target::Static | Target::ForeignFn | Target::ForeignStatic => {} | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.