diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-20 22:00:47 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-07-07 13:04:07 +0300 |
| commit | 3b6370b4ab645d65e0729b3a419946a6f2f4d1cd (patch) | |
| tree | bf4d75dcbcab9b7380a84b4d2777c0829900f7af /src/libsyntax | |
| parent | 03ac05338c4ae4d01a8d3b2b05eb8e6d53384460 (diff) | |
| download | rust-3b6370b4ab645d65e0729b3a419946a6f2f4d1cd.tar.gz rust-3b6370b4ab645d65e0729b3a419946a6f2f4d1cd.zip | |
resolve/expand: Move macro stability checking to an earlier point
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 49 |
2 files changed, 9 insertions, 42 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 57dabf98d2c..bde989a464b 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -738,7 +738,6 @@ pub struct ExpansionData { pub depth: usize, pub module: Rc<ModuleData>, pub directory_ownership: DirectoryOwnership, - pub crate_span: Option<Span>, } /// One of these is made during expansion and incrementally updated as we go; @@ -768,7 +767,6 @@ impl<'a> ExtCtxt<'a> { depth: 0, module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }), directory_ownership: DirectoryOwnership::Owned { relative: None }, - crate_span: None, }, expansions: FxHashMap::default(), } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index da965eda61e..6be5988d03b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -243,7 +243,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { module.directory.pop(); self.cx.root_path = module.directory.clone(); self.cx.current_expansion.module = Rc::new(module); - self.cx.current_expansion.crate_span = Some(krate.span); let orig_mod_span = krate.module.inner; @@ -668,39 +667,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; let path = &mac.node.path; - let validate = |this: &mut Self| { - // feature-gate the macro invocation - if let Some((feature, issue)) = ext.unstable_feature { - let crate_span = this.cx.current_expansion.crate_span.unwrap(); - // don't stability-check macros in the same crate - if !crate_span.contains(ext.span) - && !span.allows_unstable(feature) - && this.cx.ecfg.features.map_or(true, |feats| { - // macro features will count as lib features - !feats.declared_lib_features.iter().any(|&(feat, _)| feat == feature) - }) { - let explain = format!("macro {}! is unstable", path); - emit_feature_err(this.cx.parse_sess, feature, span, - GateIssue::Library(Some(issue)), &explain); - this.cx.trace_macros_diag(); - } - } - - Ok(()) - }; - let opt_expanded = match &ext.kind { + SyntaxExtensionKind::Bang(expander) => { + self.gate_proc_macro_expansion_kind(span, kind); + let tok_result = expander.expand(self.cx, span, mac.node.stream()); + let result = self.parse_ast_fragment(tok_result, kind, path, span); + self.gate_proc_macro_expansion(span, &result); + result + } SyntaxExtensionKind::LegacyBang(expander) => { - if let Err(dummy_span) = validate(self) { - dummy_span - } else { - kind.make_from(expander.expand( - self.cx, - span, - mac.node.stream(), - Some(ext.span), - )) - } + let tok_result = expander.expand(self.cx, span, mac.node.stream(), Some(ext.span)); + kind.make_from(tok_result) } SyntaxExtensionKind::Attr(..) | @@ -717,14 +694,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { self.cx.trace_macros_diag(); kind.dummy(span) } - - SyntaxExtensionKind::Bang(expander) => { - self.gate_proc_macro_expansion_kind(span, kind); - let tok_result = expander.expand(self.cx, span, mac.node.stream()); - let result = self.parse_ast_fragment(tok_result, kind, path, span); - self.gate_proc_macro_expansion(span, &result); - result - } }; if opt_expanded.is_some() { |
