Skip to content

Commit 1279939

Browse files
Auto merge of #150957 - matthiaskrgr:rollup-Cf6MsNU, r=matthiaskrgr
Rollup of 14 pull requests Successful merges: - #148941 (stabilize `Peekable::next_if_map` (`#![feature(peekable_next_if_map)]`)) - #150368 (adding Ordering enum to minicore.rs, importing minicore in "tests/assembly-llvm/rust-abi-arg-attr.rs" test file) - #150668 (Unix implementation for stdio set/take/replace) - #150743 (Reword the collect() docs) - #150776 (Fix the connect_error test on FreeBSD 15+) - #150781 (Use `rand` crate more idiomatically) - #150812 (Bump `diesel` to the most recent commit in `cargotest`) - #150862 (std: sys: fs: uefi: Implement File::flush) - #150873 (Reenable GCC CI download) - #150908 (llvm: Update `reliable_f16` configuration for LLVM22) - #150918 (std: sys: fs: uefi: Implement File::seek) - #150922 (Subscribe myself to attr parsing) - #150930 (Remove special case for `AllowedTargets::CrateLevel`) - #150942 (Port `#[rustc_has_incoherent_inherent_impls]` to attribute parser) Failed merges: - #150943 (Port `#[must_not_suspend]` to attribute parser) r? @ghost
2 parents 08f833a + 8392406 commit 1279939

33 files changed

