diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-07-15 11:52:11 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@commure.com> | 2018-07-19 23:18:07 -0700 |
| commit | fbce952193d38328c39262cf2fb7f7bfbe088a70 (patch) | |
| tree | d4dbd97694e5310b68149c2d653ece3664fa9edf | |
| parent | f53c145ef18db6543e8e5420e172e04b6054db2e (diff) | |
| download | rust-fbce952193d38328c39262cf2fb7f7bfbe088a70.tar.gz rust-fbce952193d38328c39262cf2fb7f7bfbe088a70.zip | |
review comments: modify note wording and change `println`
- Don't print the newline on its own to avoid the possibility of printing it out of order due to `stdout` locking. - Modify wording of `concat!()` with non-literals to not mislead into believing that only `&str` literals are accepted. - Add test for `concat!()` with non-literals.
| -rw-r--r-- | src/libstd/macros.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax_ext/concat.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/macros/bad-concat.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/macros/bad-concat.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/macros/trace-macro.stderr | 9 |
5 files changed, 34 insertions, 14 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index a4a6ed73c61..7f3c8fcdd5a 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 d58f4ce17e2..99dba8af754 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 00000000000..e7adee8ce85 --- /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 <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. + +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 00000000000..b97e4f26824 --- /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 c98e42ea647..6d8a329be80 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!" ) ) )` |
