Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid constructing empty identifiers from concat_idents #50406

Merged
merged 3 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ mod builtin {
#[macro_export]
#[cfg(dox)]
macro_rules! concat_idents {
($($e:ident),*) => ({ /* compiler built-in */ });
($($e:ident,)*) => ({ /* compiler built-in */ });
($($e:ident),+) => ({ /* compiler built-in */ });
($($e:ident,)+) => ({ /* compiler built-in */ });
}

/// Concatenates literals into a static string slice.
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ pub mod builtin {
#[unstable(feature = "concat_idents_macro", issue = "29599")]
#[macro_export]
macro_rules! concat_idents {
($($e:ident),*) => ({ /* compiler built-in */ });
($($e:ident,)*) => ({ /* compiler built-in */ });
($($e:ident),+) => ({ /* compiler built-in */ });
($($e:ident,)+) => ({ /* compiler built-in */ });
}

/// Concatenates literals into a static string slice.
Expand Down
5 changes: 5 additions & 0 deletions src/libsyntax_ext/concat_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issue-50403.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}
8 changes: 8 additions & 0 deletions src/test/ui/issue-50403.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: concat_idents! takes 1 or more arguments.
--> $DIR/issue-50403.rs:14:13
|
LL | let x = concat_idents!(); //~ ERROR concat_idents! takes 1 or more arguments
| ^^^^^^^^^^^^^^^^

error: aborting due to previous error