// Determine the stability for a node based on its attributes and inherited
// stability. The stability is recorded in the index and used as the parent.
Determine the stability for a node based on its attributes and inherited
stability. The stability is recorded in the index and used as the parent.
Determine the stability for a node based on its attributes and inherited stability . The stability is recorded in the index and used as the parent .
fn annotate<F>(&mut self, id: NodeId, use_parent: bool,
                   attrs: &Vec<Attribute>, item_sp: Span, f: F, required: bool) where
        F: FnOnce(&mut Annotator),
    {
        if self.index.staged_api[&LOCAL_CRATE] {
            debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
            match attr::find_stability(self.tcx.sess.diagnostic(), attrs, item_sp) {
                Some(mut stab) => {
                    debug!("annotate: found {:?}", stab);
                    // if parent is deprecated and we're not, inherit this by merging
                    // deprecated_since and its reason.
                    if let Some(parent_stab) = self.parent {
                        if parent_stab.deprecated_since.is_some()
                        && stab.deprecated_since.is_none() {
                            stab.deprecated_since = parent_stab.deprecated_since.clone();
                            stab.reason = parent_stab.reason.clone();
                        }
                    }
                    let stab = self.tcx.intern_stability(stab);
                    // Check if deprecated_since < stable_since. If it is,
                    // this is *almost surely* an accident.
                    let deprecated_predates_stable = match (stab.deprecated_since.as_ref(),
                                                            stab.since.as_ref()) {
                        (Some(dep_since), Some(stab_since)) => {
                            // explicit version of iter::order::lt to handle parse errors properly
                            let mut is_less = false;
                            for (dep_v, stab_v) in dep_since.split(".").zip(stab_since.split(".")) {
                                match (dep_v.parse::<u64>(), stab_v.parse::<u64>()) {
                                    (Ok(dep_v), Ok(stab_v)) => match dep_v.cmp(&stab_v) {
                                        Ordering::Less => {
                                            is_less = true;
                                            break;
                                        }
                                        Ordering::Equal => { continue; }
                                        Ordering::Greater => { break; }
                                    },
                                    _ => {
                                        self.tcx.sess.span_err(item_sp,
                                            "Invalid stability or deprecation version found");
                                        // act like it isn't less because the question is now
                                        // nonsensical, and this makes us not do anything else
                                        // interesting.
                                        break;
                                    }
                                }
                            }
                            is_less
                        },
                        _ => false,
                    };
                    if deprecated_predates_stable {
                        self.tcx.sess.span_err(item_sp,
                            "An API can't be stabilized after it is deprecated");
                    }
                    self.index.map.insert(DefId::local(id), Some(stab));
                    // Don't inherit #[stable(feature = "rust1", since = "1.0.0")]
                    if stab.level != attr::Stable {
                        let parent = replace(&mut self.parent, Some(stab));
                        f(self);
                        self.parent = parent;
                    } else {
                        f(self);
                    }
                }
                None => {
                    debug!("annotate: not found, use_parent = {:?}, parent = {:?}",
                           use_parent, self.parent);
                    if use_parent {
                        if let Some(stab) = self.parent {
                            self.index.map.insert(DefId::local(id), Some(stab));
                        } else if self.index.staged_api[&LOCAL_CRATE] && required
                            && self.export_map.contains(&id)
                            && !self.tcx.sess.opts.test {
                                self.tcx.sess.span_err(item_sp,
                                                       "This node does not \
                                                        have a stability attribute");
                            }
                    }
                    f(self);
                }
            }
        } else {
            // Emit warnings for non-staged-api crates. These should be errors.
            for attr in attrs {
                let tag = attr.name();
                if tag == "unstable" || tag == "stable" || tag == "deprecated" {
                    attr::mark_used(attr);
                    self.tcx.sess.span_err(attr.span(),
                                       "stability attributes may not be used outside \
                                        of the standard library");
                }
            }
            f(self);
        }
    }
fn annotate < F > ( & mut self , id : NodeId , use_parent : bool , attrs : & Vec < Attribute > , item_sp : Span , f : F , required : bool ) where F : FnOnce ( & mut Annotator ) , { if self . index . staged_api [ & LOCAL_CRATE ] { debug ! ( " " id attrs ) ; match attr :: find_stability ( self . tcx . sess . diagnostic ( ) , attrs , item_sp ) { Some ( mut stab ) => { debug ! ( " " stab ) ; // if parent is deprecated and we're not, inherit this by merging // deprecated_since and its reason. if let Some ( parent_stab ) = self . parent { if parent_stab . deprecated_since . is_some ( ) && stab . deprecated_since . is_none ( ) { stab . deprecated_since = parent_stab . deprecated_since . clone ( ) ; stab . reason = parent_stab . reason . clone ( ) ; } } let stab = self . tcx . intern_stability ( stab ) ; // Check if deprecated_since < stable_since. If it is, // this is *almost surely* an accident. let deprecated_predates_stable = match ( stab . deprecated_since . as_ref ( ) , stab . since . as_ref ( ) ) { ( Some ( dep_since ) , Some ( stab_since ) ) => { // explicit version of iter::order::lt to handle parse errors properly let mut is_less = false ; for ( dep_v , stab_v ) in dep_since . split ( " " ) . zip ( stab_since . split ( " " ) ) { match ( dep_v . parse :: < u64 > ( ) , stab_v . parse :: < u64 > ( ) ) { ( Ok ( dep_v ) , Ok ( stab_v ) ) => match dep_v . cmp ( & stab_v ) { Ordering :: Less => { is_less = true ; break ; } Ordering :: Equal => { continue ; } Ordering :: Greater => { break ; } } , _ => { self . tcx . sess . span_err ( item_sp , " " ) ; // act like it isn't less because the question is now // nonsensical, and this makes us not do anything else // interesting. break ; } } } is_less } , _ => false , } ; if deprecated_predates_stable { self . tcx . sess . span_err ( item_sp , " " ) ; } self . index . map . insert ( DefId :: local ( id ) , Some ( stab ) ) ; // Don't inherit #[stable(feature = "rust1", since = "1.0.0")] if stab . level != attr :: Stable { let parent = replace ( & mut self . parent , Some ( stab ) ) ; f ( self ) ; self . parent = parent ; } else { f ( self ) ; } } None => { debug ! ( " " use_parent self parent ) ; if use_parent { if let Some ( stab ) = self . parent { self . index . map . insert ( DefId :: local ( id ) , Some ( stab ) ) ; } else if self . index . staged_api [ & LOCAL_CRATE ] && required && self . export_map . contains ( & id ) && ! self . tcx . sess . opts . test { self . tcx . sess . span_err ( item_sp , " \
 " ) ; } } f ( self ) ; } } } else { // Emit warnings for non-staged-api crates. These should be errors. for attr in attrs { let tag = attr . name ( ) ; if tag == " " || tag == " " || tag == " " { attr :: mark_used ( attr ) ; self . tcx . sess . span_err ( attr . span ( ) , " \
 " ) ; } } f ( self ) ; } }
Determine the stability for a node based on its attributes and inherited
stability.
Determine the stability for a node based on its attributes and inherited stability .
&mut self
id
NodeId
use_parent
bool
attrs
&Vec<Attribute>
item_sp
Span
f
F
required
bool