Skip to content

Commit e57a891

Browse files
committed
Delete some useless casts from global_allocator expansion
1 parent 11467b1 commit e57a891

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

compiler/rustc_builtin_macros/src/global_allocator.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ impl AllocFnFactory<'_, '_> {
7878
};
7979
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, &mut mk)).collect();
8080
let result = self.call_allocator(method.name, args);
81-
let (output_ty, output_expr) = self.ret_ty(&method.output, result);
81+
let output_ty = self.ret_ty(&method.output);
8282
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));
8383
let header = FnHeader { unsafety: Unsafe::Yes(self.span), ..FnHeader::default() };
8484
let sig = FnSig { decl, header, span: self.span };
85-
let body = Some(self.cx.block_expr(output_expr));
85+
let body = Some(self.cx.block_expr(result));
8686
let kind = ItemKind::Fn(Box::new(Fn {
8787
defaultness: ast::Defaultness::Final,
8888
sig,
@@ -140,8 +140,7 @@ impl AllocFnFactory<'_, '_> {
140140
AllocatorTy::Ptr => {
141141
let ident = ident();
142142
args.push(self.cx.param(self.span, ident, self.ptr_u8()));
143-
let arg = self.cx.expr_ident(self.span, ident);
144-
self.cx.expr_cast(self.span, arg, self.ptr_u8())
143+
self.cx.expr_ident(self.span, ident)
145144
}
146145

147146
AllocatorTy::Usize => {
@@ -156,18 +155,11 @@ impl AllocFnFactory<'_, '_> {
156155
}
157156
}
158157

159-
fn ret_ty(&self, ty: &AllocatorTy, expr: P<Expr>) -> (P<Ty>, P<Expr>) {
158+
fn ret_ty(&self, ty: &AllocatorTy) -> P<Ty> {
160159
match *ty {
161-
AllocatorTy::ResultPtr => {
162-
// We're creating:
163-
//
164-
// #expr as *mut u8
165-
166-
let expr = self.cx.expr_cast(self.span, expr, self.ptr_u8());
167-
(self.ptr_u8(), expr)
168-
}
160+
AllocatorTy::ResultPtr => self.ptr_u8(),
169161

170-
AllocatorTy::Unit => (self.cx.ty(self.span, TyKind::Tup(ThinVec::new())), expr),
162+
AllocatorTy::Unit => self.cx.ty(self.span, TyKind::Tup(ThinVec::new())),
171163

172164
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
173165
panic!("can't convert `AllocatorTy` to an output")

0 commit comments

Comments
 (0)