rust/src/test/ui/issues/issue-27592.rs
Stephen Crane 0ec4513d5f Fix format macro expansions spans to be macro-generated
New Exprs generated as part of the format macro expansion should get the macro
expansion span which has an expansion context, not the span of the format string
which does not.
2019-09-25 17:45:15 -07:00

20 lines
547 B
Rust

// Regression test for issue #27592.
fn write<'a, F: ::std::ops::FnOnce()->::std::fmt::Arguments<'a> + 'a>(fcn: F) {
use std::fmt::Write;
let _ = match fcn() { a => write!(&mut Stream, "{}", a), };
}
struct Stream;
impl ::std::fmt::Write for Stream {
fn write_str(&mut self, _s: &str) -> ::std::fmt::Result {
Ok( () )
}
}
fn main() {
write(|| format_args!("{}", String::from("Hello world")));
//~^ ERROR cannot return value referencing temporary value
//~| ERROR cannot return reference to temporary value
}