diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-08 23:31:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-08 23:31:19 +0200 |
| commit | fc068222d06ac3ff656c4c9ef2b98428c1c4537b (patch) | |
| tree | 549c8b1517f37a1fb2c80cd8786404a5bad1d6bb /src/libsyntax_ext/source_util.rs | |
| parent | 2748a9fd93dd1a00a4521f4f16de5befbf77f6cd (diff) | |
| parent | e068cec13e2a63dba29d40f0130527d980f83f7c (diff) | |
Rollup merge of #64284 - Mark-Simulacrum:include-warn, r=petrochenkov
Warn if include macro fails to include entire file This currently introduces an error, mainly because that was just simpler, and I'm not entirely certain if we can introduce a lint without an RFC and such. This is primarily to get feedback on the approach and overall aim -- in particular, do we think this is helpful? If so, we probably will need lang-team sign off and decide if it should be an error (as currently introduced by this PR), a lint, or a warning. r? @petrochenkov cc https://github.com/rust-lang/rust/issues/35560
Diffstat (limited to 'src/libsyntax_ext/source_util.rs')
| -rw-r--r-- | src/libsyntax_ext/source_util.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libsyntax_ext/source_util.rs b/src/libsyntax_ext/source_util.rs index 9dc9d66b86f..f74507dcc21 100644 --- a/src/libsyntax_ext/source_util.rs +++ b/src/libsyntax_ext/source_util.rs @@ -5,6 +5,7 @@ use syntax::print::pprust; use syntax::ptr::P; use syntax::symbol::Symbol; use syntax::tokenstream::TokenStream; +use syntax::early_buffered_lints::BufferedEarlyLintId; use smallvec::SmallVec; use syntax_pos::{self, Pos, Span}; @@ -83,7 +84,16 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) } impl<'a> base::MacResult for ExpandResult<'a> { fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> { - Some(panictry!(self.p.parse_expr())) + let r = panictry!(self.p.parse_expr()); + if self.p.token != token::Eof { + self.p.sess.buffer_lint( + BufferedEarlyLintId::IncompleteInclude, + self.p.token.span, + ast::CRATE_NODE_ID, + "include macro expected single expression in source", + ); + } + Some(r) } fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> { |
