Skip to content

Commit 29414bf

Browse files
committed
Auto merge of #122045 - matthiaskrgr:rollup-5l3vpn7, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #121065 (Add basic i18n guidance for `Display`) - #121744 (Stop using Bubble in coherence and instead emulate it with an intercrate check) - #121829 (Dummy tweaks (attempt 2)) - #121857 (Implement async closure signature deduction) - #121894 (const_eval_select: make it safe but be careful with what we expose on stable for now) - #122014 (Change some attributes to only_local.) - #122016 (will_wake tests fail on Miri and that is expected) - #122018 (only set noalias on Box with the global allocator) - #122028 (Remove some dead code) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b6d2d84 + 4f73d2a commit 29414bf

File tree

44 files changed

+291
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+291
-133
lines changed

compiler/rustc_abi/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1612,8 +1612,9 @@ pub enum PointerKind {
16121612
SharedRef { frozen: bool },
16131613
/// Mutable reference. `unpin` indicates the absence of any pinned data.
16141614
MutableRef { unpin: bool },
1615-
/// Box. `unpin` indicates the absence of any pinned data.
1616-
Box { unpin: bool },
1615+
/// Box. `unpin` indicates the absence of any pinned data. `global` indicates whether this box
1616+
/// uses the global allocator or a custom one.
1617+
Box { unpin: bool, global: bool },
16171618
}
16181619

16191620
/// Note that this information is advisory only, and backends are free to ignore it.
@@ -1622,6 +1623,8 @@ pub enum PointerKind {
16221623
pub struct PointeeInfo {
16231624
pub size: Size,
16241625
pub align: Align,
1626+
/// If this is `None`, then this is a raw pointer, so size and alignment are not guaranteed to
1627+
/// be reliable.
16251628
pub safe: Option<PointerKind>,
16261629
}
16271630

compiler/rustc_ast/src/mut_visit.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,10 @@ pub fn noop_visit_capture_by<T: MutVisitor>(capture_by: &mut CaptureBy, vis: &mu
16041604
}
16051605
}
16061606

1607-
/// Some value for the AST node that is valid but possibly meaningless.
1607+
/// Some value for the AST node that is valid but possibly meaningless. Similar
1608+
/// to `Default` but not intended for wide use. The value will never be used
1609+
/// meaningfully, it exists just to support unwinding in `visit_clobber` in the
1610+
/// case where its closure panics.
16081611
pub trait DummyAstNode {
16091612
fn dummy() -> Self;
16101613
}
@@ -1679,19 +1682,6 @@ impl DummyAstNode for Stmt {
16791682
}
16801683
}
16811684

1682-
impl DummyAstNode for Block {
1683-
fn dummy() -> Self {
1684-
Block {
1685-
stmts: Default::default(),
1686-
id: DUMMY_NODE_ID,
1687-
rules: BlockCheckMode::Default,
1688-
span: Default::default(),
1689-
tokens: Default::default(),
1690-
could_be_bare_literal: Default::default(),
1691-
}
1692-
}
1693-
}
1694-
16951685
impl DummyAstNode for Crate {
16961686
fn dummy() -> Self {
16971687
Crate {

compiler/rustc_codegen_cranelift/example/mini_core.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,11 @@ pub struct Unique<T: ?Sized> {
525525
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
526526
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
527527

528+
#[lang = "global_alloc_ty"]
529+
pub struct Global;
530+
528531
#[lang = "owned_box"]
529-
pub struct Box<T: ?Sized, A = ()>(Unique<T>, A);
532+
pub struct Box<T: ?Sized, A = Global>(Unique<T>, A);
530533

531534
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
532535

@@ -536,7 +539,7 @@ impl<T> Box<T> {
536539
let size = intrinsics::size_of::<T>();
537540
let ptr = libc::malloc(size);
538541
intrinsics::copy(&val as *const T as *const u8, ptr, size);
539-
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, ())
542+
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
540543
}
541544
}
542545
}

compiler/rustc_codegen_cranelift/src/unsize.rs

-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ fn unsize_ptr<'tcx>(
7474
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
7575
(src, unsized_info(fx, *a, *b, old_info))
7676
}
77-
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
78-
let (a, b) = (src_layout.ty.boxed_ty(), dst_layout.ty.boxed_ty());
79-
(src, unsized_info(fx, a, b, old_info))
80-
}
8177
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
8278
assert_eq!(def_a, def_b);
8379

compiler/rustc_codegen_gcc/example/mini_core.rs

