Skip to content

Commit 603341a

Browse files
author
The Miri Cronjob Bot
committed
Merge ref 'a015919e54c6' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: a015919 Filtered ref: 1867c5844dba22ac4d77d1ceb7d1624c14139c16 Upstream diff: rust-lang/rust@4ba1cf9...a015919 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 3a784d9 + 9c42379 commit 603341a

File tree

216 files changed

+1723
-1264
lines changed

Some content is hidden

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

216 files changed

+1723
-1264
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
55
use rustc_hir::attrs::AttributeKind;
66
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
8-
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin, Target, find_attr};
8+
use rustc_hir::{
9+
self as hir, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target, find_attr,
10+
};
911
use rustc_index::{IndexSlice, IndexVec};
1012
use rustc_middle::span_bug;
1113
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
@@ -1117,20 +1119,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
11171119
}
11181120
};
11191121

1122+
let span = self.lower_span(i.span);
11201123
let item = hir::ImplItem {
11211124
owner_id: hir_id.expect_owner(),
11221125
ident: self.lower_ident(ident),
11231126
generics,
1127+
impl_kind: if is_in_trait_impl {
1128+
ImplItemImplKind::Trait {
1129+
defaultness,
1130+
trait_item_def_id: self
1131+
.resolver
1132+
.get_partial_res(i.id)
1133+
.and_then(|r| r.expect_full_res().opt_def_id())
1134+
.ok_or_else(|| {
1135+
self.dcx().span_delayed_bug(
1136+
span,
1137+
"could not resolve trait item being implemented",
1138+
)
1139+
}),
1140+
}
1141+
} else {
1142+
ImplItemImplKind::Inherent { vis_span: self.lower_span(i.vis.span) }
1143+
},
11241144
kind,
1125-
vis_span: self.lower_span(i.vis.span),
1126-
span: self.lower_span(i.span),
1127-
defaultness,
1145+
span,
11281146
has_delayed_lints: !self.delayed_lints.is_empty(),
1129-
trait_item_def_id: self
1130-
.resolver
1131-
.get_partial_res(i.id)
1132-
.map(|r| r.expect_full_res().opt_def_id())
1133-
.unwrap_or(None),
11341147
};
11351148
self.arena.alloc(item)
11361149
}

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ ast_passes_match_arm_with_no_body =
216216
.suggestion = add a body after the pattern
217217
218218
ast_passes_missing_unsafe_on_extern = extern blocks must be unsafe
219+
.suggestion = needs `unsafe` before the extern keyword
220+
221+
ast_passes_missing_unsafe_on_extern_lint = extern blocks should be unsafe
222+
.suggestion = needs `unsafe` before the extern keyword
219223
220224
ast_passes_module_nonascii = trying to load file for module `{$name}` with non-ascii identifier name
221225
.help = consider using the `#[path]` attribute to specify filesystem path

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11311131
MISSING_UNSAFE_ON_EXTERN,
11321132
item.id,
11331133
item.span,
1134-
BuiltinLintDiag::MissingUnsafeOnExtern {
1134+
errors::MissingUnsafeOnExternLint {
11351135
suggestion: item.span.shrink_to_lo(),
11361136
},
11371137
);

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,13 @@ pub(crate) struct MissingUnsafeOnExtern {
523523
pub span: Span,
524524
}
525525

