-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use str::to_owned for
format!
without formatting arguments
- Loading branch information
Showing
6 changed files
with
116 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// min-llvm-version: 10.0.0 | ||
// compile-flags: -C opt-level=3 | ||
#![crate_type = "rlib"] | ||
#![feature(format_args_capture)] | ||
|
||
// Make sure allocation not happen when result of `format!` is unused and | ||
// there are no formatting arguments. | ||
|
||
// CHECK-LABEL: @format_wo_fmt_args | ||
// CHECK-NEXT: {{"_ZN[^:]+"}}: | ||
// CHECK-NEXT: ret | ||
#[no_mangle] | ||
pub fn format_wo_fmt_args() { | ||
format!(""); | ||
format!("a long story"); | ||
format!("a long story {{"); | ||
} | ||
|
||
// CHECK-LABEL: @format_wo_fmt_args_ret | ||
// CHECK-NOT: Arguments | ||
#[no_mangle] | ||
pub fn format_wo_fmt_args_ret() -> String { | ||
format!("a long story") | ||
} | ||
|
||
// CHECK-LABEL: @format_w_fmt_args_ret_1 | ||
// CHECK: alloc::fmt::format | ||
#[no_mangle] | ||
pub fn format_w_fmt_args_ret_1(n: usize) -> String { | ||
format!("a long story: {}", n) | ||
} | ||
|
||
// CHECK-LABEL: @format_w_fmt_args_ret_2 | ||
// CHECK: core::fmt::ArgumentV1::from_usize | ||
// CHECK: alloc::fmt::format | ||
#[no_mangle] | ||
pub fn format_w_fmt_args_ret_2(n: usize, width: usize) -> String { | ||
format!("a long story {n:width$}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters