Minic rustc's new format_args! expansion

This commit is contained in:
Shoyu Vanilla 2025-06-22 03:00:20 +09:00
parent c13859903c
commit 4f8767d790
7 changed files with 366 additions and 41 deletions

View file

@ -628,6 +628,17 @@ fn main() {
#[test]
fn orphan_unsafe_format_args() {
// Checks that we don't place orphan arguments for formatting under an unsafe block.
check_diagnostics(
r#"
//- minicore: fmt_before_1_89_0
fn foo() {
let p = 0xDEADBEEF as *const i32;
format_args!("", *p);
// ^^ error: dereference of raw pointer is unsafe and requires an unsafe function or block
}
"#,
);
check_diagnostics(
r#"
//- minicore: fmt
@ -958,4 +969,18 @@ impl FooTrait for S2 {
"#,
);
}
#[test]
fn no_false_positive_on_format_args_since_1_89_0() {
check_diagnostics(
r#"
//- minicore: fmt
fn test() {
let foo = 10;
let bar = true;
let _x = format_args!("{} {0} {} {last}", foo, bar, last = "!");
}
"#,
);
}
}