Skip to content

Commit 4cc4a67

Browse files
committed
Rollup merge of rust-lang#50406 - ExpHP:concat-nonzero-idents, r=dtolnay
Forbid constructing empty identifiers from concat_idents The empty identifier is a [reserved identifier](https://github.com/rust-lang/rust/blob/8a37c75a3a661385cc607d934c70e86a9eaf5fd7/src/libsyntax_pos/symbol.rs#L300-L305) in rust, apparently used for black magicks like representing the crate root or somesuch... and therefore, being able to construct it is Ungood. Presumably. ...even if the macro that lets you construct it is so useless that you can't actually do any damage with it. (and believe me, I tried) Fixes rust-lang#50403. **Note:** I noticed that when you try to do something similar with `proc_macro::Term`, the compiler actually catches it and flags the identifier as reserved. Perhaps a better solution would be to somehow have that same check applied here.
2 parents dfb32af + 8e38d02 commit 4cc4a67

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

src/libcore/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ mod builtin {
606606
#[macro_export]
607607
#[cfg(dox)]
608608
macro_rules! concat_idents {
609-
($($e:ident),*) => ({ /* compiler built-in */ });
610-
($($e:ident,)*) => ({ /* compiler built-in */ });
609+
($($e:ident),+) => ({ /* compiler built-in */ });
610+
($($e:ident,)+) => ({ /* compiler built-in */ });
611611
}
612612

613613
/// Concatenates literals into a static string slice.

src/libstd/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ pub mod builtin {
450450
#[unstable(feature = "concat_idents_macro", issue = "29599")]
451451
#[macro_export]
452452
macro_rules! concat_idents {
453-
($($e:ident),*) => ({ /* compiler built-in */ });
454-
($($e:ident,)*) => ({ /* compiler built-in */ });
453+
($($e:ident),+) => ({ /* compiler built-in */ });
454+
($($e:ident,)+) => ({ /* compiler built-in */ });
455455
}
456456

457457
/// Concatenates literals into a static string slice.

src/libsyntax_ext/concat_idents.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
3131
return base::DummyResult::expr(sp);
3232
}
3333

34+
if tts.is_empty() {
35+
cx.span_err(sp, "concat_idents! takes 1 or more arguments.");
36+
return DummyResult::expr(sp);
37+
}
38+
3439
let mut res_str = String::new();
3540
for (i, e) in tts.iter().enumerate() {
3641
if i & 1 == 1 {

src/test/ui/issue-50403.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(concat_idents)]
12+
13+
fn main() {
14+
let x = concat_idents!(); //~ ERROR concat_idents! takes 1 or more arguments
15+
}

src/test/ui/issue-50403.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: concat_idents! takes 1 or more arguments.
2+
--> $DIR/issue-50403.rs:14:13
3+
|
4+
LL | let x = concat_idents!(); //~ ERROR concat_idents! takes 1 or more arguments
5+
| ^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)