diff options
| author | bors <bors@rust-lang.org> | 2019-06-23 00:10:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-06-23 00:10:17 +0000 |
| commit | a96ba969156d257e5d5b692946fa8fe40ed6543a (patch) | |
| tree | 6b20831f5e7fe26a17165678bc6c0ea78d492621 /src/libsyntax | |
| parent | de02101e6d949c4a9040211e9ce8c488a997497e (diff) | |
| parent | 74380b3336d6d93b74f65f0a1034b29b53aae268 (diff) | |
Auto merge of #62069 - Centril:rollup-m8n4uw7, r=Centril
Rollup of 5 pull requests Successful merges: - #62047 (Trigger `unused_attribute` lint on `#[cfg_attr($pred,)]`) - #62049 (Fix one missing `dyn`.) - #62051 (Lint empty `#[derive()]` as unused attribute.) - #62057 (Deny explicit_outlives_requirements in the compiler) - #62068 (Fix meta-variable binding errors in macros) Failed merges: r? @ghost
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/config.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/ext/derive.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 12 |
3 files changed, 17 insertions, 20 deletions
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 3b42e1de614..1ab367f73c1 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -91,10 +91,10 @@ impl<'a> StripUnconfigured<'a> { /// is in the original source file. Gives a compiler error if the syntax of /// the attribute is incorrect. fn process_cfg_attr(&mut self, attr: ast::Attribute) -> Vec<ast::Attribute> { - if !attr.check_name(sym::cfg_attr) { + if attr.path != sym::cfg_attr { return vec![attr]; } - if attr.tokens.len() == 0 { + if attr.tokens.is_empty() { self.sess.span_diagnostic .struct_span_err( attr.span, @@ -108,7 +108,7 @@ impl<'a> StripUnconfigured<'a> { <https://doc.rust-lang.org/reference/conditional-compilation.html\ #the-cfg_attr-attribute>") .emit(); - return Vec::new(); + return vec![]; } let (cfg_predicate, expanded_attrs) = match attr.parse(self.sess, |parser| { @@ -133,17 +133,18 @@ impl<'a> StripUnconfigured<'a> { Ok(result) => result, Err(mut e) => { e.emit(); - return Vec::new(); + return vec![]; } }; - // Check feature gate and lint on zero attributes in source. Even if the feature is gated, - // we still compute as if it wasn't, since the emitted error will stop compilation further - // along the compilation. - if expanded_attrs.len() == 0 { - // FIXME: Emit unused attribute lint here. + // Lint on zero attributes in source. + if expanded_attrs.is_empty() { + return vec![attr]; } + // At this point we know the attribute is considered used. + attr::mark_used(&attr); + if attr::cfg_matches(&cfg_predicate, self.sess, self.features) { // We call `process_cfg_attr` recursively in case there's a // `cfg_attr` inside of another `cfg_attr`. E.g. @@ -159,7 +160,7 @@ impl<'a> StripUnconfigured<'a> { })) .collect() } else { - Vec::new() + vec![] } } diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index abc451c96ae..3b4243ed24f 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -30,10 +30,6 @@ pub fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>) -> match attr.parse_list(cx.parse_sess, |parser| parser.parse_path_allowing_meta(PathStyle::Mod)) { - Ok(ref traits) if traits.is_empty() => { - cx.span_warn(attr.span, "empty trait list in `derive`"); - false - } Ok(traits) => { result.extend(traits); true diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index cfd67575b6f..945cf36af46 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -98,9 +98,9 @@ macro_rules! ast_fragments { } }); } - $($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)*)* + $($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)* $($(AstFragment::$Kind(ast) => - ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)*)* + ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)?)* } } @@ -108,10 +108,10 @@ macro_rules! ast_fragments { match *self { AstFragment::OptExpr(Some(ref expr)) => visitor.visit_expr(expr), AstFragment::OptExpr(None) => {} - $($(AstFragment::$Kind(ref ast) => visitor.$visit_ast(ast),)*)* + $($(AstFragment::$Kind(ref ast) => visitor.$visit_ast(ast),)?)* $($(AstFragment::$Kind(ref ast) => for ast_elt in &ast[..] { visitor.$visit_ast_elt(ast_elt); - })*)* + })?)* } } } @@ -122,10 +122,10 @@ macro_rules! ast_fragments { } $($(fn $mut_visit_ast(&mut self, ast: &mut $AstTy) { visit_clobber(ast, |ast| self.expand_fragment(AstFragment::$Kind(ast)).$make_ast()); - })*)* + })?)* $($(fn $flat_map_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy { self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast() - })*)* + })?)* } impl<'a> MacResult for crate::ext::tt::macro_rules::ParserAnyMacro<'a> { |
