Auto merge of #29014 - petrochenkov:stability, r=brson
Stricter checking of stability attributes + enforcement of their invariants at compile time (+ removed dead file librustc_front/attr.rs) I intended to enforce use of `reason` for unstable items as well (it normally presents for new items), but it turned out too intrusive, many older unstable items don't have `reason`s. r? @aturon I'm studying how stability works and do some refactoring along the way, so it's probably not the last PR.
This commit is contained in:
commit
747d951e88
18 changed files with 337 additions and 894 deletions
|
|
@ -324,8 +324,8 @@ impl Item {
|
|||
match self.stability {
|
||||
Some(ref s) => {
|
||||
let mut base = match s.level {
|
||||
attr::Unstable => "unstable".to_string(),
|
||||
attr::Stable => String::new(),
|
||||
stability::Unstable => "unstable".to_string(),
|
||||
stability::Stable => String::new(),
|
||||
};
|
||||
if !s.deprecated_since.is_empty() {
|
||||
base.push_str(" deprecated");
|
||||
|
|
@ -2674,7 +2674,7 @@ impl Clean<Item> for doctree::Macro {
|
|||
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
||||
pub struct Stability {
|
||||
pub level: attr::StabilityLevel,
|
||||
pub level: stability::StabilityLevel,
|
||||
pub feature: String,
|
||||
pub since: String,
|
||||
pub deprecated_since: String,
|
||||
|
|
@ -2685,32 +2685,36 @@ pub struct Stability {
|
|||
impl Clean<Stability> for attr::Stability {
|
||||
fn clean(&self, _: &DocContext) -> Stability {
|
||||
Stability {
|
||||
level: self.level,
|
||||
level: stability::StabilityLevel::from_attr_level(&self.level),
|
||||
feature: self.feature.to_string(),
|
||||
since: self.since.as_ref().map_or("".to_string(),
|
||||
|interned| interned.to_string()),
|
||||
deprecated_since: self.deprecated_since.as_ref().map_or("".to_string(),
|
||||
|istr| istr.to_string()),
|
||||
reason: self.reason.as_ref().map_or("".to_string(),
|
||||
|interned| interned.to_string()),
|
||||
issue: self.issue,
|
||||
since: match self.level {
|
||||
attr::Stable {ref since} => since.to_string(),
|
||||
_ => "".to_string(),
|
||||
},
|
||||
deprecated_since: match self.depr {
|
||||
Some(attr::Deprecation {ref since, ..}) => since.to_string(),
|
||||
_=> "".to_string(),
|
||||
},
|
||||
reason: {
|
||||
if let Some(ref depr) = self.depr {
|
||||
depr.reason.to_string()
|
||||
} else if let attr::Unstable {reason: Some(ref reason), ..} = self.level {
|
||||
reason.to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
},
|
||||
issue: match self.level {
|
||||
attr::Unstable {issue, ..} => Some(issue),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Clean<Stability> for &'a attr::Stability {
|
||||
fn clean(&self, _: &DocContext) -> Stability {
|
||||
Stability {
|
||||
level: self.level,
|
||||
feature: self.feature.to_string(),
|
||||
since: self.since.as_ref().map_or("".to_string(),
|
||||
|interned| interned.to_string()),
|
||||
deprecated_since: self.deprecated_since.as_ref().map_or("".to_string(),
|
||||
|istr| istr.to_string()),
|
||||
reason: self.reason.as_ref().map_or("".to_string(),
|
||||
|interned| interned.to_string()),
|
||||
issue: self.issue,
|
||||
}
|
||||
fn clean(&self, dc: &DocContext) -> Stability {
|
||||
(**self).clean(dc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,9 +52,10 @@ use std::sync::Arc;
|
|||
use externalfiles::ExternalHtml;
|
||||
|
||||
use serialize::json::{self, ToJson};
|
||||
use syntax::{abi, ast, attr};
|
||||
use syntax::{abi, ast};
|
||||
use rustc::metadata::cstore::LOCAL_CRATE;
|
||||
use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use rustc::middle::stability;
|
||||
use rustc::util::nodemap::DefIdSet;
|
||||
use rustc_front::hir;
|
||||
|
||||
|
|
@ -1608,8 +1609,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
|||
let s1 = i1.stability.as_ref().map(|s| s.level);
|
||||
let s2 = i2.stability.as_ref().map(|s| s.level);
|
||||
match (s1, s2) {
|
||||
(Some(attr::Unstable), Some(attr::Stable)) => return Ordering::Greater,
|
||||
(Some(attr::Stable), Some(attr::Unstable)) => return Ordering::Less,
|
||||
(Some(stability::Unstable), Some(stability::Stable)) => return Ordering::Greater,
|
||||
(Some(stability::Stable), Some(stability::Unstable)) => return Ordering::Less,
|
||||
_ => {}
|
||||
}
|
||||
i1.name.cmp(&i2.name)
|
||||
|
|
@ -1724,7 +1725,7 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Optio
|
|||
String::new()
|
||||
};
|
||||
format!("Deprecated{}{}", since, Markdown(&reason))
|
||||
} else if stab.level == attr::Unstable {
|
||||
} else if stab.level == stability::Unstable {
|
||||
let unstable_extra = if show_reason {
|
||||
match (!stab.feature.is_empty(), &cx.issue_tracker_base_url, stab.issue) {
|
||||
(true, &Some(ref tracker_url), Some(issue_no)) =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue