From 9b3aea602c37d53bbecf8bff8c77ccbfbefc23d0 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Tue, 30 Jan 2018 14:53:01 +0900 Subject: Remove Option from the return type of Attribute::name() --- src/libsyntax_ext/deriving/custom.rs | 8 +++----- src/libsyntax_ext/deriving/generic/mod.rs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/libsyntax_ext') diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index 5fd5e299488..76da1746a03 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -22,11 +22,9 @@ struct MarkAttrs<'a>(&'a [ast::Name]); impl<'a> Visitor<'a> for MarkAttrs<'a> { fn visit_attribute(&mut self, attr: &Attribute) { - if let Some(name) = attr.name() { - if self.0.contains(&name) { - mark_used(attr); - mark_known(attr); - } + if self.0.contains(&attr.name()) { + mark_used(attr); + mark_known(attr); } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index becd70149fd..80f65957c39 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -472,7 +472,7 @@ impl<'a> TraitDef<'a> { attrs.extend(item.attrs .iter() .filter(|a| { - a.name().is_some() && match &*a.name().unwrap().as_str() { + match &*a.name().as_str() { "allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true, _ => false, } -- cgit 1.4.1-3-g733a5 From cd54b3e4483a331326a7508de6c24c90664ae392 Mon Sep 17 00:00:00 2001 From: Michael Lamparski Date: Wed, 2 May 2018 20:51:39 -0400 Subject: forbid empty identifiers from concat_idents --- src/libsyntax_ext/concat_idents.rs | 5 +++++ src/test/ui/issue-50403.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/ui/issue-50403.rs (limited to 'src/libsyntax_ext') diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index 544b1410d3d..b8345e7cf40 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -31,6 +31,11 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, return base::DummyResult::expr(sp); } + if tts.is_empty() { + cx.span_err(sp, "concat_idents! takes 1 or more arguments."); + return DummyResult::expr(sp); + } + let mut res_str = String::new(); for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { diff --git a/src/test/ui/issue-50403.rs b/src/test/ui/issue-50403.rs new file mode 100644 index 00000000000..8d4c6c5140f --- /dev/null +++ b/src/test/ui/issue-50403.rs @@ -0,0 +1,15 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(concat_idents)] + +fn main() { + let x = concat_idents!(); //~ ERROR concat_idents! takes 1 or more arguments +} -- cgit 1.4.1-3-g733a5