diff options
| author | bors <bors@rust-lang.org> | 2023-08-06 09:29:48 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-08-06 09:29:48 +0000 | 
| commit | a339ed184f6824c88b9e1f4ea524e09f72908ebf (patch) | |
| tree | a3b4180e7cdc0c368d93989fa59e7a8f21742df8 /compiler | |
| parent | 11467b1c2a56bd2fd8272a7413190c814cfcba1f (diff) | |
| parent | e57a89174c2fdafb2d462bf99fde2df92e362f00 (diff) | |
| download | rust-a339ed184f6824c88b9e1f4ea524e09f72908ebf.tar.gz rust-a339ed184f6824c88b9e1f4ea524e09f72908ebf.zip | |
Auto merge of #114528 - dtolnay:globalalloccast, r=cjgillot
Delete some useless casts from global_allocator expansion
These casts are from when #\[global_allocator\] needed to translate back and forth between `*mut u8` and `*mut Opaque`. This should have been cleaned up as part of https://github.com/rust-lang/rust/pull/51241/commits/f6ab74b8e7efed01c1045773b6693f23f6ebd93c.
Difference to code generated by `#[global_allocator] static ALLOCATOR: Allocator = Allocator;`:
```diff
 const _: () = {
     #[rustc_std_internal_symbol]
     unsafe fn __rust_alloc(arg0: usize, arg1: usize) -> *mut u8 {
         ::core::alloc::GlobalAlloc::alloc(
             &ALLOCATOR,
             ::core::alloc::Layout::from_size_align_unchecked(arg0, arg1),
-        ) as *mut u8
+        )
     }
     #[rustc_std_internal_symbol]
     unsafe fn __rust_dealloc(arg0: *mut u8, arg1: usize, arg2: usize) -> () {
         ::core::alloc::GlobalAlloc::dealloc(
             &ALLOCATOR,
-            arg0 as *mut u8,
+            arg0,
             ::core::alloc::Layout::from_size_align_unchecked(arg1, arg2),
         )
     }
     #[rustc_std_internal_symbol]
     unsafe fn __rust_realloc(
         arg0: *mut u8,
         arg1: usize,
         arg2: usize,
         arg3: usize,
     ) -> *mut u8 {
         ::core::alloc::GlobalAlloc::realloc(
             &ALLOCATOR,
-            arg0 as *mut u8,
+            arg0,
             ::core::alloc::Layout::from_size_align_unchecked(arg1, arg2),
             arg3,
-        ) as *mut u8
+        )
     }
     #[rustc_std_internal_symbol]
     unsafe fn __rust_alloc_zeroed(arg0: usize, arg1: usize) -> *mut u8 {
         ::core::alloc::GlobalAlloc::alloc_zeroed(
             &ALLOCATOR,
             ::core::alloc::Layout::from_size_align_unchecked(arg0, arg1),
-        ) as *mut u8
+        )
     }
 };
```
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/global_allocator.rs | 20 | 
1 files changed, 6 insertions, 14 deletions
| diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 053f5730f6e..7bded6b1d82 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -78,11 +78,11 @@ impl AllocFnFactory<'_, '_> { }; let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, &mut mk)).collect(); let result = self.call_allocator(method.name, args); - let (output_ty, output_expr) = self.ret_ty(&method.output, result); + let output_ty = self.ret_ty(&method.output); let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty)); let header = FnHeader { unsafety: Unsafe::Yes(self.span), ..FnHeader::default() }; let sig = FnSig { decl, header, span: self.span }; - let body = Some(self.cx.block_expr(output_expr)); + let body = Some(self.cx.block_expr(result)); let kind = ItemKind::Fn(Box::new(Fn { defaultness: ast::Defaultness::Final, sig, @@ -140,8 +140,7 @@ impl AllocFnFactory<'_, '_> { AllocatorTy::Ptr => { let ident = ident(); args.push(self.cx.param(self.span, ident, self.ptr_u8())); - let arg = self.cx.expr_ident(self.span, ident); - self.cx.expr_cast(self.span, arg, self.ptr_u8()) + self.cx.expr_ident(self.span, ident) } AllocatorTy::Usize => { @@ -156,18 +155,11 @@ impl AllocFnFactory<'_, '_> { } } - fn ret_ty(&self, ty: &AllocatorTy, expr: P<Expr>) -> (P<Ty>, P<Expr>) { + fn ret_ty(&self, ty: &AllocatorTy) -> P<Ty> { match *ty { - AllocatorTy::ResultPtr => { - // We're creating: - // - // #expr as *mut u8 - - let expr = self.cx.expr_cast(self.span, expr, self.ptr_u8()); - (self.ptr_u8(), expr) - } + AllocatorTy::ResultPtr => self.ptr_u8(), - AllocatorTy::Unit => (self.cx.ty(self.span, TyKind::Tup(ThinVec::new())), expr), + AllocatorTy::Unit => self.cx.ty(self.span, TyKind::Tup(ThinVec::new())), AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => { panic!("can't convert `AllocatorTy` to an output") | 