Lines changed: 332 additions & 188 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl<S: Stage> SingleAttributeParser<S> for CrateNameParser {
99
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1010
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
1111
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
12-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
12+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
1313

1414
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
1515
let ArgParser::NameValue(n) = args else {
@@ -33,7 +33,7 @@ impl<S: Stage> SingleAttributeParser<S> for RecursionLimitParser {
3333
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
3434
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
3535
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute");
36-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
36+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
3737

3838
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
3939
let ArgParser::NameValue(nv) = args else {
@@ -56,7 +56,7 @@ impl<S: Stage> SingleAttributeParser<S> for MoveSizeLimitParser {
5656
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
5757
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
5858
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
59-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
59+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
6060

6161
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
6262
let ArgParser::NameValue(nv) = args else {
@@ -79,7 +79,7 @@ impl<S: Stage> SingleAttributeParser<S> for TypeLengthLimitParser {
7979
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
8080
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
8181
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
82-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
82+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
8383

8484
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
8585
let ArgParser::NameValue(nv) = args else {
@@ -102,7 +102,7 @@ impl<S: Stage> SingleAttributeParser<S> for PatternComplexityLimitParser {
102102
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
103103
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
104104
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
105-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
105+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
106106

107107
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
108108
let ArgParser::NameValue(nv) = args else {
@@ -123,7 +123,7 @@ pub(crate) struct NoCoreParser;
123123
impl<S: Stage> NoArgsAttributeParser<S> for NoCoreParser {
124124
const PATH: &[Symbol] = &[sym::no_core];
125125
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
126-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
126+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
127127
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoCore;
128128
}
129129

@@ -132,7 +132,7 @@ pub(crate) struct NoStdParser;
132132
impl<S: Stage> NoArgsAttributeParser<S> for NoStdParser {
133133
const PATH: &[Symbol] = &[sym::no_std];
134134
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
135-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
135+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
136136
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
137137
}
138138

@@ -141,7 +141,7 @@ pub(crate) struct RustcCoherenceIsCoreParser;
141141
impl<S: Stage> NoArgsAttributeParser<S> for RustcCoherenceIsCoreParser {
142142
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
143143
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
144-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
144+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
145145
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcCoherenceIsCore;
146146
}
147147

@@ -151,7 +151,7 @@ impl<S: Stage> SingleAttributeParser<S> for WindowsSubsystemParser {
151151
const PATH: &[Symbol] = &[sym::windows_subsystem];
152152
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
153153
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
154-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
154+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
155155
const TEMPLATE: AttributeTemplate = template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute");
156156

157157
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,18 @@ impl<S: Stage> SingleAttributeParser<S> for RustcScalableVectorParser {
305305
Some(AttributeKind::RustcScalableVector { element_count: Some(n), span: cx.attr_span })
306306
}
307307
}
308+
309+
pub(crate) struct RustcHasIncoherentInherentImplsParser;
310+
311+
impl<S: Stage> NoArgsAttributeParser<S> for RustcHasIncoherentInherentImplsParser {
312+
const PATH: &[Symbol] = &[sym::rustc_has_incoherent_inherent_impls];
313+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
314+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
315+
Allow(Target::Trait),
316+
Allow(Target::Struct),
317+
Allow(Target::Enum),
318+
Allow(Target::Union),
319+
Allow(Target::ForeignTy),
320+
]);
321+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcHasIncoherentInherentImpls;
322+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use std::ops::{Deref, DerefMut};
44
use std::sync::LazyLock;
55

66
use private::Sealed;
7-
use rustc_ast::{AttrStyle, CRATE_NODE_ID, MetaItemLit, NodeId};
7+
use rustc_ast::{AttrStyle, MetaItemLit, NodeId};
88
use rustc_errors::{Diag, Diagnostic, Level};
99
use rustc_feature::{AttrSuggestionStyle, AttributeTemplate};
1010
use rustc_hir::attrs::AttributeKind;
1111
use rustc_hir::lints::{AttributeLint, AttributeLintKind};
12-
use rustc_hir::{AttrPath, CRATE_HIR_ID, HirId};
12+
use rustc_hir::{AttrPath, HirId};
1313
use rustc_session::Session;
1414
use rustc_session::lint::{Lint, LintId};
1515
use rustc_span::{ErrorGuaranteed, Span, Symbol};
@@ -62,12 +62,12 @@ use crate::attributes::proc_macro_attrs::{
6262
use crate::attributes::prototype::CustomMirParser;
6363
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
6464
use crate::attributes::rustc_internal::{
65-
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
66-
RustcLegacyConstGenericsParser, RustcLintDiagnosticsParser, RustcLintOptDenyFieldAccessParser,
67-
RustcLintOptTyParser, RustcLintQueryInstabilityParser,
68-
RustcLintUntrackedQueryInformationParser, RustcMainParser, RustcMustImplementOneOfParser,
69-
RustcNeverReturnsNullPointerParser, RustcNoImplicitAutorefsParser,
70-
RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
65+
RustcHasIncoherentInherentImplsParser, RustcLayoutScalarValidRangeEndParser,
66+
RustcLayoutScalarValidRangeStartParser, RustcLegacyConstGenericsParser,
67+
RustcLintDiagnosticsParser, RustcLintOptDenyFieldAccessParser, RustcLintOptTyParser,
68+
RustcLintQueryInstabilityParser, RustcLintUntrackedQueryInformationParser, RustcMainParser,
69+
RustcMustImplementOneOfParser, RustcNeverReturnsNullPointerParser,
70+
RustcNoImplicitAutorefsParser, RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
7171
RustcSimdMonomorphizeLaneLimitParser,
7272
};
7373
use crate::attributes::semantics::MayDangleParser;
@@ -264,6 +264,7 @@ attribute_parsers!(
264264
Single<WithoutArgs<ProcMacroParser>>,
265265
Single<WithoutArgs<PubTransparentParser>>,
266266
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
267+
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
267268
Single<WithoutArgs<RustcLintDiagnosticsParser>>,
268269
Single<WithoutArgs<RustcLintOptTyParser>>,
269270
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
@@ -303,8 +304,6 @@ pub trait Stage: Sized + 'static + Sealed {
303304
) -> ErrorGuaranteed;
304305

305306
fn should_emit(&self) -> ShouldEmit;
306-
307-
fn id_is_crate_root(id: Self::Id) -> bool;
308307
}
309308

310309
// allow because it's a sealed trait
@@ -326,10 +325,6 @@ impl Stage for Early {
326325
fn should_emit(&self) -> ShouldEmit {
327326
self.emit_errors
328327
}
329-
330-
fn id_is_crate_root(id: Self::Id) -> bool {
331-
id == CRATE_NODE_ID
332-
}
333328
}
334329

335330
// allow because it's a sealed trait
@@ -351,10 +346,6 @@ impl Stage for Late {
351346
fn should_emit(&self) -> ShouldEmit {
352347
ShouldEmit::ErrorsAndLints
353348
}
354-
355-
fn id_is_crate_root(id: Self::Id) -> bool {
356-
id == CRATE_HIR_ID
357-
}
358349
}
359350

360351
/// used when parsing attributes for miscellaneous things *before* ast lowering

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ use crate::session_diagnostics::InvalidTarget;
1515
pub(crate) enum AllowedTargets {
1616
AllowList(&'static [Policy]),
1717
AllowListWarnRest(&'static [Policy]),
18-
/// Special, and not the same as `AllowList(&[Allow(Target::Crate)])`.
19-
/// For crate-level attributes we emit a specific set of lints to warn
20-
/// people about accidentally not using them on the crate.
21-
/// Only use this for attributes that are *exclusively* valid at the crate level.
22-
CrateLevel,
2318
}
2419

2520
pub(crate) enum AllowedResult {
@@ -53,15 +48,13 @@ impl AllowedTargets {
5348
AllowedResult::Warn
5449
}
5550
}
56-
AllowedTargets::CrateLevel => AllowedResult::Allowed,
5751
}
5852
}
5953

6054
pub(crate) fn allowed_targets(&self) -> Vec<Target> {
6155
match self {
6256
AllowedTargets::AllowList(list) => list,
6357
AllowedTargets::AllowListWarnRest(list) => list,
64-
AllowedTargets::CrateLevel => ALL_TARGETS,
6558
}
6659
.iter()
6760
.filter_map(|target| match target {
@@ -95,7 +88,10 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
9588
target: Target,
9689
cx: &mut AcceptContext<'_, 'sess, S>,
9790
) {
98-
Self::check_type(matches!(allowed_targets, AllowedTargets::CrateLevel), target, cx);
91+
if allowed_targets.allowed_targets() == &[Target::Crate] {
92+
Self::check_crate_level(target, cx);
93+
return;
94+
}
9995

10096
match allowed_targets.is_allowed(target) {
10197
AllowedResult::Allowed => {}
@@ -149,18 +145,10 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
149145
}
150146
}
151147

152-
pub(crate) fn check_type(
153-
crate_level: bool,
154-
target: Target,
155-
cx: &mut AcceptContext<'_, 'sess, S>,
156-
) {
157-
let is_crate_root = S::id_is_crate_root(cx.target_id);
158-
159-
if is_crate_root {
160-
return;
161-
}
162-
163-
if !crate_level {
148+
pub(crate) fn check_crate_level(target: Target, cx: &mut AcceptContext<'_, 'sess, S>) {
149+
// For crate-level attributes we emit a specific set of lints to warn
150+
// people about accidentally not using them on the crate.
151+
if target == Target::Crate {
164152
return;
165153
}
166154

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,19 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
379379
{
380380
false
381381
}
382-
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
383-
(Arch::Arm64EC, _) => false,
382+
// Unsupported <https://github.com/llvm/llvm-project/issues/94434> (fixed in llvm22)
383+
(Arch::Arm64EC, _) if major < 22 => false,
384384
// Selection failure <https://github.com/llvm/llvm-project/issues/50374> (fixed in llvm21)
385385
(Arch::S390x, _) if major < 21 => false,
386386
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
387387
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
388388
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
389-
(Arch::CSky, _) => false,
389+
(Arch::CSky, _) if major < 22 => false, // (fixed in llvm22)
390390
(Arch::Hexagon, _) if major < 21 => false, // (fixed in llvm21)
391391
(Arch::LoongArch32 | Arch::LoongArch64, _) if major < 21 => false, // (fixed in llvm21)
392-
(Arch::PowerPC | Arch::PowerPC64, _) => false,
393-
(Arch::Sparc | Arch::Sparc64, _) => false,
394-
(Arch::Wasm32 | Arch::Wasm64, _) => false,
392+
(Arch::PowerPC | Arch::PowerPC64, _) if major < 22 => false, // (fixed in llvm22)
393+
(Arch::Sparc | Arch::Sparc64, _) if major < 22 => false, // (fixed in llvm22)
394+
(Arch::Wasm32 | Arch::Wasm64, _) if major < 22 => false, // (fixed in llvm22)
395395
// `f16` support only requires that symbols converting to and from `f32` are available. We
396396
// provide these in `compiler-builtins`, so `f16` should be available on all platforms that
397397
// do not have other ABI issues or LLVM crashes.

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ pub enum AttributeKind {
880880
/// Represents `#[rustc_coherence_is_core]`
881881
RustcCoherenceIsCore(Span),
882882

883+
/// Represents `#[rustc_has_incoherent_inherent_impls]`
884+
RustcHasIncoherentInherentImpls,
885+
883886
/// Represents `#[rustc_layout_scalar_valid_range_end]`.
884887
RustcLayoutScalarValidRangeEnd(Box<u128>, Span),
885888

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl AttributeKind {
9595
Repr { .. } => No,
9696
RustcBuiltinMacro { .. } => Yes,
9797
RustcCoherenceIsCore(..) => No,
98+
RustcHasIncoherentInherentImpls => Yes,
9899
RustcLayoutScalarValidRangeEnd(..) => Yes,
99100
RustcLayoutScalarValidRangeStart(..) => Yes,
100101
RustcLegacyConstGenerics { .. } => Yes,

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_hir::find_attr;
1515
use rustc_middle::bug;
1616
use rustc_middle::ty::fast_reject::{SimplifiedType, TreatParams, simplify_type};
1717
use rustc_middle::ty::{self, CrateInherentImpls, Ty, TyCtxt};
18-
use rustc_span::{ErrorGuaranteed, sym};
18+
use rustc_span::ErrorGuaranteed;
1919

2020
use crate::errors;
2121

@@ -79,7 +79,10 @@ impl<'tcx> InherentCollect<'tcx> {
7979
}
8080

8181
if self.tcx.features().rustc_attrs() {
82-
if !self.tcx.has_attr(ty_def_id, sym::rustc_has_incoherent_inherent_impls) {
82+
if !find_attr!(
83+
self.tcx.get_all_attrs(ty_def_id),
84+
AttributeKind::RustcHasIncoherentInherentImpls
85+
) {
8386
let impl_span = self.tcx.def_span(impl_def_id);
8487
return Err(self.tcx.dcx().emit_err(errors::InherentTyOutside { span: impl_span }));
8588
}

compiler/rustc_middle/src/ty/trait_def.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::iter;
22

33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_errors::ErrorGuaranteed;
5-
use rustc_hir as hir;
5+
use rustc_hir::attrs::AttributeKind;
66
use rustc_hir::def::DefKind;
77
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
8+
use rustc_hir::{self as hir, find_attr};
89
use rustc_macros::{Decodable, Encodable, HashStable};
9-
use rustc_span::symbol::sym;
1010
use tracing::debug;
1111

1212
use crate::query::LocalCrate;
@@ -241,7 +241,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
241241
/// Query provider for `incoherent_impls`.
242242
pub(super) fn incoherent_impls_provider(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] {
243243
if let Some(def_id) = simp.def()
244-
&& !tcx.has_attr(def_id, sym::rustc_has_incoherent_inherent_impls)
244+
&& !find_attr!(tcx.get_all_attrs(def_id), AttributeKind::RustcHasIncoherentInherentImpls)
245245
{
246246
return &[];
247247
}

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,6 @@ passes_function_not_have_default_implementation = function doesn't have a defaul
244244
passes_functions_names_duplicated = functions names are duplicated
245245
.note = all `#[rustc_must_implement_one_of]` arguments must be unique
246246
247-
passes_has_incoherent_inherent_impl =
248-
`rustc_has_incoherent_inherent_impls` attribute should be applied to types or traits
249-
.label = only adts, extern types and traits are supported
250-
251247
passes_ignored_derived_impls =
252248
`{$name}` has {$trait_list_len ->
253249
[one] a derived impl

0 commit comments

Comments
 (0)