diff options
| author | bors <bors@rust-lang.org> | 2021-09-26 05:15:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-26 05:15:11 +0000 |
| commit | f6e6ddc09d660fbfb4d483a9677d80768cc4e31c (patch) | |
| tree | 61b3e7fda85f83fa96d221012da392502e7d1cf6 /compiler/rustc_interface/src/util.rs | |
| parent | 4da89a180facdecf168cbe0ddbc6bfbdd9f6e696 (diff) | |
| parent | 75f058dbfd1c02daa191efb6eb53dc91fda8add6 (diff) | |
Auto merge of #88680 - ehuss:more-attr-validation, r=petrochenkov
Validate builtin attributes for macro args. This adds some validation for `path`, `crate_type`, and `recursion_limit` attributes so that they will now return an error if you attempt to pass a macro into them (such as `#[path = foo!()]`). Previously, the attribute would be completely ignored. These attributes are special because their values need to be known before/during expansion. cc #87681
Diffstat (limited to 'compiler/rustc_interface/src/util.rs')
| -rw-r--r-- | compiler/rustc_interface/src/util.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 24975702b87..a1d1b63c8fa 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -10,6 +10,7 @@ use rustc_errors::registry::Registry; use rustc_metadata::dynamic_lib::DynamicLibrary; #[cfg(parallel_compiler)] use rustc_middle::ty::tls; +use rustc_parse::validate_attr; #[cfg(parallel_compiler)] use rustc_query_impl::QueryCtxt; use rustc_resolve::{self, Resolver}; @@ -475,7 +476,7 @@ pub fn get_codegen_sysroot( } pub(crate) fn check_attr_crate_type( - _sess: &Session, + sess: &Session, attrs: &[ast::Attribute], lint_buffer: &mut LintBuffer, ) { @@ -515,6 +516,19 @@ pub(crate) fn check_attr_crate_type( ); } } + } else { + // This is here mainly to check for using a macro, such as + // #![crate_type = foo!()]. That is not supported since the + // crate type needs to be known very early in compilation long + // before expansion. Otherwise, validation would normally be + // caught in AstValidator (via `check_builtin_attribute`), but + // by the time that runs the macro is expanded, and it doesn't + // give an error. + validate_attr::emit_fatal_malformed_builtin_attribute( + &sess.parse_sess, + a, + sym::crate_type, + ); } } } |
