Skip to content

Commit 54e6ad9

Browse files
committed
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.
1 parent a99c2da commit 54e6ad9

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

src/libstd/macros.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,7 @@ macro_rules! print {
155155
#[stable(feature = "rust1", since = "1.0.0")]
156156
macro_rules! println {
157157
() => (print!("\n"));
158-
($fmt:expr) => ({
159-
print!($fmt);
160-
print!("\n");
161-
});
162-
($fmt:expr, $($arg:tt)*) => ({
163-
print!($fmt, $($arg)*);
164-
print!("\n");
165-
});
158+
($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*)));
166159
}
167160

168161
/// Macro for printing to the standard error.

src/libsyntax_ext/concat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn expand_syntax_ext(
5858
}
5959
if missing_literal.len() > 0 {
6060
let mut err = cx.struct_span_err(missing_literal, "expected a literal");
61-
err.note("only `&str` literals can be passed to `concat!()`");
61+
err.note("only literals (like `\"foo\"`, `42` and `3.14`) can be passed to `concat!()`");
6262
err.emit();
6363
}
6464
let sp = sp.apply_mark(cx.current_expansion.mark);

src/test/ui/macros/bad-concat.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 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+
fn main() {
12+
let x: u32 = 42;
13+
let y: f64 = 3.14;
14+
let z = "foo";
15+
let _ = concat!(x, y, z, "bar");
16+
//~^ ERROR expected a literal
17+
//~| NOTE only literals
18+
}

src/test/ui/macros/bad-concat.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected a literal
2+
--> $DIR/bad-concat.rs:15:21
3+
|
4+
LL | let _ = concat!(x, y, z, "bar");
5+
| ^ ^ ^
6+
|
7+
= note: only literals (like `"foo"`, `42` and `3.14`) can be passed to `concat!()`
8+
9+
error: aborting due to previous error
10+

src/test/ui/macros/trace-macro.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ LL | println!("Hello, World!");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: expanding `println! { "Hello, World!" }`
8-
= note: to `{ print ! ( "Hello, World!" ) ; print ! ( "/n" ) ; }`
9-
= note: expanding `print! { "Hello, World!" }`
10-
= note: to `$crate :: io :: _print ( format_args ! ( "Hello, World!" ) )`
11-
= note: expanding `print! { "/n" }`
12-
= note: to `$crate :: io :: _print ( format_args ! ( "/n" ) )`
8+
= note: to `print ! ( "{}/n" , format_args ! ( "Hello, World!" ) )`
9+
= note: expanding `print! { "{}/n" , format_args ! ( "Hello, World!" ) }`
10+
= note: to `$crate :: io :: _print (
11+
format_args ! ( "{}/n" , format_args ! ( "Hello, World!" ) ) )`
1312

0 commit comments

Comments
 (0)