526+
#[derive(LintDiagnostic)]
527+
#[diag(ast_passes_missing_unsafe_on_extern_lint)]
528+
pub(crate) struct MissingUnsafeOnExternLint {
529+
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
530+
pub suggestion: Span,
531+
}
532+
526533
#[derive(Diagnostic)]
527534
#[diag(ast_passes_fieldless_union)]
528535
pub(crate) struct FieldlessUnion {

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ impl<S: Stage> SingleAttributeParser<S> for CrateNameParser {
4343
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
4444
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
4545
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
46-
const TYPE: AttributeType = AttributeType::CrateLevel;
47-
48-
// because it's a crate-level attribute, we already warn about it.
49-
// Putting target limitations here would give duplicate warnings
50-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
46+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
5147

5248
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
5349
let ArgParser::NameValue(n) = args else {
@@ -76,11 +72,7 @@ impl<S: Stage> SingleAttributeParser<S> for RecursionLimitParser {
7672
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
7773
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
7874
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute");
79-
const TYPE: AttributeType = AttributeType::CrateLevel;
80-
81-
// because it's a crate-level attribute, we already warn about it.
82-
// Putting target limitations here would give duplicate warnings
83-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
75+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
8476

8577
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
8678
let ArgParser::NameValue(nv) = args else {
@@ -103,11 +95,7 @@ impl<S: Stage> SingleAttributeParser<S> for MoveSizeLimitParser {
10395
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
10496
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
10597
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
106-
const TYPE: AttributeType = AttributeType::CrateLevel;
107-
108-
// because it's a crate-level attribute, we already warn about it.
109-
// Putting target limitations here would give duplicate warnings
110-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
98+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
11199

112100
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
113101
let ArgParser::NameValue(nv) = args else {
@@ -130,11 +118,7 @@ impl<S: Stage> SingleAttributeParser<S> for TypeLengthLimitParser {
130118
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
131119
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
132120
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
133-
const TYPE: AttributeType = AttributeType::CrateLevel;
134-
135-
// because it's a crate-level attribute, we already warn about it.
136-
// Putting target limitations here would give duplicate warnings
137-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
121+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
138122

139123
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
140124
let ArgParser::NameValue(nv) = args else {
@@ -157,11 +141,7 @@ impl<S: Stage> SingleAttributeParser<S> for PatternComplexityLimitParser {
157141
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
158142
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
159143
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
160-
const TYPE: AttributeType = AttributeType::CrateLevel;
161-
162-
// because it's a crate-level attribute, we already warn about it.
163-
// Putting target limitations here would give duplicate warnings
164-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
144+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
165145

166146
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
167147
let ArgParser::NameValue(nv) = args else {
@@ -182,21 +162,15 @@ pub(crate) struct NoCoreParser;
182162
impl<S: Stage> NoArgsAttributeParser<S> for NoCoreParser {
183163
const PATH: &[Symbol] = &[sym::no_core];
184164
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
185-
// because it's a crate-level attribute, we already warn about it.
186-
// Putting target limitations here would give duplicate warnings
187-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
165+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
188166
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoCore;
189-
const TYPE: AttributeType = AttributeType::CrateLevel;
190167
}
191168

192169
pub(crate) struct NoStdParser;
193170

194171
impl<S: Stage> NoArgsAttributeParser<S> for NoStdParser {
195172
const PATH: &[Symbol] = &[sym::no_std];
196173
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
197-
// because it's a crate-level attribute, we already warn about it.
198-
// Putting target limitations here would give duplicate warnings
199-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
174+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
200175
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
201-
const TYPE: AttributeType = AttributeType::CrateLevel;
202176
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
//! - [`CombineAttributeParser`](crate::attributes::CombineAttributeParser): makes it easy to implement an attribute which should combine the
1313
//! contents of attributes, if an attribute appear multiple times in a list
1414
//!
15-
//! By default, attributes are allowed anywhere. When adding an attribute that should only be used
16-
//! at the crate root, consider setting the `TYPE` in the parser trait to
17-
//! [`AttributeType::CrateLevel`](rustc_feature::AttributeType::CrateLevel).
18-
//!
1915
//! Attributes should be added to `crate::context::ATTRIBUTE_PARSERS` to be parsed.
2016
2117
use std::marker::PhantomData;
2218

23-
use rustc_feature::{AttributeTemplate, AttributeType, template};
19+
use rustc_feature::{AttributeTemplate, template};
2420
use rustc_hir::attrs::AttributeKind;
2521
use rustc_span::{Span, Symbol};
2622
use thin_vec::ThinVec;
@@ -89,11 +85,8 @@ pub(crate) trait AttributeParser<S: Stage>: Default + 'static {
8985
///
9086
/// If an attribute has this symbol, the `accept` function will be called on it.
9187
const ATTRIBUTES: AcceptMapping<Self, S>;
92-
9388
const ALLOWED_TARGETS: AllowedTargets;
9489

95-
const TYPE: AttributeType = AttributeType::Normal;
96-
9790
/// The parser has gotten a chance to accept the attributes on an item,
9891
/// here it can produce an attribute.
9992
///
@@ -135,8 +128,6 @@ pub(crate) trait SingleAttributeParser<S: Stage>: 'static {
135128
/// The template this attribute parser should implement. Used for diagnostics.
136129
const TEMPLATE: AttributeTemplate;
137130

138-
const TYPE: AttributeType = AttributeType::Normal;
139-
140131
/// Converts a single syntactical attribute to a single semantic attribute, or [`AttributeKind`]
141132
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind>;
142133
}
@@ -183,8 +174,6 @@ impl<T: SingleAttributeParser<S>, S: Stage> AttributeParser<S> for Single<T, S>
183174
)];
184175
const ALLOWED_TARGETS: AllowedTargets = T::ALLOWED_TARGETS;
185176

186-
const TYPE: AttributeType = T::TYPE;
187-
188177
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
189178
Some(self.1?.0)
190179
}
@@ -269,7 +258,6 @@ pub(crate) trait NoArgsAttributeParser<S: Stage>: 'static {
269258
const PATH: &[Symbol];
270259
const ON_DUPLICATE: OnDuplicate<S>;
271260
const ALLOWED_TARGETS: AllowedTargets;
272-
const TYPE: AttributeType = AttributeType::Normal;
273261

274262
/// Create the [`AttributeKind`] given attribute's [`Span`].
275263
const CREATE: fn(Span) -> AttributeKind;
@@ -289,7 +277,6 @@ impl<T: NoArgsAttributeParser<S>, S: Stage> SingleAttributeParser<S> for Without
289277
const ON_DUPLICATE: OnDuplicate<S> = T::ON_DUPLICATE;
290278
const ALLOWED_TARGETS: AllowedTargets = T::ALLOWED_TARGETS;
291279
const TEMPLATE: AttributeTemplate = template!(Word);
292-
const TYPE: AttributeType = T::TYPE;
293280

294281
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
295282
if let Err(span) = args.no_args() {
@@ -323,8 +310,6 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
323310
/// The template this attribute parser should implement. Used for diagnostics.
324311
const TEMPLATE: AttributeTemplate;
325312

326-
const TYPE: AttributeType = AttributeType::Normal;
327-
328313
/// Converts a single syntactical attribute to a number of elements of the semantic attribute, or [`AttributeKind`]
329314
fn extend<'c>(
330315
cx: &'c mut AcceptContext<'_, '_, S>,
@@ -360,7 +345,6 @@ impl<T: CombineAttributeParser<S>, S: Stage> AttributeParser<S> for Combine<T, S
360345
group.items.extend(T::extend(cx, args))
361346
})];
362347
const ALLOWED_TARGETS: AllowedTargets = T::ALLOWED_TARGETS;
363-
const TYPE: AttributeType = T::TYPE;
364348

365349
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
366350
if let Some(first_span) = self.first_span {

compiler/rustc_attr_parsing/src/attributes/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// data structures
22
#[doc(hidden)]
3-
pub(super) use rustc_feature::{AttributeTemplate, AttributeType, template};
3+
pub(super) use rustc_feature::{AttributeTemplate, template};
44
#[doc(hidden)]
55
pub(super) use rustc_hir::attrs::AttributeKind;
66
#[doc(hidden)]

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::mem;
22

3-
use rustc_feature::AttributeType;
4-
53
use super::prelude::*;
64
use crate::attributes::{
75
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
@@ -155,8 +153,7 @@ pub(crate) struct CoherenceIsCoreParser;
155153
impl<S: Stage> NoArgsAttributeParser<S> for CoherenceIsCoreParser {
156154
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
157155
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
158-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
159-
const TYPE: AttributeType = AttributeType::CrateLevel;
156+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
160157
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::CoherenceIsCore;
161158
}
162159

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::LazyLock;
66
use private::Sealed;
77
use rustc_ast::{AttrStyle, CRATE_NODE_ID, MetaItemLit, NodeId};
88
use rustc_errors::{Diag, Diagnostic, Level};
9-
use rustc_feature::{AttributeTemplate, AttributeType};
9+
use rustc_feature::AttributeTemplate;
1010
use rustc_hir::attrs::AttributeKind;
1111
use rustc_hir::lints::{AttributeLint, AttributeLintKind};
1212
use rustc_hir::{AttrPath, CRATE_HIR_ID, HirId};
@@ -83,7 +83,6 @@ pub(super) struct GroupTypeInnerAccept<S: Stage> {
8383
pub(super) template: AttributeTemplate,
8484
pub(super) accept_fn: AcceptFn<S>,
8585
pub(super) allowed_targets: AllowedTargets,
86-
pub(super) attribute_type: AttributeType,
8786
}
8887

8988
type AcceptFn<S> =
@@ -133,7 +132,6 @@ macro_rules! attribute_parsers {
133132
})
134133
}),
135134
allowed_targets: <$names as crate::attributes::AttributeParser<$stage>>::ALLOWED_TARGETS,
136-
attribute_type: <$names as crate::attributes::AttributeParser<$stage>>::TYPE,
137135
});
138136
}
139137

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
272272

273273
(accept.accept_fn)(&mut cx, args);
274274
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
275-
Self::check_type(accept.attribute_type, target, &mut cx);
276275
Self::check_target(&accept.allowed_targets, target, &mut cx);
277276
}
278277
}

0 commit comments

Comments
 (0)