@@ -238,22 +238,22 @@ pub fn contains_name<AM: AttrMetaMethods>(metas: &[AM], name: &str) -> bool {
238238 debug ! ( "attr::contains_name (name={})" , name) ;
239239 metas. iter ( ) . any ( |item| {
240240 debug ! ( " testing: {}" , item. name( ) ) ;
241- item. name ( ) . equiv ( & name)
241+ item. check_name ( name)
242242 } )
243243}
244244
245245pub fn first_attr_value_str_by_name ( attrs : & [ Attribute ] , name : & str )
246246 -> Option < InternedString > {
247247 attrs. iter ( )
248- . find ( |at| at. name ( ) . equiv ( & name) )
248+ . find ( |at| at. check_name ( name) )
249249 . and_then ( |at| at. value_str ( ) )
250250}
251251
252252pub fn last_meta_item_value_str_by_name ( items : & [ @MetaItem ] , name : & str )
253253 -> Option < InternedString > {
254254 items. iter ( )
255255 . rev ( )
256- . find ( |mi| mi. name ( ) . equiv ( & name) )
256+ . find ( |mi| mi. check_name ( name) )
257257 . and_then ( |i| i. value_str ( ) )
258258}
259259
@@ -289,7 +289,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> Vec<@MetaItem> {
289289 */
290290pub fn find_linkage_metas ( attrs : & [ Attribute ] ) -> Vec < @MetaItem > {
291291 let mut result = Vec :: new ( ) ;
292- for attr in attrs. iter ( ) . filter ( |at| at. name ( ) . equiv ( & ( "link" ) ) ) {
292+ for attr in attrs. iter ( ) . filter ( |at| at. check_name ( "link" ) ) {
293293 match attr. meta ( ) . node {
294294 MetaList ( _, ref items) => result. push_all ( items. as_slice ( ) ) ,
295295 _ => ( )
@@ -318,17 +318,21 @@ pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr {
318318 // FIXME (#2809)---validate the usage of #[inline] and #[inline]
319319 attrs. iter ( ) . fold ( InlineNone , |ia, attr| {
320320 match attr. node . value . node {
321- MetaWord ( ref n) if n. equiv ( & ( "inline" ) ) => InlineHint ,
322- MetaList ( ref n, ref items) if n. equiv ( & ( "inline" ) ) => {
323- if contains_name ( items. as_slice ( ) , "always" ) {
324- InlineAlways
325- } else if contains_name ( items. as_slice ( ) , "never" ) {
326- InlineNever
327- } else {
321+ MetaWord ( ref n) if n. equiv ( & ( "inline" ) ) => {
322+ mark_used ( attr) ;
328323 InlineHint
329324 }
330- }
331- _ => ia
325+ MetaList ( ref n, ref items) if n. equiv ( & ( "inline" ) ) => {
326+ mark_used ( attr) ;
327+ if contains_name ( items. as_slice ( ) , "always" ) {
328+ InlineAlways
329+ } else if contains_name ( items. as_slice ( ) , "never" ) {
330+ InlineNever
331+ } else {
332+ InlineHint
333+ }
334+ }
335+ _ => ia
332336 }
333337 } )
334338}
@@ -348,7 +352,7 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>>
348352 // this doesn't work.
349353 let some_cfg_matches = metas. any ( |mi| {
350354 debug ! ( "testing name: {}" , mi. name( ) ) ;
351- if mi. name ( ) . equiv ( & ( "cfg" ) ) { // it is a #[cfg()] attribute
355+ if mi. check_name ( "cfg" ) { // it is a #[cfg()] attribute
352356 debug ! ( "is cfg" ) ;
353357 no_cfgs = false ;
354358 // only #[cfg(...)] ones are understood.
@@ -399,11 +403,13 @@ pub enum StabilityLevel {
399403 Locked
400404}
401405
402- /// Find the first stability attribute. `None` if none exists.
403- pub fn find_stability < AM : AttrMetaMethods , It : Iterator < AM > > ( mut metas : It )
404- -> Option < Stability > {
405- for m in metas {
406- let level = match m. name ( ) . get ( ) {
406+ pub fn find_stability_generic < ' a ,
407+ AM : AttrMetaMethods ,
408+ I : Iterator < & ' a AM > >
409+ ( mut attrs : I )
410+ -> Option < ( Stability , & ' a AM ) > {
411+ for attr in attrs {
412+ let level = match attr. name ( ) . get ( ) {
407413 "deprecated" => Deprecated ,
408414 "experimental" => Experimental ,
409415 "unstable" => Unstable ,
@@ -413,14 +419,22 @@ pub fn find_stability<AM: AttrMetaMethods, It: Iterator<AM>>(mut metas: It)
413419 _ => continue // not a stability level
414420 } ;
415421
416- return Some ( Stability {
422+ return Some ( ( Stability {
417423 level : level,
418- text : m . value_str ( )
419- } ) ;
424+ text : attr . value_str ( )
425+ } , attr ) ) ;
420426 }
421427 None
422428}
423429
430+ /// Find the first stability attribute. `None` if none exists.
431+ pub fn find_stability ( attrs : & [ Attribute ] ) -> Option < Stability > {
432+ find_stability_generic ( attrs. iter ( ) ) . map ( |( s, attr) | {
433+ mark_used ( attr) ;
434+ s
435+ } )
436+ }
437+
424438pub fn require_unique_names ( diagnostic : & SpanHandler , metas : & [ @MetaItem ] ) {
425439 let mut set = HashSet :: new ( ) ;
426440 for meta in metas. iter ( ) {
@@ -447,11 +461,13 @@ pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[@MetaItem]) {
447461 * present (before fields, if any) with that type; reprensentation
448462 * optimizations which would remove it will not be done.
449463 */
450- pub fn find_repr_attr ( diagnostic : & SpanHandler , attr : @ast :: MetaItem , acc : ReprAttr )
464+ pub fn find_repr_attr ( diagnostic : & SpanHandler , attr : & Attribute , acc : ReprAttr )
451465 -> ReprAttr {
452466 let mut acc = acc;
453- match attr. node {
467+ info ! ( "{}" , :: print:: pprust:: attribute_to_str( attr) ) ;
468+ match attr. node . value . node {
454469 ast:: MetaList ( ref s, ref items) if s. equiv ( & ( "repr" ) ) => {
470+ mark_used ( attr) ;
455471 for item in items. iter ( ) {
456472 match item. node {
457473 ast:: MetaWord ( ref word) => {
0 commit comments