resolve: Check stability for local macros as well

This commit is contained in:
Vadim Petrochenkov 2019-06-21 01:59:30 +03:00
parent 290475e837
commit 73dec4a804
3 changed files with 20 additions and 13 deletions

View File

@ -236,21 +236,20 @@ impl<'a> base::Resolver for Resolver<'a> {
};
invoc.expansion_data.mark.set_expn_info(ext.expn_info(span, &format));
if let Some((feature, issue)) = ext.unstable_feature {
let features = self.session.features_untracked();
if !span.allows_unstable(feature) &&
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
let msg = format!("macro {}! is unstable", path);
emit_feature_err(&self.session.parse_sess, feature, span,
GateIssue::Library(Some(issue)), &msg);
}
}
if let Res::Def(_, def_id) = res {
if after_derive {
self.session.span_err(span, "macro attributes must be placed before `#[derive]`");
}
if let Some((feature, issue)) = ext.unstable_feature {
// Do not stability-check macros in the same crate.
let features = self.session.features_untracked();
if !def_id.is_local() &&
!span.allows_unstable(feature) &&
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
let msg = format!("macro {}! is unstable", path);
emit_feature_err(&self.session.parse_sess, feature, span,
GateIssue::Library(Some(issue)), &msg);
}
}
self.macro_defs.insert(invoc.expansion_data.mark, def_id);
let normal_module_def_id =
self.macro_def_scope(invoc.expansion_data.mark).normal_ancestor_id;

View File

@ -7,6 +7,6 @@
macro_rules! local_unstable { () => () }
fn main() {
local_unstable!();
local_unstable!(); //~ ERROR: macro local_unstable! is unstable
unstable_macro!(); //~ ERROR: macro unstable_macro! is unstable
}

View File

@ -1,3 +1,11 @@
error[E0658]: macro local_unstable! is unstable
--> $DIR/macro-stability.rs:10:5
|
LL | local_unstable!();
| ^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(local_unstable)] to the crate attributes to enable
error[E0658]: macro unstable_macro! is unstable
--> $DIR/macro-stability.rs:11:5
|
@ -6,6 +14,6 @@ LL | unstable_macro!();
|
= help: add #![feature(unstable_macros)] to the crate attributes to enable
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.