Skip to content

Commit 24139cf

Browse files
committed
Auto merge of #150199 - JonathanBrouwer:rollup-pjxlhel, r=JonathanBrouwer
Rollup of 2 pull requests Successful merges: - #150188 (Dogfood `strip_circumfix`) - #150198 (Port `#[thread_local]` to attribute parser) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b53da99 + 73292d9 commit 24139cf

File tree

15 files changed

+53
-64
lines changed

15 files changed

+53
-64
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,16 @@ impl<S: Stage> SingleAttributeParser<S> for SanitizeParser {
690690
}
691691
}
692692

693+
pub(crate) struct ThreadLocalParser;
694+
695+
impl<S: Stage> NoArgsAttributeParser<S> for ThreadLocalParser {
696+
const PATH: &[Symbol] = &[sym::thread_local];
697+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
698+
const ALLOWED_TARGETS: AllowedTargets =
699+
AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::ForeignStatic)]);
700+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ThreadLocal;
701+
}
702+
693703
pub(crate) struct RustcPassIndirectlyInNonRusticAbisParser;
694704

695705
impl<S: Stage> NoArgsAttributeParser<S> for RustcPassIndirectlyInNonRusticAbisParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::attributes::codegen_attrs::{
2323
ColdParser, CoverageParser, EiiExternItemParser, ExportNameParser, ForceTargetFeatureParser,
2424
NakedParser, NoMangleParser, ObjcClassParser, ObjcSelectorParser, OptimizeParser,
2525
RustcPassIndirectlyInNonRusticAbisParser, SanitizeParser, TargetFeatureParser,
26-
TrackCallerParser, UsedParser,
26+
ThreadLocalParser, TrackCallerParser, UsedParser,
2727
};
2828
use crate::attributes::confusables::ConfusablesParser;
2929
use crate::attributes::crate_level::{
@@ -269,6 +269,7 @@ attribute_parsers!(
269269
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
270270
Single<WithoutArgs<SpecializationTraitParser>>,
271271
Single<WithoutArgs<StdInternalSymbolParser>>,
272+
Single<WithoutArgs<ThreadLocalParser>>,
272273
Single<WithoutArgs<TrackCallerParser>>,
273274
Single<WithoutArgs<TypeConstParser>>,
274275
Single<WithoutArgs<UnsafeSpecializationMarkerParser>>,

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ fn process_builtin_attrs(
350350
codegen_fn_attrs.flags |= CodegenFnAttrFlags::EXTERNALLY_IMPLEMENTABLE_ITEM;
351351
}
352352
}
353+
AttributeKind::ThreadLocal => {
354+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL
355+
}
353356
_ => {}
354357
}
355358
}
@@ -366,7 +369,6 @@ fn process_builtin_attrs(
366369
sym::rustc_allocator_zeroed => {
367370
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
368371
}
369-
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
370372
sym::instruction_set => {
371373
codegen_fn_attrs.instruction_set = parse_instruction_set_attr(tcx, attr)
372374
}

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,9 @@ pub enum AttributeKind {
10101010
/// `#[unsafe(force_target_feature(enable = "...")]`.
10111011
TargetFeature { features: ThinVec<(Symbol, Span)>, attr_span: Span, was_forced: bool },
10121012

1013+
/// Represents `#[thread_local]`
1014+
ThreadLocal,
1015+
10131016
/// Represents `#[track_caller]`
10141017
TrackCaller(Span),
10151018

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl AttributeKind {
114114
Stability { .. } => Yes,
115115
StdInternalSymbol(..) => No,
116116
TargetFeature { .. } => No,
117+
ThreadLocal => No,
117118
TrackCaller(..) => Yes,
118119
TypeConst(..) => Yes,
119120
TypeLengthLimit { .. } => No,

compiler/rustc_metadata/src/errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ impl<'a> MissingNativeLibrary<'a> {
251251
// if it looks like the user has provided a complete filename rather just the bare lib name,
252252
// then provide a note that they might want to try trimming the name
253253
let suggested_name = if !verbatim {
254-
if let Some(libname) = libname.strip_prefix("lib")
255-
&& let Some(libname) = libname.strip_suffix(".a")
256-
{
254+
if let Some(libname) = libname.strip_circumfix("lib", ".a") {
257255
// this is a unix style filename so trim prefix & suffix
258256
Some(libname)
259257
} else if let Some(libname) = libname.strip_suffix(".lib") {

compiler/rustc_metadata/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![feature(never_type)]
1111
#![feature(proc_macro_internals)]
1212
#![feature(result_option_map_or_default)]
13+
#![feature(strip_circumfix)]
1314
#![feature(trusted_len)]
1415
// tidy-alphabetical-end
1516

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,6 @@ passes_sanitize_attribute_not_allowed =
484484
.no_body = function has no body
485485
.help = sanitize attribute can be applied to a function (with body), impl block, or module
486486
487-
passes_should_be_applied_to_static =
488-
attribute should be applied to a static
489-
.label = not a static
490-
491487
passes_should_be_applied_to_trait =
492488
attribute should be applied to a trait
493489
.label = not a trait

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
297297
| AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
298298
| AttributeKind::PinV2(..)
299299
| AttributeKind::WindowsSubsystem(..)
300+
| AttributeKind::ThreadLocal
300301
) => { /* do nothing */ }
301302
Attribute::Unparsed(attr_item) => {
302303
style = Some(attr_item.style);
@@ -310,7 +311,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
310311
[sym::diagnostic, sym::on_const, ..] => {
311312
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
312313
}
313-
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
314314
[sym::rustc_clean, ..]
315315
| [sym::rustc_dirty, ..]
316316
| [sym::rustc_if_this_changed, ..]
@@ -768,19 +768,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
768768
}
769769
}
770770

771-
/// Checks if the `#[thread_local]` attribute on `item` is valid.
772-
fn check_thread_local(&self, attr: &Attribute, span: Span, target: Target) {
773-
match target {
774-
Target::ForeignStatic | Target::Static => {}
775-
_ => {
776-
self.dcx().emit_err(errors::AttrShouldBeAppliedToStatic {
777-
attr_span: attr.span(),
778-
defn_span: span,
779-
});
780-
}
781-
}
782-
}
783-
784771
fn check_doc_alias_value(&self, span: Span, hir_id: HirId, target: Target, alias: Symbol) {
785772
if let Some(location) = match target {
786773
Target::AssocTy => {

compiler/rustc_passes/src/errors.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,6 @@ pub(crate) struct AttrShouldBeAppliedToTrait {
9898
pub defn_span: Span,
9999
}
100100

101-
#[derive(Diagnostic)]
102-
#[diag(passes_should_be_applied_to_static)]
103-
pub(crate) struct AttrShouldBeAppliedToStatic {
104-
#[primary_span]
105-
pub attr_span: Span,
106-
#[label]
107-
pub defn_span: Span,
108-
}
109-
110101
#[derive(Diagnostic)]
111102
#[diag(passes_doc_alias_bad_location)]
112103
pub(crate) struct DocAliasBadLocation<'a> {

0 commit comments

Comments
 (0)