From 7759822229d1920304326d48c7b5f0edf7f063bb Mon Sep 17 00:00:00 2001 From: mu001999 Date: Mon, 5 Aug 2024 23:22:33 +0800 Subject: [PATCH] Removes dead code from the compiler/standard library --- compiler/rustc_incremental/messages.ftl | 2 - compiler/rustc_incremental/src/errors.rs | 7 - compiler/rustc_passes/messages.ftl | 4 - compiler/rustc_passes/src/errors.rs | 7 - .../src/maybe_transmutable/query_context.rs | 6 +- library/alloc/tests/boxed.rs | 122 ------------------ 6 files changed, 1 insertion(+), 147 deletions(-) diff --git a/compiler/rustc_incremental/messages.ftl b/compiler/rustc_incremental/messages.ftl index de2177ebb6e0f..2a65101d360d3 100644 --- a/compiler/rustc_incremental/messages.ftl +++ b/compiler/rustc_incremental/messages.ftl @@ -99,6 +99,4 @@ incremental_unrecognized_depnode = unrecognized `DepNode` variant: {$name} incremental_unrecognized_depnode_label = dep-node label `{$label}` not recognized -incremental_write_dep_graph = failed to write dependency graph to `{$path}`: {$err} - incremental_write_new = failed to write {$name} to `{$path}`: {$err} diff --git a/compiler/rustc_incremental/src/errors.rs b/compiler/rustc_incremental/src/errors.rs index f891003063440..889795f3dadec 100644 --- a/compiler/rustc_incremental/src/errors.rs +++ b/compiler/rustc_incremental/src/errors.rs @@ -272,13 +272,6 @@ pub struct LoadDepGraph { pub err: std::io::Error, } -#[derive(Diagnostic)] -#[diag(incremental_write_dep_graph)] -pub struct WriteDepGraph<'a> { - pub path: &'a Path, - pub err: std::io::Error, -} - #[derive(Diagnostic)] #[diag(incremental_move_dep_graph)] pub struct MoveDepGraph<'a> { diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 59c9d1e49f5b3..85dc4bcbb94ff 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -471,10 +471,6 @@ passes_must_not_suspend = `must_not_suspend` attribute should be applied to a struct, enum, or trait .label = is not a struct, enum, or trait -passes_must_use_async = - `must_use` attribute on `async` functions applies to the anonymous `Future` returned by the function, not the value within - .label = this attribute does nothing, the `Future`s returned by async functions are already `must_use` - passes_must_use_no_effect = `#[must_use]` has no effect when applied to {$article} {$target} diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 36dfc40e7628b..097b0dfc01577 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -371,13 +371,6 @@ pub struct FfiConstInvalidTarget { pub attr_span: Span, } -#[derive(LintDiagnostic)] -#[diag(passes_must_use_async)] -pub struct MustUseAsync { - #[label] - pub span: Span, -} - #[derive(LintDiagnostic)] #[diag(passes_must_use_no_effect)] pub struct MustUseNoEffect { diff --git a/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs b/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs index 95373916a71ae..f8b59bdf32684 100644 --- a/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs +++ b/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs @@ -4,7 +4,6 @@ use crate::layout; pub(crate) trait QueryContext { type Def: layout::Def; type Ref: layout::Ref; - type Scope: Copy; } #[cfg(test)] @@ -28,20 +27,17 @@ pub(crate) mod test { impl QueryContext for UltraMinimal { type Def = Def; type Ref = !; - type Scope = (); } } #[cfg(feature = "rustc")] mod rustc { - use rustc_middle::ty::{Ty, TyCtxt}; + use rustc_middle::ty::TyCtxt; use super::*; impl<'tcx> super::QueryContext for TyCtxt<'tcx> { type Def = layout::rustc::Def<'tcx>; type Ref = layout::rustc::Ref<'tcx>; - - type Scope = Ty<'tcx>; } } diff --git a/library/alloc/tests/boxed.rs b/library/alloc/tests/boxed.rs index 4cacee0414d7d..e379a80fae7c7 100644 --- a/library/alloc/tests/boxed.rs +++ b/library/alloc/tests/boxed.rs @@ -1,4 +1,3 @@ -use core::alloc::{AllocError, Allocator, Layout}; use core::cell::Cell; use core::mem::MaybeUninit; use core::ptr::NonNull; @@ -58,124 +57,3 @@ fn box_deref_lval() { x.set(1000); assert_eq!(x.get(), 1000); } - -pub struct ConstAllocator; - -unsafe impl Allocator for ConstAllocator { - fn allocate(&self, layout: Layout) -> Result, AllocError> { - match layout.size() { - 0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)), - _ => unsafe { - let ptr = core::intrinsics::const_allocate(layout.size(), layout.align()); - Ok(NonNull::new_unchecked(ptr as *mut [u8; 0] as *mut [u8])) - }, - } - } - - unsafe fn deallocate(&self, _ptr: NonNull, layout: Layout) { - match layout.size() { - 0 => { /* do nothing */ } - _ => { /* do nothing too */ } - } - } - - fn allocate_zeroed(&self, layout: Layout) -> Result, AllocError> { - let ptr = self.allocate(layout)?; - if layout.size() > 0 { - unsafe { - ptr.as_mut_ptr().write_bytes(0, layout.size()); - } - } - Ok(ptr) - } - - unsafe fn grow( - &self, - ptr: NonNull, - old_layout: Layout, - new_layout: Layout, - ) -> Result, AllocError> { - debug_assert!( - new_layout.size() >= old_layout.size(), - "`new_layout.size()` must be greater than or equal to `old_layout.size()`" - ); - - let new_ptr = self.allocate(new_layout)?; - if new_layout.size() > 0 { - // Safety: `new_ptr` is valid for writes and `ptr` for reads of - // `old_layout.size()`, because `new_layout.size() >= - // old_layout.size()` (which is an invariant that must be upheld by - // callers). - unsafe { - new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), old_layout.size()); - } - // Safety: `ptr` is never used again is also an invariant which must - // be upheld by callers. - unsafe { - self.deallocate(ptr, old_layout); - } - } - Ok(new_ptr) - } - - unsafe fn grow_zeroed( - &self, - ptr: NonNull, - old_layout: Layout, - new_layout: Layout, - ) -> Result, AllocError> { - // Safety: Invariants of `grow_zeroed` and `grow` are the same, and must - // be enforced by callers. - let new_ptr = unsafe { self.grow(ptr, old_layout, new_layout)? }; - if new_layout.size() > 0 { - let old_size = old_layout.size(); - let new_size = new_layout.size(); - let raw_ptr = new_ptr.as_mut_ptr(); - // Safety: - // - `grow` returned Ok, so the returned pointer must be valid for - // `new_size` bytes - // - `new_size` must be larger than `old_size`, which is an - // invariant which must be upheld by callers. - unsafe { - raw_ptr.add(old_size).write_bytes(0, new_size - old_size); - } - } - Ok(new_ptr) - } - - unsafe fn shrink( - &self, - ptr: NonNull, - old_layout: Layout, - new_layout: Layout, - ) -> Result, AllocError> { - debug_assert!( - new_layout.size() <= old_layout.size(), - "`new_layout.size()` must be smaller than or equal to `old_layout.size()`" - ); - - let new_ptr = self.allocate(new_layout)?; - if new_layout.size() > 0 { - // Safety: `new_ptr` and `ptr` are valid for reads/writes of - // `new_layout.size()` because of the invariants of shrink, which - // include `new_layout.size()` being smaller than (or equal to) - // `old_layout.size()`. - unsafe { - new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), new_layout.size()); - } - // Safety: `ptr` is never used again is also an invariant which must - // be upheld by callers. - unsafe { - self.deallocate(ptr, old_layout); - } - } - Ok(new_ptr) - } - - fn by_ref(&self) -> &Self - where - Self: Sized, - { - self - } -}