@@ -45,7 +45,7 @@ use syntax::ast_map;
45
45
use syntax:: ast_util:: is_shift_binop;
46
46
use syntax:: attr:: AttrMetaMethods ;
47
47
use syntax:: attr;
48
- use syntax:: codemap:: Span ;
48
+ use syntax:: codemap:: { Span , DUMMY_SP } ;
49
49
use syntax:: parse:: token;
50
50
use syntax:: { ast, ast_util, visit} ;
51
51
use syntax:: ast:: { TyI , TyU , TyI8 , TyU8 , TyI16 , TyU16 , TyI32 , TyU32 , TyI64 , TyU64 } ;
@@ -1553,11 +1553,57 @@ declare_lint!(UNSTABLE, Allow,
1553
1553
/// `#[unstable]` attributes, or no stability attribute.
1554
1554
pub struct Stability ;
1555
1555
1556
+ impl Stability {
1557
+ fn lint ( & self , cx : & Context , id : ast:: DefId , span : Span ) {
1558
+ let stability = stability:: lookup ( cx. tcx , id) ;
1559
+ let cross_crate = !ast_util:: is_local ( id) ;
1560
+
1561
+ // stability attributes are promises made across crates; only
1562
+ // check DEPRECATED for crate-local usage.
1563
+ let ( lint, label) = match stability {
1564
+ // no stability attributes == Unstable
1565
+ None if cross_crate => ( UNSTABLE , "unmarked" ) ,
1566
+ Some ( attr:: Stability { level : attr:: Unstable , .. } ) if cross_crate =>
1567
+ ( UNSTABLE , "unstable" ) ,
1568
+ Some ( attr:: Stability { level : attr:: Experimental , .. } ) if cross_crate =>
1569
+ ( EXPERIMENTAL , "experimental" ) ,
1570
+ Some ( attr:: Stability { level : attr:: Deprecated , .. } ) =>
1571
+ ( DEPRECATED , "deprecated" ) ,
1572
+ _ => return
1573
+ } ;
1574
+
1575
+ let msg = match stability {
1576
+ Some ( attr:: Stability { text : Some ( ref s) , .. } ) => {
1577
+ format ! ( "use of {} item: {}" , label, * s)
1578
+ }
1579
+ _ => format ! ( "use of {} item" , label)
1580
+ } ;
1581
+
1582
+ cx. span_lint ( lint, span, msg. as_slice ( ) ) ;
1583
+ }
1584
+ }
1585
+
1556
1586
impl LintPass for Stability {
1557
1587
fn get_lints ( & self ) -> LintArray {
1558
1588
lint_array ! ( DEPRECATED , EXPERIMENTAL , UNSTABLE )
1559
1589
}
1560
1590
1591
+ fn check_view_item ( & mut self , cx : & Context , item : & ast:: ViewItem ) {
1592
+ // compiler-generated `extern crate` statements have a dummy span.
1593
+ if item. span == DUMMY_SP { return }
1594
+
1595
+ let id = match item. node {
1596
+ ast:: ViewItemExternCrate ( _, _, id) => id,
1597
+ ast:: ViewItemUse ( ..) => return ,
1598
+ } ;
1599
+ let cnum = match cx. tcx . sess . cstore . find_extern_mod_stmt_cnum ( id) {
1600
+ Some ( cnum) => cnum,
1601
+ None => return ,
1602
+ } ;
1603
+ let id = ast:: DefId { krate : cnum, node : ast:: CRATE_NODE_ID } ;
1604
+ self . lint ( cx, id, item. span ) ;
1605
+ }
1606
+
1561
1607
fn check_expr ( & mut self , cx : & Context , e : & ast:: Expr ) {
1562
1608
// first, check if the given expression was generated by a macro or not
1563
1609
// we need to go back the expn_info tree to check only the arguments
@@ -1629,32 +1675,7 @@ impl LintPass for Stability {
1629
1675
}
1630
1676
_ => return
1631
1677
} ;
1632
-
1633
- let stability = stability:: lookup ( cx. tcx , id) ;
1634
- let cross_crate = !ast_util:: is_local ( id) ;
1635
-
1636
- // stability attributes are promises made across crates; only
1637
- // check DEPRECATED for crate-local usage.
1638
- let ( lint, label) = match stability {
1639
- // no stability attributes == Unstable
1640
- None if cross_crate => ( UNSTABLE , "unmarked" ) ,
1641
- Some ( attr:: Stability { level : attr:: Unstable , .. } ) if cross_crate =>
1642
- ( UNSTABLE , "unstable" ) ,
1643
- Some ( attr:: Stability { level : attr:: Experimental , .. } ) if cross_crate =>
1644
- ( EXPERIMENTAL , "experimental" ) ,
1645
- Some ( attr:: Stability { level : attr:: Deprecated , .. } ) =>
1646
- ( DEPRECATED , "deprecated" ) ,
1647
- _ => return
1648
- } ;
1649
-
1650
- let msg = match stability {
1651
- Some ( attr:: Stability { text : Some ( ref s) , .. } ) => {
1652
- format ! ( "use of {} item: {}" , label, * s)
1653
- }
1654
- _ => format ! ( "use of {} item" , label)
1655
- } ;
1656
-
1657
- cx. span_lint ( lint, span, msg. as_slice ( ) ) ;
1678
+ self . lint ( cx, id, span) ;
1658
1679
}
1659
1680
}
1660
1681
0 commit comments