Skip to content

Commit 8067d03

Browse files
committed
auto merge of #15726 : aturon/rust/macro-stability, r=alexcrichton
This small patch causes the stability lint to bail out when traversing any AST produced via a macro expansion. Ultimately, we would like to lint the contents of the macro at the place where the macro is defined, but regardless we should not be linting it at the use site. Closes #15703
2 parents 8a308b1 + 81b69d1 commit 8067d03

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/librustc/lint/builtin.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,9 @@ impl LintPass for Stability {
14331433
}
14341434

14351435
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
1436+
// if the expression was produced by a macro expansion,
1437+
if e.span.expn_info.is_some() { return }
1438+
14361439
let id = match e.node {
14371440
ast::ExprPath(..) | ast::ExprStruct(..) => {
14381441
match cx.tcx.def_map.borrow().find(&e.id) {

src/test/auxiliary/lint_stability.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#![crate_id="lint_stability#0.1"]
1111
#![crate_type = "lib"]
1212

13+
#![feature(macro_rules)]
14+
#![macro_escape]
15+
1316
#[deprecated]
1417
pub fn deprecated() {}
1518
#[deprecated="text"]
@@ -173,3 +176,8 @@ pub struct StableTupleStruct(pub int);
173176
pub struct FrozenTupleStruct(pub int);
174177
#[locked]
175178
pub struct LockedTupleStruct(pub int);
179+
180+
#[macro_export]
181+
macro_rules! macro_test(
182+
() => (deprecated());
183+
)

src/test/compile-fail/lint-stability.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
// aux-build:lint_stability.rs
1212
// aux-build:inherited_stability.rs
1313

14-
#![feature(globs)]
14+
#![feature(globs, phase)]
1515
#![deny(unstable)]
1616
#![deny(deprecated)]
1717
#![deny(experimental)]
1818
#![allow(dead_code)]
1919

2020
mod cross_crate {
21+
#[phase(plugin, link)]
2122
extern crate lint_stability;
2223
use self::lint_stability::*;
2324

@@ -76,7 +77,6 @@ mod cross_crate {
7677
foo.method_locked_text();
7778
foo.trait_locked_text();
7879

79-
8080
let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
8181
let _ = ExperimentalStruct { i: 0 }; //~ ERROR use of experimental item
8282
let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable item
@@ -108,6 +108,13 @@ mod cross_crate {
108108
let _ = StableTupleStruct (1);
109109
let _ = FrozenTupleStruct (1);
110110
let _ = LockedTupleStruct (1);
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
115+
// macro in the module *defining* it. Also, stability levels
116+
// on macros themselves are not yet linted.
117+
macro_test!();
111118
}
112119

113120
fn test_method_param<F: Trait>(foo: F) {

0 commit comments

Comments
 (0)