+1
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ pub trait Allocator {
472472

473473
impl Allocator for () {}
474474

475+
#[lang = "global_alloc_ty"]
475476
pub struct Global;
476477

477478
impl Allocator for Global {}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,13 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
454454
ty::RawPtr(ty::TypeAndMut { ty: pointee_type, .. }) | ty::Ref(_, pointee_type, _) => {
455455
build_pointer_or_reference_di_node(cx, t, pointee_type, unique_type_id)
456456
}
457-
// Box<T, A> may have a non-1-ZST allocator A. In that case, we
458-
// cannot treat Box<T, A> as just an owned alias of `*mut T`.
459-
ty::Adt(def, args) if def.is_box() && cx.layout_of(args.type_at(1)).is_1zst() => {
457+
// Some `Box` are newtyped pointers, make debuginfo aware of that.
458+
// Only works if the allocator argument is a 1-ZST and hence irrelevant for layout
459+
// (or if there is no allocator argument).
460+
ty::Adt(def, args)
461+
if def.is_box()
462+
&& args.get(1).map_or(true, |arg| cx.layout_of(arg.expect_ty()).is_1zst()) =>
463+
{
460464
build_pointer_or_reference_di_node(cx, t, t.boxed_ty(), unique_type_id)
461465
}
462466
ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id),

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
852852
}
853853

854854
let instance = match intrinsic {
855-
None | Some(ty::IntrinsicDef { name: sym::drop_in_place, .. }) => instance,
855+
None => instance,
856856
Some(intrinsic) => {
857857
let mut llargs = Vec::with_capacity(1);
858858
let ret_dest = self.make_return_dest(

compiler/rustc_codegen_ssa/src/mir/operand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
204204

205205
pub fn deref<Cx: LayoutTypeMethods<'tcx>>(self, cx: &Cx) -> PlaceRef<'tcx, V> {
206206
if self.layout.ty.is_box() {
207+
// Derefer should have removed all Box derefs
207208
bug!("dereferencing {:?} in codegen", self.layout.ty);
208209
}
209210

compiler/rustc_const_eval/src/interpret/place.rs

+1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ where
437437
trace!("deref to {} on {:?}", val.layout.ty, *val);
438438

439439
if val.layout.ty.is_box() {
440+
// Derefer should have removed all Box derefs
440441
bug!("dereferencing {}", val.layout.ty);
441442
}
442443

compiler/rustc_const_eval/src/interpret/terminator.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
359359
Ok(Some(match ty.kind() {
360360
ty::Ref(_, ty, _) => *ty,
361361
ty::RawPtr(mt) => mt.ty,
362-
// We should only accept `Box` with the default allocator.
363-
// It's hard to test for that though so we accept every 1-ZST allocator.
364-
ty::Adt(def, args)
365-
if def.is_box()
366-
&& self.layout_of(args[1].expect_ty()).is_ok_and(|l| l.is_1zst()) =>
367-
{
368-
args[0].expect_ty()
369-
}
362+
// We only accept `Box` with the default allocator.
363+
_ if ty.is_box_global(*self.tcx) => ty.boxed_ty(),
370364
_ => return Ok(None),
371365
}))
372366
};

compiler/rustc_expand/src/base.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::expand::{self, AstFragment, Invocation};
44
use crate::module::DirOwnership;
55

66
use rustc_ast::attr::MarkedAttrs;
7-
use rustc_ast::mut_visit::DummyAstNode;
87
use rustc_ast::ptr::P;
98
use rustc_ast::token::{self, Nonterminal};
109
use rustc_ast::tokenstream::TokenStream;
@@ -582,6 +581,17 @@ impl DummyResult {
582581
tokens: None,
583582
})
584583
}
584+
585+
/// A plain dummy crate.
586+
pub fn raw_crate() -> ast::Crate {
587+
ast::Crate {
588+
attrs: Default::default(),
589+
items: Default::default(),
590+
spans: Default::default(),
591+
id: ast::DUMMY_NODE_ID,
592+
is_placeholder: Default::default(),
593+
}
594+
}
585595
}
586596

587597
impl MacResult for DummyResult {
@@ -650,7 +660,7 @@ impl MacResult for DummyResult {
650660
}
651661

652662
fn make_crate(self: Box<DummyResult>) -> Option<ast::Crate> {
653-
Some(DummyAstNode::dummy())
663+
Some(DummyResult::raw_crate())
654664
}
655665
}
656666

compiler/rustc_feature/src/builtin_attrs.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
709709
// Internal attributes, Const related:
710710
// ==========================================================================
711711

