Skip to content

Commit 4831dce

Browse files
Revert "revert impl Display change"
This reverts commit 32fb9cd.
1 parent 32fb9cd commit 4831dce

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::borrow::Cow;
22
use std::cell::Cell;
33
use std::convert::TryFrom;
4+
use std::fmt::Display;
45
use std::ops::Deref;
56

67
use gccjit::{
@@ -526,14 +527,14 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
526527
self.block
527528
}
528529

529-
fn append_block(cx: &'a CodegenCx<'gcc, 'tcx>, func: RValue<'gcc>, name: &str) -> Block<'gcc> {
530+
fn append_block(cx: &'a CodegenCx<'gcc, 'tcx>, func: RValue<'gcc>, name: impl Display) -> Block<'gcc> {
530531
let func = cx.rvalue_as_function(func);
531-
func.new_block(name)
532+
func.new_block(name.to_string())
532533
}
533534

534-
fn append_sibling_block(&mut self, name: &str) -> Block<'gcc> {
535+
fn append_sibling_block(&mut self, name: impl Display) -> Block<'gcc> {
535536
let func = self.current_func();
536-
func.new_block(name)
537+
func.new_block(name.to_string())
537538
}
538539

539540
fn switch_to_block(&mut self, block: Self::BasicBlock) {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
2626
use rustc_target::spec::{HasTargetSpec, SanitizerSet, Target};
2727
use smallvec::SmallVec;
2828
use std::borrow::Cow;
29+
use std::fmt::Display;
2930
use std::iter;
3031
use std::ops::Deref;
3132
use std::ptr;
@@ -153,20 +154,24 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
153154

154155
fn set_span(&mut self, _span: Span) {}
155156

156-
fn append_block(cx: &'a CodegenCx<'ll, 'tcx>, llfn: &'ll Value, name: &str) -> &'ll BasicBlock {
157+
fn append_block(
158+
cx: &'a CodegenCx<'ll, 'tcx>,
159+
llfn: &'ll Value,
160+
name: impl Display,
161+
) -> &'ll BasicBlock {
157162
unsafe {
158163
let c_str_name;
159164
let name_ptr = if cx.tcx.sess.fewer_names() {
160165
const { c"".as_ptr().cast() }
161166
} else {
162-
c_str_name = SmallCStr::new(name);
167+
c_str_name = SmallCStr::new(&name.to_string());
163168
c_str_name.as_ptr()
164169
};
165170
llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, name_ptr)
166171
}
167172
}
168173

169-
fn append_sibling_block(&mut self, name: &str) -> &'ll BasicBlock {
174+
fn append_sibling_block(&mut self, name: impl Display) -> &'ll BasicBlock {
170175
Self::append_block(self.cx, self.llfn(), name)
171176
}
172177

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
8383
// Cross-funclet jump - need a trampoline
8484
debug_assert!(base::wants_new_eh_instructions(fx.cx.tcx().sess));
8585
debug!("llbb_with_cleanup: creating cleanup trampoline for {:?}", target);
86-
let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
87-
let trampoline_llbb = Bx::append_block(fx.cx, fx.llfn, name);
86+
let trampoline_llbb = Bx::append_block(
87+
fx.cx,
88+
fx.llfn,
89+
format_args!("{:?}_cleanup_trampoline_{:?}", self.bb, target),
90+
);
8891
let mut trampoline_bx = Bx::build(fx.cx, trampoline_llbb);
8992
trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
9093
trampoline_llbb
@@ -1565,7 +1568,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
15651568
fn landing_pad_for_uncached(&mut self, bb: mir::BasicBlock) -> Bx::BasicBlock {
15661569
let llbb = self.llbb(bb);
15671570
if base::wants_new_eh_instructions(self.cx.sess()) {
1568-
let cleanup_bb = Bx::append_block(self.cx, self.llfn, &format!("funclet_{bb:?}"));
1571+
let cleanup_bb = Bx::append_block(self.cx, self.llfn, format_args!("funclet_{bb:?}"));
15691572
let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
15701573
let funclet = cleanup_bx.cleanup_pad(None, &[]);
15711574
cleanup_bx.br(llbb);
@@ -1688,7 +1691,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16881691
pub fn try_llbb(&mut self, bb: mir::BasicBlock) -> Option<Bx::BasicBlock> {
16891692
match self.cached_llbbs[bb] {
16901693
CachedLlbb::None => {
1691-
let llbb = Bx::append_block(self.cx, self.llfn, &format!("{bb:?}"));
1694+
let llbb = Bx::append_block(self.cx, self.llfn, format_args!("{bb:?}"));
16921695
self.cached_llbbs[bb] = CachedLlbb::Some(llbb);
16931696
Some(llbb)
16941697
}

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use rustc_target::abi::call::FnAbi;
2222
use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
2323
use rustc_target::spec::HasTargetSpec;
2424

25+
use std::fmt::Display;
26+
2527
#[derive(Copy, Clone)]
2628
pub enum OverflowOp {
2729
Add,
@@ -49,9 +51,13 @@ pub trait BuilderMethods<'a, 'tcx>:
4951
fn set_span(&mut self, span: Span);
5052

5153
// FIXME(eddyb) replace uses of this with `append_sibling_block`.
52-
fn append_block(cx: &'a Self::CodegenCx, llfn: Self::Function, name: &str) -> Self::BasicBlock;
54+
fn append_block(
55+
cx: &'a Self::CodegenCx,
56+
llfn: Self::Function,
57+
name: impl Display,
58+
) -> Self::BasicBlock;
5359

54-
fn append_sibling_block(&mut self, name: &str) -> Self::BasicBlock;
60+
fn append_sibling_block(&mut self, name: impl Display) -> Self::BasicBlock;
5561

5662
fn switch_to_block(&mut self, llbb: Self::BasicBlock);
5763

0 commit comments

Comments
 (0)