diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-19 17:34:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-19 17:34:36 +0200 |
| commit | 7b3984b21b3ca526d6452f39334d4a4ca2234ba9 (patch) | |
| tree | 089f5cc0159c79ac7003b09772d94e687e5e174f /src/libsyntax | |
| parent | 564326a6268d199c1b3c3d67d270c708da7b30ec (diff) | |
| parent | 0b58bb32f66f4ec5f00683293093d94d8fb1aada (diff) | |
| download | rust-7b3984b21b3ca526d6452f39334d4a4ca2234ba9.tar.gz rust-7b3984b21b3ca526d6452f39334d4a4ca2234ba9.zip | |
Rollup merge of #61547 - petrochenkov:cfgen, r=Centril
Support `cfg` and `cfg_attr` on generic parameters `cfg` attributes are supported in all other positions where attributes are accepted at all. They were previously prohibited in https://github.com/rust-lang/rust/pull/51283 because they weren't implemented correctly before that and were simply ignored.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/config.rs | 20 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 6 |
2 files changed, 7 insertions, 19 deletions
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 1cc13ac7878..3b42e1de614 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -240,6 +240,10 @@ impl<'a> StripUnconfigured<'a> { items.flat_map_in_place(|item| self.configure(item)); } + pub fn configure_generic_params(&mut self, params: &mut Vec<ast::GenericParam>) { + params.flat_map_in_place(|param| self.configure(param)); + } + fn configure_variant_data(&mut self, vdata: &mut ast::VariantData) { match vdata { ast::VariantData::Struct(fields, ..) | ast::VariantData::Tuple(fields, _) => @@ -301,22 +305,6 @@ impl<'a> StripUnconfigured<'a> { pub fn configure_fn_decl(&mut self, fn_decl: &mut ast::FnDecl) { fn_decl.inputs.flat_map_in_place(|arg| self.configure(arg)); } - - /// Denies `#[cfg]` on generic parameters until we decide what to do with it. - /// See issue #51279. - pub fn disallow_cfg_on_generic_param(&mut self, param: &ast::GenericParam) { - for attr in param.attrs() { - let offending_attr = if attr.check_name(sym::cfg) { - "cfg" - } else if attr.check_name(sym::cfg_attr) { - "cfg_attr" - } else { - continue; - }; - let msg = format!("#[{}] cannot be applied on a generic parameter", offending_attr); - self.sess.span_diagnostic.span_err(attr.span, &msg); - } - } } impl<'a> MutVisitor for StripUnconfigured<'a> { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index be90def0bdd..cfd67575b6f 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1329,9 +1329,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } } - fn visit_generic_param(&mut self, param: &mut ast::GenericParam) { - self.cfg.disallow_cfg_on_generic_param(¶m); - noop_visit_generic_param(param, self) + fn visit_generic_params(&mut self, params: &mut Vec<ast::GenericParam>) { + self.cfg.configure_generic_params(params); + noop_visit_generic_params(params, self); } fn visit_attribute(&mut self, at: &mut ast::Attribute) { |
