Skip to content

Commit

Permalink
Auto merge of rust-lang#129563 - matthiaskrgr:rollup-t6bai2d, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#129091 (add Box::as_ptr and Box::as_mut_ptr methods)
 - rust-lang#129134 (bootstrap: improve error recovery flags to curl)
 - rust-lang#129416 (library: Move unstable API of new_uninit to new features)
 - rust-lang#129459 (handle stage0 `cargo` and `rustc` separately)
 - rust-lang#129487 (repr_transparent_external_private_fields: special-case some std types)
 - rust-lang#129511 (Update minifier to 0.3.1)
 - rust-lang#129523 (Make `rustc_type_ir` build on stable)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 25, 2024
2 parents 1a94d83 + 86d5c53 commit 705176d
Show file tree
Hide file tree
Showing 30 changed files with 291 additions and 33 deletions.
7 changes: 5 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2226,9 +2226,12 @@ dependencies = [

[[package]]
name = "minifier"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95bbbf96b9ac3482c2a25450b67a15ed851319bc5fabf3b40742ea9066e84282"
checksum = "9aa3f302fe0f8de065d4a2d1ed64f60204623cac58b80cd3c2a83a25d5a7d437"
dependencies = [
"clap",
]

[[package]]
name = "minimal-lexical"
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ErrorFollowing, EncodeCrossCrate::Yes,
"rustc_deprecated_safe_2024 is supposed to be used in libstd only",
),
rustc_attr!(
rustc_pub_transparent, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::Yes,
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
),


// ==========================================================================
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,8 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
ty::Adt(def, args) => {
if !def.did().is_local() {
if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
{
let non_exhaustive = def.is_variant_list_non_exhaustive()
|| def
.variants()
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
#![cfg_attr(feature = "nightly", allow(internal_features))]
#![cfg_attr(feature = "nightly", feature(extend_one, new_uninit, step_trait, test))]
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
// tidy-alphabetical-end

pub mod bit_set;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#![feature(allocator_api)]
#![feature(array_windows)]
#![feature(assert_matches)]
#![feature(box_as_ptr)]
#![feature(box_patterns)]
#![feature(closure_track_caller)]
#![feature(const_option)]
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ impl AllocBytes for Box<[u8]> {
}

fn as_mut_ptr(&mut self) -> *mut u8 {
// Carefully avoiding any intermediate references.
ptr::addr_of_mut!(**self).cast()
Box::as_mut_ptr(self).cast()
}

fn as_ptr(&self) -> *const u8 {
// Carefully avoiding any intermediate references.
ptr::addr_of!(**self).cast()
Box::as_ptr(self).cast()
}
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ passes_rustc_lint_opt_ty =
`#[rustc_lint_opt_ty]` should be applied to a struct
.label = not a struct
passes_rustc_pub_transparent =
attribute should be applied to `#[repr(transparent)]` types
.label = not a `#[repr(transparent)]` type
passes_rustc_safe_intrinsic =
attribute should be applied to intrinsic functions
.label = not an intrinsic function
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_coroutine(attr, target);
}
[sym::linkage, ..] => self.check_linkage(attr, span, target),
[sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent( attr.span, span, attrs),
[
// ok
sym::allow
Expand Down Expand Up @@ -2381,6 +2382,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
}

fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attribute]) {
if !attrs
.iter()
.filter(|attr| attr.has_name(sym::repr))
.filter_map(|attr| attr.meta_item_list())
.flatten()
.any(|nmi| nmi.has_name(sym::transparent))
{
self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span });
}
}
}

impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,15 @@ pub struct RustcStdInternalSymbol {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(passes_rustc_pub_transparent)]
pub struct RustcPubTransparent {
#[primary_span]
pub attr_span: Span,
#[label]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(passes_link_ordinal)]
pub struct LinkOrdinal {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ symbols! {
rustc_private,
rustc_proc_macro_decls,
rustc_promotable,
rustc_pub_transparent,
rustc_reallocator,
rustc_regions,
rustc_reservation_impl,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_type_ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ nightly = [
"rustc_index/nightly",
"rustc_ast_ir/nightly"
]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bootstrap)'] }
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/elaborate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub fn supertrait_def_ids<I: Interner>(
cx: I,
trait_def_id: I::DefId,
) -> impl Iterator<Item = I::DefId> {
let mut set = HashSet::default();
let mut set: HashSet<I::DefId> = HashSet::default();
let mut stack = vec![trait_def_id];

set.insert(trait_def_id);
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_type_ir/src/outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct OutlivesCollector<'a, I: Interner> {
}

impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
#[cfg(not(feature = "nightly"))]
type Result = ();

fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
if !self.visited.insert(ty) {
return;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/search_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<X: Cx> NestedGoals<X> {
}
}

#[rustc_lint_query_instability]
#[cfg_attr(feature = "nightly", rustc_lint_query_instability)]
#[allow(rustc::potential_query_instability)]
fn iter(&self) -> impl Iterator<Item = (X::Input, UsageKind)> + '_ {
self.nested_goals.iter().map(|(i, p)| (*i, *p))
Expand Down
98 changes: 95 additions & 3 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ impl<T> Box<T> {
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(new_zeroed_alloc)]
///
/// let zero = Box::<u32>::new_zeroed();
/// let zero = unsafe { zero.assume_init() };
Expand All @@ -303,7 +304,7 @@ impl<T> Box<T> {
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[inline]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
#[must_use]
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
Self::new_zeroed_in(Global)
Expand Down Expand Up @@ -684,6 +685,7 @@ impl<T> Box<[T]> {
/// # Examples
///
/// ```
/// #![feature(new_zeroed_alloc)]
/// #![feature(new_uninit)]
///
/// let values = Box::<[u32]>::new_zeroed_slice(3);
Expand All @@ -694,7 +696,7 @@ impl<T> Box<[T]> {
///
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
#[must_use]
pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
unsafe { RawVec::with_capacity_zeroed(len).into_box(len) }
Expand Down Expand Up @@ -955,6 +957,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
/// # Examples
///
/// ```
/// #![feature(box_uninit_write)]
/// #![feature(new_uninit)]
///
/// let big_box = Box::<[usize; 1024]>::new_uninit();
Expand All @@ -972,7 +975,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
/// assert_eq!(*x, i);
/// }
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "box_uninit_write", issue = "129397")]
#[inline]
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
unsafe {
Expand Down Expand Up @@ -1254,6 +1257,95 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
unsafe { (Unique::from(&mut *ptr), alloc) }
}

/// Returns a raw mutable pointer to the `Box`'s contents.
///
/// The caller must ensure that the `Box` outlives the pointer this
/// function returns, or else it will end up dangling.
///
/// This method guarantees that for the purpose of the aliasing model, this method
/// does not materialize a reference to the underlying memory, and thus the returned pointer
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
/// Note that calling other methods that materialize references to the memory
/// may still invalidate this pointer.
/// See the example below for how this guarantee can be used.
///
/// # Examples
///
/// Due to the aliasing guarantee, the following code is legal:
///
/// ```rust
/// #![feature(box_as_ptr)]
///
/// unsafe {
/// let mut b = Box::new(0);
/// let ptr1 = Box::as_mut_ptr(&mut b);
/// ptr1.write(1);
/// let ptr2 = Box::as_mut_ptr(&mut b);
/// ptr2.write(2);
/// // Notably, the write to `ptr2` did *not* invalidate `ptr1`:
/// ptr1.write(3);
/// }
/// ```
///
/// [`as_mut_ptr`]: Self::as_mut_ptr
/// [`as_ptr`]: Self::as_ptr
#[unstable(feature = "box_as_ptr", issue = "129090")]
#[rustc_never_returns_null_ptr]
#[inline]
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
// any references.
ptr::addr_of_mut!(**b)
}

/// Returns a raw pointer to the `Box`'s contents.
///
/// The caller must ensure that the `Box` outlives the pointer this
/// function returns, or else it will end up dangling.
///
/// The caller must also ensure that the memory the pointer (non-transitively) points to
/// is never written to (except inside an `UnsafeCell`) using this pointer or any pointer
/// derived from it. If you need to mutate the contents of the `Box`, use [`as_mut_ptr`].
///
/// This method guarantees that for the purpose of the aliasing model, this method
/// does not materialize a reference to the underlying memory, and thus the returned pointer
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
/// Note that calling other methods that materialize mutable references to the memory,
/// as well as writing to this memory, may still invalidate this pointer.
/// See the example below for how this guarantee can be used.
///
/// # Examples
///
/// Due to the aliasing guarantee, the following code is legal:
///
/// ```rust
/// #![feature(box_as_ptr)]
///
/// unsafe {
/// let mut v = Box::new(0);
/// let ptr1 = Box::as_ptr(&v);
/// let ptr2 = Box::as_mut_ptr(&mut v);
/// let _val = ptr2.read();
/// // No write to this memory has happened yet, so `ptr1` is still valid.
/// let _val = ptr1.read();
/// // However, once we do a write...
/// ptr2.write(1);
/// // ... `ptr1` is no longer valid.
/// // This would be UB: let _val = ptr1.read();
/// }
/// ```
///
/// [`as_mut_ptr`]: Self::as_mut_ptr
/// [`as_ptr`]: Self::as_ptr
#[unstable(feature = "box_as_ptr", issue = "129090")]
#[rustc_never_returns_null_ptr]
#[inline]
pub fn as_ptr(b: &Self) -> *const T {
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
// any references.
ptr::addr_of!(**b)
}

/// Returns a reference to the underlying allocator.
///
/// Note: this is an associated function, which means that you have
Expand Down
6 changes: 4 additions & 2 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(new_zeroed_alloc)]
/// #![feature(new_uninit)]
///
/// use std::rc::Rc;
Expand All @@ -551,7 +552,7 @@ impl<T> Rc<T> {
///
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
#[must_use]
pub fn new_zeroed() -> Rc<mem::MaybeUninit<T>> {
unsafe {
Expand Down Expand Up @@ -1000,6 +1001,7 @@ impl<T> Rc<[T]> {
///
/// ```
/// #![feature(new_uninit)]
/// #![feature(new_zeroed_alloc)]
///
/// use std::rc::Rc;
///
Expand All @@ -1011,7 +1013,7 @@ impl<T> Rc<[T]> {
///
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
#[must_use]
pub fn new_zeroed_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
unsafe {
Expand Down
10 changes: 6 additions & 4 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ impl<T> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(new_zeroed_alloc)]
/// #![feature(new_uninit)]
///
/// use std::sync::Arc;
Expand All @@ -555,7 +556,7 @@ impl<T> Arc<T> {
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[inline]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
#[must_use]
pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> {
unsafe {
Expand Down Expand Up @@ -1134,6 +1135,7 @@ impl<T> Arc<[T]> {
/// # Examples
///
/// ```
/// #![feature(new_zeroed_alloc)]
/// #![feature(new_uninit)]
///
/// use std::sync::Arc;
Expand All @@ -1147,7 +1149,7 @@ impl<T> Arc<[T]> {
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[inline]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
#[must_use]
pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
unsafe {
Expand Down Expand Up @@ -1191,7 +1193,7 @@ impl<T, A: Allocator> Arc<[T], A> {
/// assert_eq!(*values, [1, 2, 3])
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "allocator_api", issue = "32838")]
#[inline]
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit<T>], A> {
unsafe { Arc::from_ptr_in(Arc::allocate_for_slice_in(len, &alloc), alloc) }
Expand Down Expand Up @@ -1220,7 +1222,7 @@ impl<T, A: Allocator> Arc<[T], A> {
///
/// [zeroed]: mem::MaybeUninit::zeroed
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "new_uninit", issue = "63291")]
#[unstable(feature = "allocator_api", issue = "32838")]
#[inline]
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit<T>], A> {
unsafe {
Expand Down
Loading

0 comments on commit 705176d

Please sign in to comment.