Auto merge of #95956 - yaahc:stable-in-unstable, r=cjgillot
Support unstable moves via stable in unstable items part of https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/moving.20items.20to.20core.20unstably and a blocker of https://github.com/rust-lang/rust/pull/90328. The libs-api team needs the ability to move an already stable item to a new location unstably, in this case for Error in core. Otherwise these changes are insta-stable making them much harder to merge. This PR attempts to solve the problem by checking the stability of path segments as well as the last item in the path itself, which is currently the only thing checked.
This commit is contained in:
@@ -471,13 +471,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
///
|
||||
/// This function will also check if the item is deprecated.
|
||||
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
|
||||
///
|
||||
/// Returns `true` if item is allowed aka, stable or unstable under an enabled feature.
|
||||
pub fn check_stability(
|
||||
self,
|
||||
def_id: DefId,
|
||||
id: Option<HirId>,
|
||||
span: Span,
|
||||
method_span: Option<Span>,
|
||||
) {
|
||||
) -> bool {
|
||||
self.check_stability_allow_unstable(def_id, id, span, method_span, AllowUnstable::No)
|
||||
}
|
||||
|
||||
@@ -490,6 +492,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
|
||||
///
|
||||
/// Pass `AllowUnstable::Yes` to `allow_unstable` to force an unstable item to be allowed. Deprecation warnings will be emitted normally.
|
||||
///
|
||||
/// Returns `true` if item is allowed aka, stable or unstable under an enabled feature.
|
||||
pub fn check_stability_allow_unstable(
|
||||
self,
|
||||
def_id: DefId,
|
||||
@@ -497,7 +501,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
span: Span,
|
||||
method_span: Option<Span>,
|
||||
allow_unstable: AllowUnstable,
|
||||
) {
|
||||
) -> bool {
|
||||
self.check_optional_stability(
|
||||
def_id,
|
||||
id,
|
||||
@@ -516,6 +520,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// missing stability attributes (not necessarily just emit a `bug!`). This is necessary
|
||||
/// for default generic parameters, which only have stability attributes if they were
|
||||
/// added after the type on which they're defined.
|
||||
///
|
||||
/// Returns `true` if item is allowed aka, stable or unstable under an enabled feature.
|
||||
pub fn check_optional_stability(
|
||||
self,
|
||||
def_id: DefId,
|
||||
@@ -524,13 +530,16 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
method_span: Option<Span>,
|
||||
allow_unstable: AllowUnstable,
|
||||
unmarked: impl FnOnce(Span, DefId),
|
||||
) {
|
||||
) -> bool {
|
||||
let soft_handler = |lint, span, msg: &_| {
|
||||
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
|
||||
lint.build(msg).emit();
|
||||
})
|
||||
};
|
||||
match self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable) {
|
||||
let eval_result =
|
||||
self.eval_stability_allow_unstable(def_id, id, span, method_span, allow_unstable);
|
||||
let is_allowed = matches!(eval_result, EvalResult::Allow);
|
||||
match eval_result {
|
||||
EvalResult::Allow => {}
|
||||
EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => report_unstable(
|
||||
self.sess,
|
||||
@@ -544,6 +553,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
),
|
||||
EvalResult::Unmarked => unmarked(span, def_id),
|
||||
}
|
||||
|
||||
is_allowed
|
||||
}
|
||||
|
||||
pub fn lookup_deprecation(self, id: DefId) -> Option<Deprecation> {
|
||||
|
||||
Reference in New Issue
Block a user