Skip to content

Commit 73dec4a

Browse files
committed
resolve: Check stability for local macros as well
1 parent 290475e commit 73dec4a

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/librustc_resolve/macros.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,20 @@ impl<'a> base::Resolver for Resolver<'a> {
236236
};
237237
invoc.expansion_data.mark.set_expn_info(ext.expn_info(span, &format));
238238

239+
if let Some((feature, issue)) = ext.unstable_feature {
240+
let features = self.session.features_untracked();
241+
if !span.allows_unstable(feature) &&
242+
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
243+
let msg = format!("macro {}! is unstable", path);
244+
emit_feature_err(&self.session.parse_sess, feature, span,
245+
GateIssue::Library(Some(issue)), &msg);
246+
}
247+
}
248+
239249
if let Res::Def(_, def_id) = res {
240250
if after_derive {
241251
self.session.span_err(span, "macro attributes must be placed before `#[derive]`");
242252
}
243-
if let Some((feature, issue)) = ext.unstable_feature {
244-
// Do not stability-check macros in the same crate.
245-
let features = self.session.features_untracked();
246-
if !def_id.is_local() &&
247-
!span.allows_unstable(feature) &&
248-
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
249-
let msg = format!("macro {}! is unstable", path);
250-
emit_feature_err(&self.session.parse_sess, feature, span,
251-
GateIssue::Library(Some(issue)), &msg);
252-
}
253-
}
254253
self.macro_defs.insert(invoc.expansion_data.mark, def_id);
255254
let normal_module_def_id =
256255
self.macro_def_scope(invoc.expansion_data.mark).normal_ancestor_id;

src/test/ui/macros/macro-stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
macro_rules! local_unstable { () => () }
88

99
fn main() {
10-
local_unstable!();
10+
local_unstable!(); //~ ERROR: macro local_unstable! is unstable
1111
unstable_macro!(); //~ ERROR: macro unstable_macro! is unstable
1212
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error[E0658]: macro local_unstable! is unstable
2+
--> $DIR/macro-stability.rs:10:5
3+
|
4+
LL | local_unstable!();
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add #![feature(local_unstable)] to the crate attributes to enable
8+
19
error[E0658]: macro unstable_macro! is unstable
210
--> $DIR/macro-stability.rs:11:5
311
|
@@ -6,6 +14,6 @@ LL | unstable_macro!();
614
|
715
= help: add #![feature(unstable_macros)] to the crate attributes to enable
816

9-
error: aborting due to previous error
17+
error: aborting due to 2 previous errors
1018

1119
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)