diff --git a/tests/codegen/issues/issue-128709-format-without-args.rs b/tests/codegen/issues/issue-128709-format-without-args.rs new file mode 100644 index 0000000000000..ceb9ce034d435 --- /dev/null +++ b/tests/codegen/issues/issue-128709-format-without-args.rs @@ -0,0 +1,17 @@ +//@ compile-flags: -C no-prepopulate-passes -C opt-level=0 + +#![crate_type = "lib"] + +// String formating macros without any arguments should compile +// to a `memcpy` followed by a call to `std::io::stdio::_print`. + +#[no_mangle] +pub fn code() { + // CHECK-LABEL: @code + // CHECK-NOT: getelementptr + // CHECK-NOT: store + // CHECK-NOT: ; call core::fmt::Arguments::new_const + // CHECK: call void @llvm.memcpy + // CHECK-NEXT: ; call std::io::stdio::_print + println!("hello world"); +} diff --git a/tests/ui/consts/const-format-arguments.rs b/tests/ui/consts/const-format-arguments.rs new file mode 100644 index 0000000000000..46f9c0b76ed55 --- /dev/null +++ b/tests/ui/consts/const-format-arguments.rs @@ -0,0 +1,5 @@ + +pub fn main() { + const A: std::fmt::Arguments = std::fmt::Arguments::new_const(&[&"hola"]); + //~^ use of unstable library feature +} diff --git a/tests/ui/consts/const-format-arguments.stderr b/tests/ui/consts/const-format-arguments.stderr new file mode 100644 index 0000000000000..46f5c642f8e0d --- /dev/null +++ b/tests/ui/consts/const-format-arguments.stderr @@ -0,0 +1,20 @@ +error[E0658]: use of unstable library feature 'fmt_internals' + --> $DIR/const-format-arguments.rs:3:36 + | +LL | const A: std::fmt::Arguments = std::fmt::Arguments::new_const(&[&"hola"]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(fmt_internals)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: `Arguments::<'a>::new_const` is not yet stable as a const fn + --> $DIR/const-format-arguments.rs:3:36 + | +LL | const A: std::fmt::Arguments = std::fmt::Arguments::new_const(&[&"hola"]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(const_fmt_arguments_new)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`.