File tree 3 files changed +36
-5
lines changed
3 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -1490,8 +1490,27 @@ impl LintPass for Stability {
1490
1490
}
1491
1491
1492
1492
fn check_expr ( & mut self , cx : & Context , e : & ast:: Expr ) {
1493
- // if the expression was produced by a macro expansion,
1494
- if e. span . expn_id != NO_EXPANSION { return }
1493
+ // skip if `e` is not from macro arguments
1494
+ let skip = cx. tcx . sess . codemap ( ) . with_expn_info ( e. span . expn_id , |expninfo| {
1495
+ match expninfo {
1496
+ Some ( ref info) => {
1497
+ if info. call_site . expn_id != NO_EXPANSION ||
1498
+ !( e. span . lo > info. call_site . lo && e. span . hi < info. call_site . hi ) {
1499
+ // This code is not from the arguments,
1500
+ // or this macro call was generated by an other macro
1501
+ // We can't handle it.
1502
+ true
1503
+ } else if info. callee . span . is_none ( ) {
1504
+ // We don't want to mess with compiler builtins.
1505
+ true
1506
+ } else {
1507
+ false
1508
+ }
1509
+ } ,
1510
+ _ => { false }
1511
+ }
1512
+ } ) ;
1513
+ if skip { return ; }
1495
1514
1496
1515
let id = match e. node {
1497
1516
ast:: ExprPath ( ..) | ast:: ExprStruct ( ..) => {
Original file line number Diff line number Diff line change @@ -181,3 +181,13 @@ pub struct LockedTupleStruct(pub int);
181
181
macro_rules! macro_test(
182
182
( ) => ( deprecated( ) ) ;
183
183
)
184
+
185
+ #[ macro_export]
186
+ macro_rules! macro_test_arg(
187
+ ( $func: expr) => ( $func) ;
188
+ )
189
+
190
+ #[ macro_export]
191
+ macro_rules! macro_test_arg_nested(
192
+ ( $func: ident) => ( macro_test_arg!( $func( ) ) ) ;
193
+ )
Original file line number Diff line number Diff line change @@ -109,12 +109,14 @@ mod cross_crate {
109
109
let _ = FrozenTupleStruct ( 1 ) ;
110
110
let _ = LockedTupleStruct ( 1 ) ;
111
111
112
- // At the moment, the following just checks that the stability
113
- // level of expanded code does not trigger the
114
- // lint. Eventually, we will want to lint the contents of the
112
+ // At the moment, the lint checker only checks stability in
113
+ // in the arguments of macros.
114
+ // Eventually, we will want to lint the contents of the
115
115
// macro in the module *defining* it. Also, stability levels
116
116
// on macros themselves are not yet linted.
117
117
macro_test ! ( ) ;
118
+ macro_test_arg ! ( deprecated_text( ) ) ; //~ ERROR use of deprecated item: text
119
+ macro_test_arg_nested ! ( deprecated_text) ;
118
120
}
119
121
120
122
fn test_method_param < F : Trait > ( foo : F ) {
You can’t perform that action at this time.
0 commit comments