Skip to content

Commit c6db1ca

Browse files
committed
Auto merge of rust-lang#129563 - matthiaskrgr:rollup-t6bai2d, r=matthiaskrgr
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
2 parents 1a94d83 + 86d5c53 commit c6db1ca

File tree

30 files changed

+291
-33
lines changed

30 files changed

+291
-33
lines changed

Cargo.lock

+5-2
Original file line numberDiff line numberDiff line change
@@ -2226,9 +2226,12 @@ dependencies = [
22262226

22272227
[[package]]
22282228
name = "minifier"
2229-
version = "0.3.0"
2229+
version = "0.3.1"
22302230
source = "registry+https://github.com/rust-lang/crates.io-index"
2231-
checksum = "95bbbf96b9ac3482c2a25450b67a15ed851319bc5fabf3b40742ea9066e84282"
2231+
checksum = "9aa3f302fe0f8de065d4a2d1ed64f60204623cac58b80cd3c2a83a25d5a7d437"
2232+
dependencies = [
2233+
"clap",
2234+
]
22322235

22332236
[[package]]
22342237
name = "minimal-lexical"

compiler/rustc_feature/src/builtin_attrs.rs

+5
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
641641
ErrorFollowing, EncodeCrossCrate::Yes,
642642
"rustc_deprecated_safe_2024 is supposed to be used in libstd only",
643643
),
644+
rustc_attr!(
645+
rustc_pub_transparent, Normal, template!(Word),
646+
WarnFollowing, EncodeCrossCrate::Yes,
647+
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
648+
),
644649

645650

646651
// ==========================================================================

compiler/rustc_hir_analysis/src/check/check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,8 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
12591259
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
12601260
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
12611261
ty::Adt(def, args) => {
1262-
if !def.did().is_local() {
1262+
if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
1263+
{
12631264
let non_exhaustive = def.is_variant_list_non_exhaustive()
12641265
|| def
12651266
.variants()

compiler/rustc_index/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
33
#![cfg_attr(feature = "nightly", allow(internal_features))]
44
#![cfg_attr(feature = "nightly", feature(extend_one, new_uninit, step_trait, test))]
5+
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
56
// tidy-alphabetical-end
67

78
pub mod bit_set;

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#![feature(allocator_api)]
3535
#![feature(array_windows)]
3636
#![feature(assert_matches)]
37+
#![feature(box_as_ptr)]
3738
#![feature(box_patterns)]
3839
#![feature(closure_track_caller)]
3940
#![feature(const_option)]

compiler/rustc_middle/src/mir/interpret/allocation.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ impl AllocBytes for Box<[u8]> {
6262
}
6363

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

6968
fn as_ptr(&self) -> *const u8 {
70-
// Carefully avoiding any intermediate references.
71-
ptr::addr_of!(**self).cast()
69+
Box::as_ptr(self).cast()
7270
}
7371
}
7472

compiler/rustc_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ passes_rustc_lint_opt_ty =
657657
`#[rustc_lint_opt_ty]` should be applied to a struct
658658
.label = not a struct
659659
660+
passes_rustc_pub_transparent =
661+
attribute should be applied to `#[repr(transparent)]` types
662+
.label = not a `#[repr(transparent)]` type
663+
660664
passes_rustc_safe_intrinsic =
661665
attribute should be applied to intrinsic functions
662666
.label = not an intrinsic function

compiler/rustc_passes/src/check_attr.rs

+13
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
245245
self.check_coroutine(attr, target);
246246
}
247247
[sym::linkage, ..] => self.check_linkage(attr, span, target),
248+
[sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent( attr.span, span, attrs),
248249
[
249250
// ok
250251
sym::allow
@@ -2381,6 +2382,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23812382
}
23822383
}
23832384
}
2385+
2386+
fn check_rustc_pub_transparent(&self, attr_span: Span, span: Span, attrs: &[Attribute]) {
2387+
if !attrs
2388+
.iter()
2389+
.filter(|attr| attr.has_name(sym::repr))
2390+
.filter_map(|attr| attr.meta_item_list())
2391+
.flatten()
2392+
.any(|nmi| nmi.has_name(sym::transparent))
2393+
{
2394+
self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span });
2395+
}
2396+
}
23842397
}
23852398

23862399
impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {

compiler/rustc_passes/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,15 @@ pub struct RustcStdInternalSymbol {
622622
pub span: Span,
623623
}
624624

625+
#[derive(Diagnostic)]
626+
#[diag(passes_rustc_pub_transparent)]
627+
pub struct RustcPubTransparent {
628+
#[primary_span]
629+
pub attr_span: Span,
630+
#[label]
631+
pub span: Span,
632+
}
633+
625634
#[derive(Diagnostic)]
626635
#[diag(passes_link_ordinal)]
627636
pub struct LinkOrdinal {

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ symbols! {
16741674
rustc_private,
16751675
rustc_proc_macro_decls,
16761676
rustc_promotable,
1677+
rustc_pub_transparent,
16771678
rustc_reallocator,
16781679
rustc_regions,
16791680
rustc_reservation_impl,

compiler/rustc_type_ir/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ nightly = [
3131
"rustc_index/nightly",
3232
"rustc_ast_ir/nightly"
3333
]
34+
35+
[lints.rust]
36+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(bootstrap)'] }

compiler/rustc_type_ir/src/elaborate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn supertrait_def_ids<I: Interner>(
237237
cx: I,
238238
trait_def_id: I::DefId,
239239
) -> impl Iterator<Item = I::DefId> {
240-
let mut set = HashSet::default();
240+
let mut set: HashSet<I::DefId> = HashSet::default();
241241
let mut stack = vec![trait_def_id];
242242

243243
set.insert(trait_def_id);

compiler/rustc_type_ir/src/outlives.rs

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ struct OutlivesCollector<'a, I: Interner> {
6868
}
6969

7070
impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
71+
#[cfg(not(feature = "nightly"))]
72+
type Result = ();
73+
7174
fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
7275
if !self.visited.insert(ty) {
7376
return;

compiler/rustc_type_ir/src/search_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<X: Cx> NestedGoals<X> {
287287
}
288288
}
289289

290-
#[rustc_lint_query_instability]
290+
#[cfg_attr(feature = "nightly", rustc_lint_query_instability)]
291291
#[allow(rustc::potential_query_instability)]
292292
fn iter(&self) -> impl Iterator<Item = (X::Input, UsageKind)> + '_ {
293293
self.nested_goals.iter().map(|(i, p)| (*i, *p))

library/alloc/src/boxed.rs

+95-3
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ impl<T> Box<T> {
293293
///
294294
/// ```
295295
/// #![feature(new_uninit)]
296+
/// #![feature(new_zeroed_alloc)]
296297
///
297298
/// let zero = Box::<u32>::new_zeroed();
298299
/// let zero = unsafe { zero.assume_init() };
@@ -303,7 +304,7 @@ impl<T> Box<T> {
303304
/// [zeroed]: mem::MaybeUninit::zeroed
304305
#[cfg(not(no_global_oom_handling))]
305306
#[inline]
306-
#[unstable(feature = "new_uninit", issue = "63291")]
307+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
307308
#[must_use]
308309
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
309310
Self::new_zeroed_in(Global)
@@ -684,6 +685,7 @@ impl<T> Box<[T]> {
684685
/// # Examples
685686
///
686687
/// ```
688+
/// #![feature(new_zeroed_alloc)]
687689
/// #![feature(new_uninit)]
688690
///
689691
/// let values = Box::<[u32]>::new_zeroed_slice(3);
@@ -694,7 +696,7 @@ impl<T> Box<[T]> {
694696
///
695697
/// [zeroed]: mem::MaybeUninit::zeroed
696698
#[cfg(not(no_global_oom_handling))]
697-
#[unstable(feature = "new_uninit", issue = "63291")]
699+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
698700
#[must_use]
699701
pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
700702
unsafe { RawVec::with_capacity_zeroed(len).into_box(len) }
@@ -955,6 +957,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
955957
/// # Examples
956958
///
957959
/// ```
960+
/// #![feature(box_uninit_write)]
958961
/// #![feature(new_uninit)]
959962
///
960963
/// let big_box = Box::<[usize; 1024]>::new_uninit();
@@ -972,7 +975,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
972975
/// assert_eq!(*x, i);
973976
/// }
974977
/// ```
975-
#[unstable(feature = "new_uninit", issue = "63291")]
978+
#[unstable(feature = "box_uninit_write", issue = "129397")]
976979
#[inline]
977980
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
978981
unsafe {
@@ -1254,6 +1257,95 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12541257
unsafe { (Unique::from(&mut *ptr), alloc) }
12551258
}
12561259

1260+
/// Returns a raw mutable pointer to the `Box`'s contents.
1261+
///
1262+
/// The caller must ensure that the `Box` outlives the pointer this
1263+
/// function returns, or else it will end up dangling.
1264+
///
1265+
/// This method guarantees that for the purpose of the aliasing model, this method
1266+
/// does not materialize a reference to the underlying memory, and thus the returned pointer
1267+
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
1268+
/// Note that calling other methods that materialize references to the memory
1269+
/// may still invalidate this pointer.
1270+
/// See the example below for how this guarantee can be used.
1271+
///
1272+
/// # Examples
1273+
///
1274+
/// Due to the aliasing guarantee, the following code is legal:
1275+
///
1276+
/// ```rust
1277+
/// #![feature(box_as_ptr)]
1278+
///
1279+
/// unsafe {
1280+
/// let mut b = Box::new(0);
1281+
/// let ptr1 = Box::as_mut_ptr(&mut b);
1282+
/// ptr1.write(1);
1283+
/// let ptr2 = Box::as_mut_ptr(&mut b);
1284+
/// ptr2.write(2);
1285+
/// // Notably, the write to `ptr2` did *not* invalidate `ptr1`:
1286+
/// ptr1.write(3);
1287+
/// }
1288+
/// ```
1289+
///
1290+
/// [`as_mut_ptr`]: Self::as_mut_ptr
1291+
/// [`as_ptr`]: Self::as_ptr
1292+
#[unstable(feature = "box_as_ptr", issue = "129090")]
1293+
#[rustc_never_returns_null_ptr]
1294+
#[inline]
1295+
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
1296+
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
1297+
// any references.
1298+
ptr::addr_of_mut!(**b)
1299+
}
1300+
1301+
/// Returns a raw pointer to the `Box`'s contents.
1302+
///
1303+
/// The caller must ensure that the `Box` outlives the pointer this
1304+
/// function returns, or else it will end up dangling.
1305+
///
1306+
/// The caller must also ensure that the memory the pointer (non-transitively) points to
1307+
/// is never written to (except inside an `UnsafeCell`) using this pointer or any pointer
1308+
/// derived from it. If you need to mutate the contents of the `Box`, use [`as_mut_ptr`].
1309+
///
1310+
/// This method guarantees that for the purpose of the aliasing model, this method
1311+
/// does not materialize a reference to the underlying memory, and thus the returned pointer
1312+
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
1313+
/// Note that calling other methods that materialize mutable references to the memory,
1314+
/// as well as writing to this memory, may still invalidate this pointer.
1315+
/// See the example below for how this guarantee can be used.
1316+
///
1317+
/// # Examples
1318+
///
1319+
/// Due to the aliasing guarantee, the following code is legal:
1320+
///
1321+
/// ```rust
1322+
/// #![feature(box_as_ptr)]
1323+
///
1324+
/// unsafe {
1325+
/// let mut v = Box::new(0);
1326+
/// let ptr1 = Box::as_ptr(&v);
1327+
/// let ptr2 = Box::as_mut_ptr(&mut v);
1328+
/// let _val = ptr2.read();
1329+
/// // No write to this memory has happened yet, so `ptr1` is still valid.
1330+
/// let _val = ptr1.read();
1331+
/// // However, once we do a write...
1332+
/// ptr2.write(1);
1333+
/// // ... `ptr1` is no longer valid.
1334+
/// // This would be UB: let _val = ptr1.read();
1335+
/// }
1336+
/// ```
1337+
///
1338+
/// [`as_mut_ptr`]: Self::as_mut_ptr
1339+
/// [`as_ptr`]: Self::as_ptr
1340+
#[unstable(feature = "box_as_ptr", issue = "129090")]
1341+
#[rustc_never_returns_null_ptr]
1342+
#[inline]
1343+
pub fn as_ptr(b: &Self) -> *const T {
1344+
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
1345+
// any references.
1346+
ptr::addr_of!(**b)
1347+
}
1348+
12571349
/// Returns a reference to the underlying allocator.
12581350
///
12591351
/// Note: this is an associated function, which means that you have

library/alloc/src/rc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ impl<T> Rc<T> {
539539
/// # Examples
540540
///
541541
/// ```
542+
/// #![feature(new_zeroed_alloc)]
542543
/// #![feature(new_uninit)]
543544
///
544545
/// use std::rc::Rc;
@@ -551,7 +552,7 @@ impl<T> Rc<T> {
551552
///
552553
/// [zeroed]: mem::MaybeUninit::zeroed
553554
#[cfg(not(no_global_oom_handling))]
554-
#[unstable(feature = "new_uninit", issue = "63291")]
555+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
555556
#[must_use]
556557
pub fn new_zeroed() -> Rc<mem::MaybeUninit<T>> {
557558
unsafe {
@@ -1000,6 +1001,7 @@ impl<T> Rc<[T]> {
10001001
///
10011002
/// ```
10021003
/// #![feature(new_uninit)]
1004+
/// #![feature(new_zeroed_alloc)]
10031005
///
10041006
/// use std::rc::Rc;
10051007
///
@@ -1011,7 +1013,7 @@ impl<T> Rc<[T]> {
10111013
///
10121014
/// [zeroed]: mem::MaybeUninit::zeroed
10131015
#[cfg(not(no_global_oom_handling))]
1014-
#[unstable(feature = "new_uninit", issue = "63291")]
1016+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
10151017
#[must_use]
10161018
pub fn new_zeroed_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
10171019
unsafe {

library/alloc/src/sync.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ impl<T> Arc<T> {
542542
/// # Examples
543543
///
544544
/// ```
545+
/// #![feature(new_zeroed_alloc)]
545546
/// #![feature(new_uninit)]
546547
///
547548
/// use std::sync::Arc;
@@ -555,7 +556,7 @@ impl<T> Arc<T> {
555556
/// [zeroed]: mem::MaybeUninit::zeroed
556557
#[cfg(not(no_global_oom_handling))]
557558
#[inline]
558-
#[unstable(feature = "new_uninit", issue = "63291")]
559+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
559560
#[must_use]
560561
pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> {
561562
unsafe {
@@ -1134,6 +1135,7 @@ impl<T> Arc<[T]> {
11341135
/// # Examples
11351136
///
11361137
/// ```
1138+
/// #![feature(new_zeroed_alloc)]
11371139
/// #![feature(new_uninit)]
11381140
///
11391141
/// use std::sync::Arc;
@@ -1147,7 +1149,7 @@ impl<T> Arc<[T]> {
11471149
/// [zeroed]: mem::MaybeUninit::zeroed
11481150
#[cfg(not(no_global_oom_handling))]
11491151
#[inline]
1150-
#[unstable(feature = "new_uninit", issue = "63291")]
1152+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
11511153
#[must_use]
11521154
pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
11531155
unsafe {
@@ -1191,7 +1193,7 @@ impl<T, A: Allocator> Arc<[T], A> {
11911193
/// assert_eq!(*values, [1, 2, 3])
11921194
/// ```
11931195
#[cfg(not(no_global_oom_handling))]
1194-
#[unstable(feature = "new_uninit", issue = "63291")]
1196+
#[unstable(feature = "allocator_api", issue = "32838")]
11951197
#[inline]
11961198
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit<T>], A> {
11971199
unsafe { Arc::from_ptr_in(Arc::allocate_for_slice_in(len, &alloc), alloc) }
@@ -1220,7 +1222,7 @@ impl<T, A: Allocator> Arc<[T], A> {
12201222
///
12211223
/// [zeroed]: mem::MaybeUninit::zeroed
12221224
#[cfg(not(no_global_oom_handling))]
1223-
#[unstable(feature = "new_uninit", issue = "63291")]
1225+
#[unstable(feature = "allocator_api", issue = "32838")]
12241226
#[inline]
12251227
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit<T>], A> {
12261228
unsafe {

0 commit comments

Comments
 (0)