diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index a4a6ed73c61c..7f3c8fcdd5aa 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -155,14 +155,7 @@ macro_rules! print { #[stable(feature = "rust1", since = "1.0.0")] macro_rules! println { () => (print!("\n")); - ($fmt:expr) => ({ - print!($fmt); - print!("\n"); - }); - ($fmt:expr, $($arg:tt)*) => ({ - print!($fmt, $($arg)*); - print!("\n"); - }); + ($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*))); } /// Macro for printing to the standard error. diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index d58f4ce17e2f..99dba8af754f 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -58,7 +58,7 @@ pub fn expand_syntax_ext( } if missing_literal.len() > 0 { let mut err = cx.struct_span_err(missing_literal, "expected a literal"); - err.note("only `&str` literals can be passed to `concat!()`"); + err.note("only literals (like `\"foo\"`, `42` and `3.14`) can be passed to `concat!()`"); err.emit(); } let sp = sp.apply_mark(cx.current_expansion.mark); diff --git a/src/test/ui/macros/bad-concat.rs b/src/test/ui/macros/bad-concat.rs new file mode 100644 index 000000000000..e7adee8ce859 --- /dev/null +++ b/src/test/ui/macros/bad-concat.rs @@ -0,0 +1,18 @@ +// Copyright 2018 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. + +fn main() { + let x: u32 = 42; + let y: f64 = 3.14; + let z = "foo"; + let _ = concat!(x, y, z, "bar"); + //~^ ERROR expected a literal + //~| NOTE only literals +} diff --git a/src/test/ui/macros/bad-concat.stderr b/src/test/ui/macros/bad-concat.stderr new file mode 100644 index 000000000000..b97e4f268241 --- /dev/null +++ b/src/test/ui/macros/bad-concat.stderr @@ -0,0 +1,10 @@ +error: expected a literal + --> $DIR/bad-concat.rs:15:21 + | +LL | let _ = concat!(x, y, z, "bar"); + | ^ ^ ^ + | + = note: only literals (like `"foo"`, `42` and `3.14`) can be passed to `concat!()` + +error: aborting due to previous error + diff --git a/src/test/ui/macros/trace-macro.stderr b/src/test/ui/macros/trace-macro.stderr index c98e42ea647d..6d8a329be804 100644 --- a/src/test/ui/macros/trace-macro.stderr +++ b/src/test/ui/macros/trace-macro.stderr @@ -5,9 +5,8 @@ LL | println!("Hello, World!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: expanding `println! { "Hello, World!" }` - = note: to `{ print ! ( "Hello, World!" ) ; print ! ( "/n" ) ; }` - = note: expanding `print! { "Hello, World!" }` - = note: to `$crate :: io :: _print ( format_args ! ( "Hello, World!" ) )` - = note: expanding `print! { "/n" }` - = note: to `$crate :: io :: _print ( format_args ! ( "/n" ) )` + = note: to `print ! ( "{}/n" , format_args ! ( "Hello, World!" ) )` + = note: expanding `print! { "{}/n" , format_args ! ( "Hello, World!" ) }` + = note: to `$crate :: io :: _print ( + format_args ! ( "{}/n" , format_args ! ( "Hello, World!" ) ) )`