712-
rustc_attr!(rustc_promotable, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
712+
rustc_attr!(
713+
rustc_promotable, Normal, template!(Word), WarnFollowing,
714+
@only_local: true, IMPL_DETAIL),
713715
rustc_attr!(
714716
rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing,
715717
INTERNAL_UNSTABLE
@@ -784,7 +786,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
784786
the given type by annotating all impl items with #[rustc_allow_incoherent_impl]."
785787
),
786788
rustc_attr!(
787-
rustc_box, AttributeType::Normal, template!(Word), ErrorFollowing,
789+
rustc_box, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true,
788790
"#[rustc_box] allows creating boxes \
789791
and it is only intended to be used in `alloc`."
790792
),
@@ -806,11 +808,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
806808
gated!(
807809
// Used in resolve:
808810
prelude_import, Normal, template!(Word), WarnFollowing,
809-
"`#[prelude_import]` is for use by rustc only",
811+
@only_local: true, "`#[prelude_import]` is for use by rustc only",
810812
),
811813
gated!(
812-
rustc_paren_sugar, Normal, template!(Word), WarnFollowing, unboxed_closures,
813-
"unboxed_closures are still evolving",
814+
rustc_paren_sugar, Normal, template!(Word), WarnFollowing, @only_local: true,
815+
unboxed_closures, "unboxed_closures are still evolving",
814816
),
815817
rustc_attr!(
816818
rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, @only_local: true,
@@ -826,27 +828,31 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
826828
),
827829
rustc_attr!(
828830
rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing,
829-
"the `#[rustc_test_marker]` attribute is used internally to track tests",
831+
@only_local: true, "the `#[rustc_test_marker]` attribute is used internally to track tests",
830832
),
831833
rustc_attr!(
832-
rustc_unsafe_specialization_marker, Normal, template!(Word), WarnFollowing,
834+
rustc_unsafe_specialization_marker, Normal, template!(Word),
835+
WarnFollowing, @only_local: true,
833836
"the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
834837
),
835838
rustc_attr!(
836-
rustc_specialization_trait, Normal, template!(Word), WarnFollowing,
839+
rustc_specialization_trait, Normal, template!(Word),
840+
WarnFollowing, @only_local: true,
837841
"the `#[rustc_specialization_trait]` attribute is used to check specializations"
838842
),
839843
rustc_attr!(
840-
rustc_main, Normal, template!(Word), WarnFollowing,
844+
rustc_main, Normal, template!(Word), WarnFollowing, @only_local: true,
841845
"the `#[rustc_main]` attribute is used internally to specify test entry point function",
842846
),
843847
rustc_attr!(
844-
rustc_skip_array_during_method_dispatch, Normal, template!(Word), WarnFollowing,
848+
rustc_skip_array_during_method_dispatch, Normal, template!(Word),
849+
WarnFollowing, @only_local: true,
845850
"the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \
846851
from method dispatch when the receiver is an array, for compatibility in editions < 2021."
847852
),
848853
rustc_attr!(
849-
rustc_must_implement_one_of, Normal, template!(List: "function1, function2, ..."), ErrorFollowing,
854+
rustc_must_implement_one_of, Normal, template!(List: "function1, function2, ..."),
855+
ErrorFollowing, @only_local: true,
850856
"the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
851857
definition of a trait, it's currently in experimental form and should be changed before \
852858
being exposed outside of the std"
@@ -857,6 +863,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
857863
),
858864
rustc_attr!(
859865
rustc_safe_intrinsic, Normal, template!(Word), WarnFollowing,
866+
@only_local: true,
860867
"the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe"
861868
),
862869
rustc_attr!(
@@ -877,8 +884,14 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
877884
// ==========================================================================
878885

879886
rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing),
880-
rustc_attr!(TEST, rustc_outlives, Normal, template!(Word), WarnFollowing),
881-
rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word), WarnFollowing),
887+
rustc_attr!(
888+
TEST, rustc_outlives, Normal, template!(Word),
889+
WarnFollowing, @only_local: true
890+
),
891+
rustc_attr!(
892+
TEST, rustc_capture_analysis, Normal, template!(Word),
893+
WarnFollowing, @only_local: true
894+
),
882895
rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word), WarnFollowing),
883896
rustc_attr!(TEST, rustc_strict_coherence, Normal, template!(Word), WarnFollowing),
884897
rustc_attr!(TEST, rustc_variance, Normal, template!(Word), WarnFollowing),

compiler/rustc_hir/src/lang_items.rs

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ language_item_table! {
267267
EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None;
268268

269269
OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);
270+
GlobalAlloc, sym::global_alloc_ty, global_alloc_ty, Target::Struct, GenericRequirement::None;
271+
270272
// Experimental language item for Miri
271273
PtrUnique, sym::ptr_unique, ptr_unique, Target::Struct, GenericRequirement::Exact(1);
272274

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
132132
| sym::fsub_algebraic
133133
| sym::fmul_algebraic
134134
| sym::fdiv_algebraic
135-
| sym::frem_algebraic => hir::Unsafety::Normal,
135+
| sym::frem_algebraic
136+
| sym::const_eval_select => hir::Unsafety::Normal,
136137
_ => hir::Unsafety::Unsafe,
137138
};
138139

@@ -247,7 +248,6 @@ pub fn check_intrinsic_type(
247248
],
248249
Ty::new_unit(tcx),
249250
),
250-
sym::drop_in_place => (1, 0, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_unit(tcx)),
251251
sym::needs_drop => (1, 0, vec![], tcx.types.bool),
252252

253253
sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)),

0 commit comments

Comments
 (0)