mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
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.
This commit is contained in:
parent
f53c145ef1
commit
fbce952193
@ -155,14 +155,7 @@ macro_rules! print {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
macro_rules! println {
|
macro_rules! println {
|
||||||
() => (print!("\n"));
|
() => (print!("\n"));
|
||||||
($fmt:expr) => ({
|
($($arg:tt)*) => (print!("{}\n", format_args!($($arg)*)));
|
||||||
print!($fmt);
|
|
||||||
print!("\n");
|
|
||||||
});
|
|
||||||
($fmt:expr, $($arg:tt)*) => ({
|
|
||||||
print!($fmt, $($arg)*);
|
|
||||||
print!("\n");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Macro for printing to the standard error.
|
/// Macro for printing to the standard error.
|
||||||
|
@ -58,7 +58,7 @@ pub fn expand_syntax_ext(
|
|||||||
}
|
}
|
||||||
if missing_literal.len() > 0 {
|
if missing_literal.len() > 0 {
|
||||||
let mut err = cx.struct_span_err(missing_literal, "expected a literal");
|
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();
|
err.emit();
|
||||||
}
|
}
|
||||||
let sp = sp.apply_mark(cx.current_expansion.mark);
|
let sp = sp.apply_mark(cx.current_expansion.mark);
|
||||||
|
18
src/test/ui/macros/bad-concat.rs
Normal file
18
src/test/ui/macros/bad-concat.rs
Normal file
@ -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
|
||||||
|
}
|
10
src/test/ui/macros/bad-concat.stderr
Normal file
10
src/test/ui/macros/bad-concat.stderr
Normal file
@ -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
|
||||||
|
|
@ -5,9 +5,8 @@ LL | println!("Hello, World!");
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: expanding `println! { "Hello, World!" }`
|
= note: expanding `println! { "Hello, World!" }`
|
||||||
= note: to `{ print ! ( "Hello, World!" ) ; print ! ( "/n" ) ; }`
|
= note: to `print ! ( "{}/n" , format_args ! ( "Hello, World!" ) )`
|
||||||
= note: expanding `print! { "Hello, World!" }`
|
= note: expanding `print! { "{}/n" , format_args ! ( "Hello, World!" ) }`
|
||||||
= note: to `$crate :: io :: _print ( format_args ! ( "Hello, World!" ) )`
|
= note: to `$crate :: io :: _print (
|
||||||
= note: expanding `print! { "/n" }`
|
format_args ! ( "{}/n" , format_args ! ( "Hello, World!" ) ) )`
|
||||||
= note: to `$crate :: io :: _print ( format_args ! ( "/n" ) )`
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user