Skip to content

Commit c6db1ca

Browse files
committed
Auto merge of #129563 - matthiaskrgr:rollup-t6bai2d, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #129091 (add Box::as_ptr and Box::as_mut_ptr methods) - #129134 (bootstrap: improve error recovery flags to curl) - #129416 (library: Move unstable API of new_uninit to new features) - #129459 (handle stage0 `cargo` and `rustc` separately) - #129487 (repr_transparent_external_private_fields: special-case some std types) - #129511 (Update minifier to 0.3.1) - #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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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,

0 commit comments

Comments
 (0)