Add and use stability helper methods
This avoids an ambiguity (when reading) where `.level.is_stable()` is not immediately clear whether it is general stability or const stability.
This commit is contained in:
parent
f53fc41cfc
commit
a9dd4cfa6b
8 changed files with 30 additions and 15 deletions
|
@ -101,6 +101,16 @@ pub struct Stability {
|
||||||
pub feature: Symbol,
|
pub feature: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Stability {
|
||||||
|
pub fn is_unstable(&self) -> bool {
|
||||||
|
self.level.is_unstable()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_stable(&self) -> bool {
|
||||||
|
self.level.is_stable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
|
/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
|
||||||
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
#[derive(HashStable_Generic)]
|
#[derive(HashStable_Generic)]
|
||||||
|
@ -111,6 +121,16 @@ pub struct ConstStability {
|
||||||
pub promotable: bool,
|
pub promotable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ConstStability {
|
||||||
|
pub fn is_const_unstable(&self) -> bool {
|
||||||
|
self.level.is_unstable()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_const_stable(&self) -> bool {
|
||||||
|
self.level.is_stable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The available stability levels.
|
/// The available stability levels.
|
||||||
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||||
#[derive(HashStable_Generic)]
|
#[derive(HashStable_Generic)]
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rustc_span::symbol::Symbol;
|
||||||
pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
|
pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
|
||||||
if tcx.is_const_fn_raw(def_id) {
|
if tcx.is_const_fn_raw(def_id) {
|
||||||
let const_stab = tcx.lookup_const_stability(def_id)?;
|
let const_stab = tcx.lookup_const_stability(def_id)?;
|
||||||
if const_stab.level.is_unstable() { Some(const_stab.feature) } else { None }
|
if const_stab.is_const_unstable() { Some(const_stab.feature) } else { None }
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -944,7 +944,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
// have no `rustc_const_stable` attributes to be const-unstable as well. This
|
// have no `rustc_const_stable` attributes to be const-unstable as well. This
|
||||||
// should be fixed later.
|
// should be fixed later.
|
||||||
let callee_is_unstable_unmarked = tcx.lookup_const_stability(callee).is_none()
|
let callee_is_unstable_unmarked = tcx.lookup_const_stability(callee).is_none()
|
||||||
&& tcx.lookup_stability(callee).map_or(false, |s| s.level.is_unstable());
|
&& tcx.lookup_stability(callee).map_or(false, |s| s.is_unstable());
|
||||||
if callee_is_unstable_unmarked {
|
if callee_is_unstable_unmarked {
|
||||||
trace!("callee_is_unstable_unmarked");
|
trace!("callee_is_unstable_unmarked");
|
||||||
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
|
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
|
||||||
|
|
|
@ -2791,7 +2791,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn is_const_fn(self, def_id: DefId) -> bool {
|
pub fn is_const_fn(self, def_id: DefId) -> bool {
|
||||||
if self.is_const_fn_raw(def_id) {
|
if self.is_const_fn_raw(def_id) {
|
||||||
match self.lookup_const_stability(def_id) {
|
match self.lookup_const_stability(def_id) {
|
||||||
Some(stability) if stability.level.is_unstable() => {
|
Some(stability) if stability.is_const_unstable() => {
|
||||||
// has a `rustc_const_unstable` attribute, check whether the user enabled the
|
// has a `rustc_const_unstable` attribute, check whether the user enabled the
|
||||||
// corresponding feature gate.
|
// corresponding feature gate.
|
||||||
self.features()
|
self.features()
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
// Propagate unstability. This can happen even for non-staged-api crates in case
|
// Propagate unstability. This can happen even for non-staged-api crates in case
|
||||||
// -Zforce-unstable-if-unmarked is set.
|
// -Zforce-unstable-if-unmarked is set.
|
||||||
if let Some(stab) = self.parent_stab {
|
if let Some(stab) = self.parent_stab {
|
||||||
if inherit_deprecation.yes() && stab.level.is_unstable() {
|
if inherit_deprecation.yes() && stab.is_unstable() {
|
||||||
self.index.stab_map.insert(def_id, stab);
|
self.index.stab_map.insert(def_id, stab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
if const_stab.is_none() {
|
if const_stab.is_none() {
|
||||||
debug!("annotate: const_stab not found, parent = {:?}", self.parent_const_stab);
|
debug!("annotate: const_stab not found, parent = {:?}", self.parent_const_stab);
|
||||||
if let Some(parent) = self.parent_const_stab {
|
if let Some(parent) = self.parent_const_stab {
|
||||||
if parent.level.is_unstable() {
|
if parent.is_const_unstable() {
|
||||||
self.index.const_stab_map.insert(def_id, parent);
|
self.index.const_stab_map.insert(def_id, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,9 +272,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
if stab.is_none() {
|
if stab.is_none() {
|
||||||
debug!("annotate: stab not found, parent = {:?}", self.parent_stab);
|
debug!("annotate: stab not found, parent = {:?}", self.parent_stab);
|
||||||
if let Some(stab) = self.parent_stab {
|
if let Some(stab) = self.parent_stab {
|
||||||
if inherit_deprecation.yes() && stab.level.is_unstable()
|
if inherit_deprecation.yes() && stab.is_unstable() || inherit_from_parent.yes() {
|
||||||
|| inherit_from_parent.yes()
|
|
||||||
{
|
|
||||||
self.index.stab_map.insert(def_id, stab);
|
self.index.stab_map.insert(def_id, stab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,7 +344,7 @@ crate fn build_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(stab) = tcx.lookup_stability(did) {
|
if let Some(stab) = tcx.lookup_stability(did) {
|
||||||
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
|
if stab.is_unstable() && stab.feature == sym::rustc_private {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,7 +373,7 @@ crate fn build_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(stab) = tcx.lookup_stability(did) {
|
if let Some(stab) = tcx.lookup_stability(did) {
|
||||||
if stab.level.is_unstable() && stab.feature == sym::rustc_private {
|
if stab.is_unstable() && stab.feature == sym::rustc_private {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -632,7 +632,7 @@ impl Item {
|
||||||
self.stability(tcx).as_ref().and_then(|s| {
|
self.stability(tcx).as_ref().and_then(|s| {
|
||||||
let mut classes = Vec::with_capacity(2);
|
let mut classes = Vec::with_capacity(2);
|
||||||
|
|
||||||
if s.level.is_unstable() {
|
if s.is_unstable() {
|
||||||
classes.push("unstable");
|
classes.push("unstable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -445,10 +445,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
|
||||||
|
|
||||||
// The "rustc_private" crates are permanently unstable so it makes no sense
|
// The "rustc_private" crates are permanently unstable so it makes no sense
|
||||||
// to render "unstable" everywhere.
|
// to render "unstable" everywhere.
|
||||||
if item
|
if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
|
||||||
.stability(tcx)
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.level.is_unstable() && s.feature != sym::rustc_private)
|
|
||||||
== Some(true)
|
== Some(true)
|
||||||
{
|
{
|
||||||
tags += &tag_html("unstable", "", "Experimental");
|
tags += &tag_html("unstable", "", "Experimental");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue