Skip to content

Commit 9b37157

Browse files
committed
Auto merge of #151339 - JonathanBrouwer:rollup-DYrRtnq, r=JonathanBrouwer
Rollup of 3 pull requests Successful merges: - #151287 (Reorganizing `tests/ui/issues` 15 tests [2/N] ) - #151309 (fix: thread creation failed on the wasm32-wasip1-threads target.) - #151335 (Port rustc allocator attributes to attribute parser) r? @ghost
2 parents 0a3cd3b + 47d8a87 commit 9b37157

39 files changed

Lines changed: 163 additions & 41 deletions

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub(crate) mod pin_v2;
5858
pub(crate) mod proc_macro_attrs;
5959
pub(crate) mod prototype;
6060
pub(crate) mod repr;
61+
pub(crate) mod rustc_allocator;
6162
pub(crate) mod rustc_dump;
6263
pub(crate) mod rustc_internal;
6364
pub(crate) mod semantics;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use super::prelude::*;
2+
3+
pub(crate) struct RustcAllocatorParser;
4+
5+
impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorParser {
6+
const PATH: &[Symbol] = &[sym::rustc_allocator];
7+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
8+
const ALLOWED_TARGETS: AllowedTargets =
9+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
10+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocator;
11+
}
12+
13+
pub(crate) struct RustcAllocatorZeroedParser;
14+
15+
impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorZeroedParser {
16+
const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed];
17+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
18+
const ALLOWED_TARGETS: AllowedTargets =
19+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
20+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocatorZeroed;
21+
}
22+
23+
pub(crate) struct RustcAllocatorZeroedVariantParser;
24+
25+
impl<S: Stage> SingleAttributeParser<S> for RustcAllocatorZeroedVariantParser {
26+
const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed_variant];
27+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
28+
const ALLOWED_TARGETS: AllowedTargets =
29+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
30+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "function");
31+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
32+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
33+
let Some(name) = args.name_value().and_then(NameValueParser::value_as_str) else {
34+
cx.expected_name_value(cx.attr_span, None);
35+
return None;
36+
};
37+
38+
Some(AttributeKind::RustcAllocatorZeroedVariant { name })
39+
}
40+
}
41+
42+
pub(crate) struct RustcDeallocatorParser;
43+
44+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDeallocatorParser {
45+
const PATH: &[Symbol] = &[sym::rustc_deallocator];
46+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
47+
const ALLOWED_TARGETS: AllowedTargets =
48+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
49+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDeallocator;
50+
}
51+
52+
pub(crate) struct RustcReallocatorParser;
53+
54+
impl<S: Stage> NoArgsAttributeParser<S> for RustcReallocatorParser {
55+
const PATH: &[Symbol] = &[sym::rustc_reallocator];
56+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
57+
const ALLOWED_TARGETS: AllowedTargets =
58+
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
59+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcReallocator;
60+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ use crate::attributes::proc_macro_attrs::{
6464
};
6565
use crate::attributes::prototype::CustomMirParser;
6666
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
67+
use crate::attributes::rustc_allocator::{
68+
RustcAllocatorParser, RustcAllocatorZeroedParser, RustcAllocatorZeroedVariantParser,
69+
RustcDeallocatorParser, RustcReallocatorParser,
70+
};
6771
use crate::attributes::rustc_dump::{
6872
RustcDumpDefParents, RustcDumpItemBounds, RustcDumpPredicates, RustcDumpUserArgs,
6973
RustcDumpVtable,
@@ -223,6 +227,7 @@ attribute_parsers!(
223227
Single<PatternComplexityLimitParser>,
224228
Single<ProcMacroDeriveParser>,
225229
Single<RecursionLimitParser>,
230+
Single<RustcAllocatorZeroedVariantParser>,
226231
Single<RustcBuiltinMacroParser>,
227232
Single<RustcForceInlineParser>,
228233
Single<RustcLayoutScalarValidRangeEndParser>,
@@ -274,7 +279,10 @@ attribute_parsers!(
274279
Single<WithoutArgs<ProcMacroAttributeParser>>,
275280
Single<WithoutArgs<ProcMacroParser>>,
276281
Single<WithoutArgs<PubTransparentParser>>,
282+
Single<WithoutArgs<RustcAllocatorParser>>,
283+
Single<WithoutArgs<RustcAllocatorZeroedParser>>,
277284
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
285+
Single<WithoutArgs<RustcDeallocatorParser>>,
278286
Single<WithoutArgs<RustcDumpDefParents>>,
279287
Single<WithoutArgs<RustcDumpItemBounds>>,
280288
Single<WithoutArgs<RustcDumpPredicates>>,
@@ -289,6 +297,7 @@ attribute_parsers!(
289297
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
290298
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
291299
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
300+
Single<WithoutArgs<RustcReallocatorParser>>,
292301
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
293302
Single<WithoutArgs<SpecializationTraitParser>>,
294303
Single<WithoutArgs<StdInternalSymbolParser>>,

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Set and unset common attributes on LLVM values.
22
use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, OptimizeAttr, RtsanSetting};
33
use rustc_hir::def_id::DefId;
4+
use rustc_hir::find_attr;
45
use rustc_middle::middle::codegen_fn_attrs::{
56
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs,
67
};
@@ -470,9 +471,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
470471
{
471472
to_add.push(create_alloc_family_attr(cx.llcx));
472473
if let Some(instance) = instance
473-
&& let Some(zv) =
474-
tcx.get_attr(instance.def_id(), rustc_span::sym::rustc_allocator_zeroed_variant)
475-
&& let Some(name) = zv.value_str()
474+
&& let Some(name) = find_attr!(tcx.get_all_attrs(instance.def_id()), rustc_hir::attrs::AttributeKind::RustcAllocatorZeroedVariant {name} => name)
476475
{
477476
to_add.push(llvm::CreateAttrStringValue(
478477
cx.llcx,

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ fn process_builtin_attrs(
335335
AttributeKind::InstructionSet(instruction_set) => {
336336
codegen_fn_attrs.instruction_set = Some(*instruction_set)
337337
}
338+
AttributeKind::RustcAllocator => {
339+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR
340+
}
341+
AttributeKind::RustcDeallocator => {
342+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR
343+
}
344+
AttributeKind::RustcReallocator => {
345+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR
346+
}
347+
AttributeKind::RustcAllocatorZeroed => {
348+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
349+
}
338350
_ => {}
339351
}
340352
}
@@ -344,13 +356,7 @@ fn process_builtin_attrs(
344356
};
345357

346358
match name {
347-
sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
348359
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
349-
sym::rustc_reallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR,
350-
sym::rustc_deallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR,
351-
sym::rustc_allocator_zeroed => {
352-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
353-
}
354360
sym::patchable_function_entry => {
355361
codegen_fn_attrs.patchable_function_entry =
356362
parse_patchable_function_entry(tcx, attr);

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,12 +909,24 @@ pub enum AttributeKind {
909909
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
910910
Repr { reprs: ThinVec<(ReprAttr, Span)>, first_span: Span },
911911

912+
/// Represents `#[rustc_allocator]`
913+
RustcAllocator,
914+
915+
/// Represents `#[rustc_allocator_zeroed]`
916+
RustcAllocatorZeroed,
917+
918+
/// Represents `#[rustc_allocator_zeroed_variant]`
919+
RustcAllocatorZeroedVariant { name: Symbol },
920+
912921
/// Represents `#[rustc_builtin_macro]`.
913922
RustcBuiltinMacro { builtin_name: Option<Symbol>, helper_attrs: ThinVec<Symbol>, span: Span },
914923

915924
/// Represents `#[rustc_coherence_is_core]`
916925
RustcCoherenceIsCore(Span),
917926

927+
/// Represents `#[rustc_deallocator]`
928+
RustcDeallocator,
929+
918930
/// Represents `#[rustc_dump_def_parents]`
919931
RustcDumpDefParents,
920932

@@ -975,6 +987,9 @@ pub enum AttributeKind {
975987
/// Represents `#[rustc_pass_indirectly_in_non_rustic_abis]`
976988
RustcPassIndirectlyInNonRusticAbis(Span),
977989

990+
/// Represents `#[rustc_reallocator]`
991+
RustcReallocator,
992+
978993
/// Represents `#[rustc_scalable_vector(N)]`
979994
RustcScalableVector {
980995
/// The base multiple of lanes that are in a scalable vector, if provided. `element_count`

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@ impl AttributeKind {
9898
PubTransparent(..) => Yes,
9999
RecursionLimit { .. } => No,
100100
Repr { .. } => No,
101+
RustcAllocator => No,
102+
RustcAllocatorZeroed => No,
103+
RustcAllocatorZeroedVariant { .. } => Yes,
101104
RustcBuiltinMacro { .. } => Yes,
102105
RustcCoherenceIsCore(..) => No,
106+
RustcDeallocator => No,
103107
RustcDumpDefParents => No,
104108
RustcDumpItemBounds => No,
105109
RustcDumpPredicates => No,
@@ -120,6 +124,7 @@ impl AttributeKind {
120124
RustcNoImplicitAutorefs => Yes,
121125
RustcObjectLifetimeDefault => No,
122126
RustcPassIndirectlyInNonRusticAbis(..) => No,
127+
RustcReallocator => No,
123128
RustcScalableVector { .. } => Yes,
124129
RustcShouldNotBeCalledOnConstItems(..) => Yes,
125130
RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
317317
| AttributeKind::RustcDumpDefParents
318318
| AttributeKind::RustcDumpVtable(..)
319319
| AttributeKind::NeedsAllocator
320+
| AttributeKind::RustcAllocator
321+
| AttributeKind::RustcAllocatorZeroed
322+
| AttributeKind::RustcAllocatorZeroedVariant { .. }
323+
| AttributeKind::RustcDeallocator
324+
| AttributeKind::RustcReallocator
320325
) => { /* do nothing */ }
321326
Attribute::Unparsed(attr_item) => {
322327
style = Some(attr_item.style);
@@ -361,12 +366,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
361366
| sym::rustc_do_not_const_check
362367
| sym::rustc_reservation_impl
363368
| sym::rustc_doc_primitive
364-
| sym::rustc_allocator
365-
| sym::rustc_deallocator
366-
| sym::rustc_reallocator
367369
| sym::rustc_conversion_suggestion
368-
| sym::rustc_allocator_zeroed
369-
| sym::rustc_allocator_zeroed_variant
370370
| sym::rustc_deprecated_safe_2024
371371
| sym::rustc_test_marker
372372
| sym::rustc_abi

library/std/src/sys/thread/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Thread {
4949
// WASI does not support threading via pthreads. While wasi-libc provides
5050
// pthread stubs, pthread_create returns EAGAIN, which causes confusing
5151
// errors. We return UNSUPPORTED_PLATFORM directly instead.
52-
if cfg!(target_os = "wasi") {
52+
if cfg!(all(target_os = "wasi", not(target_feature = "atomics"))) {
5353
return Err(io::Error::UNSUPPORTED_PLATFORM);
5454
}
5555

tests/ui/issues/issue-38919.rs renamed to tests/ui/associated-types/associated-type-as-value.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! regression test for <https://github.com/rust-lang/rust/issues/38919>
2+
13
fn foo<T: Iterator>() {
24
T::Item; //~ ERROR no associated item named `Item` found
35
}

0 commit comments

Comments
 (0)