Skip to content

Commit 56cc9e3

Browse files
committed
Auto merge of #151038 - matthiaskrgr:rollup-fBdEuCE, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - #145343 (Dogfood `-Zno-embed-metadata` in the standard library) - #150151 (Destabilise `target-spec-json`) - #150723 (std: move `errno` and related functions into `sys::io`) - #150826 (Add `f16` inline ASM support for s390x) - #150934 (Move some checks from `check_doc_attrs` directly into `rustc_attr_parsing`) - #150943 (Port `#[must_not_suspend]` to attribute parser) - #150990 (std: sys: net: uefi: Make TcpStream Send) - #150995 (core: ptr: split_at_mut: fix typo in safety doc) - #150998 (Relax test expectation for @__llvm_profile_runtime_user) - #151002 (Remove a workaround for a bug (take 2)) - #151005 (Fix typo in `MaybeUninit` docs) - #151011 (Update books) r? @ghost
2 parents 2f1bd3f + d63bda3 commit 56cc9e3

File tree

113 files changed

+1311
-1131
lines changed

Some content is hidden

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

113 files changed

+1311
-1131
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ attr_parsing_doc_alias_malformed =
2323
attr_parsing_doc_alias_start_end =
2424
{$attr_str} cannot start or end with ' '
2525
26+
attr_parsing_doc_attr_not_crate_level =
27+
`#![doc({$attr_name} = "...")]` isn't allowed as a crate-level attribute
28+
2629
attr_parsing_doc_attribute_not_attribute =
2730
nonexistent builtin attribute `{$attribute}` used in `#[doc(attribute = "...")]`
2831
.help = only existing builtin attributes are allowed in core/std

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 96 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_ast::ast::{AttrStyle, LitKind, MetaItemLit};
22
use rustc_feature::template;
3+
use rustc_hir::Target;
34
use rustc_hir::attrs::{
45
AttributeKind, CfgEntry, CfgHideShow, CfgInfo, DocAttribute, DocInline, HideOrShow,
56
};
@@ -12,8 +13,8 @@ use super::{AcceptMapping, AttributeParser};
1213
use crate::context::{AcceptContext, FinalizeContext, Stage};
1314
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
1415
use crate::session_diagnostics::{
15-
DocAliasBadChar, DocAliasEmpty, DocAliasMalformed, DocAliasStartEnd, DocAttributeNotAttribute,
16-
DocKeywordNotKeyword,
16+
DocAliasBadChar, DocAliasEmpty, DocAliasMalformed, DocAliasStartEnd, DocAttrNotCrateLevel,
17+
DocAttributeNotAttribute, DocKeywordNotKeyword,
1718
};
1819

1920
fn check_keyword<S: Stage>(cx: &mut AcceptContext<'_, '_, S>, keyword: Symbol, span: Span) -> bool {
@@ -43,16 +44,39 @@ fn check_attribute<S: Stage>(
4344
false
4445
}
4546

46-
fn parse_keyword_and_attribute<S, F>(
47+
/// Checks that an attribute is *not* used at the crate level. Returns `true` if valid.
48+
fn check_attr_not_crate_level<S: Stage>(
49+
cx: &mut AcceptContext<'_, '_, S>,
50+
span: Span,
51+
attr_name: Symbol,
52+
) -> bool {
53+
if cx.shared.target.is_some_and(|target| target == Target::Crate) {
54+
cx.emit_err(DocAttrNotCrateLevel { span, attr_name });
55+
return false;
56+
}
57+
true
58+
}
59+
60+
/// Checks that an attribute is used at the crate level. Returns `true` if valid.
61+
fn check_attr_crate_level<S: Stage>(cx: &mut AcceptContext<'_, '_, S>, span: Span) -> bool {
62+
if cx.shared.target.is_some_and(|target| target != Target::Crate) {
63+
cx.emit_lint(
64+
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
65+
AttributeLintKind::AttrCrateLevelOnly,
66+
span,
67+
);
68+
return false;
69+
}
70+
true
71+
}
72+
73+
fn parse_keyword_and_attribute<S: Stage>(
4774
cx: &mut AcceptContext<'_, '_, S>,
4875
path: &OwnedPathParser,
4976
args: &ArgParser,
5077
attr_value: &mut Option<(Symbol, Span)>,
51-
callback: F,
52-
) where
53-
S: Stage,
54-
F: FnOnce(&mut AcceptContext<'_, '_, S>, Symbol, Span) -> bool,
55-
{
78+
attr_name: Symbol,
79+
) {
5680
let Some(nv) = args.name_value() else {
5781
cx.expected_name_value(args.span().unwrap_or(path.span()), path.word_sym());
5882
return;
@@ -63,16 +87,26 @@ fn parse_keyword_and_attribute<S, F>(
6387
return;
6488
};
6589

66-
if !callback(cx, value, nv.value_span) {
90+
let ret = if attr_name == sym::keyword {
91+
check_keyword(cx, value, nv.value_span)
92+
} else {
93+
check_attribute(cx, value, nv.value_span)
94+
};
95+
if !ret {
6796
return;
6897
}
6998

99+
let span = path.span();
70100
if attr_value.is_some() {
71-
cx.duplicate_key(path.span(), path.word_sym().unwrap());
101+
cx.duplicate_key(span, path.word_sym().unwrap());
72102
return;
73103
}
74104

75-
*attr_value = Some((value, path.span()));
105+
if !check_attr_not_crate_level(cx, span, attr_name) {
106+
return;
107+
}
108+
109+
*attr_value = Some((value, span));
76110
}
77111

78112
#[derive(Default, Debug)]
@@ -102,6 +136,10 @@ impl DocParser {
102136
return;
103137
}
104138

139+
if !check_attr_crate_level(cx, path.span()) {
140+
return;
141+
}
142+
105143
self.attribute.no_crate_inject = Some(path.span())
106144
}
107145
Some(sym::attr) => {
@@ -155,6 +193,9 @@ impl DocParser {
155193
cx.emit_err(DocAliasStartEnd { span, attr_str });
156194
return;
157195
}
196+
if !check_attr_not_crate_level(cx, span, sym::alias) {
197+
return;
198+
}
158199

159200
if let Some(first_definition) = self.attribute.aliases.get(&alias).copied() {
160201
cx.emit_lint(
@@ -366,7 +407,33 @@ impl DocParser {
366407
self.attribute.$ident = Some(path.span());
367408
}};
368409
}
369-
macro_rules! string_arg {
410+
macro_rules! no_args_and_not_crate_level {
411+
($ident: ident) => {{
412+
if let Err(span) = args.no_args() {
413+
cx.expected_no_args(span);
414+
return;
415+
}
416+
let span = path.span();
417+
if !check_attr_not_crate_level(cx, span, sym::$ident) {
418+
return;
419+
}
420+
self.attribute.$ident = Some(span);
421+
}};
422+
}
423+
macro_rules! no_args_and_crate_level {
424+
($ident: ident) => {{
425+
if let Err(span) = args.no_args() {
426+
cx.expected_no_args(span);
427+
return;
428+
}
429+
let span = path.span();
430+
if !check_attr_crate_level(cx, span) {
431+
return;
432+
}
433+
self.attribute.$ident = Some(span);
434+
}};
435+
}
436+
macro_rules! string_arg_and_crate_level {
370437
($ident: ident) => {{
371438
let Some(nv) = args.name_value() else {
372439
cx.expected_name_value(args.span().unwrap_or(path.span()), path.word_sym());
@@ -378,6 +445,10 @@ impl DocParser {
378445
return;
379446
};
380447

448+
if !check_attr_crate_level(cx, path.span()) {
449+
return;
450+
}
451+
381452
// FIXME: It's errorring when the attribute is passed multiple times on the command
382453
// line.
383454
// The right fix for this would be to only check this rule if the attribute is
@@ -394,12 +465,14 @@ impl DocParser {
394465
match path.word_sym() {
395466
Some(sym::alias) => self.parse_alias(cx, path, args),
396467
Some(sym::hidden) => no_args!(hidden),
397-
Some(sym::html_favicon_url) => string_arg!(html_favicon_url),
398-
Some(sym::html_logo_url) => string_arg!(html_logo_url),
399-
Some(sym::html_no_source) => no_args!(html_no_source),
400-
Some(sym::html_playground_url) => string_arg!(html_playground_url),
401-
Some(sym::html_root_url) => string_arg!(html_root_url),
402-
Some(sym::issue_tracker_base_url) => string_arg!(issue_tracker_base_url),
468+
Some(sym::html_favicon_url) => string_arg_and_crate_level!(html_favicon_url),
469+
Some(sym::html_logo_url) => string_arg_and_crate_level!(html_logo_url),
470+
Some(sym::html_no_source) => no_args_and_crate_level!(html_no_source),
471+
Some(sym::html_playground_url) => string_arg_and_crate_level!(html_playground_url),
472+
Some(sym::html_root_url) => string_arg_and_crate_level!(html_root_url),
473+
Some(sym::issue_tracker_base_url) => {
474+
string_arg_and_crate_level!(issue_tracker_base_url)
475+
}
403476
Some(sym::inline) => self.parse_inline(cx, path, args, DocInline::Inline),
404477
Some(sym::no_inline) => self.parse_inline(cx, path, args, DocInline::NoInline),
405478
Some(sym::masked) => no_args!(masked),
@@ -410,18 +483,18 @@ impl DocParser {
410483
path,
411484
args,
412485
&mut self.attribute.keyword,
413-
check_keyword,
486+
sym::keyword,
414487
),
415488
Some(sym::attribute) => parse_keyword_and_attribute(
416489
cx,
417490
path,
418491
args,
419492
&mut self.attribute.attribute,
420-
check_attribute,
493+
sym::attribute,
421494
),
422-
Some(sym::fake_variadic) => no_args!(fake_variadic),
423-
Some(sym::search_unbox) => no_args!(search_unbox),
424-
Some(sym::rust_logo) => no_args!(rust_logo),
495+
Some(sym::fake_variadic) => no_args_and_not_crate_level!(fake_variadic),
496+
Some(sym::search_unbox) => no_args_and_not_crate_level!(search_unbox),
497+
Some(sym::rust_logo) => no_args_and_crate_level!(rust_logo),
425498
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
426499
Some(sym::test) => {
427500
let Some(list) = args.list() else {

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub(crate) mod link_attrs;
4747
pub(crate) mod lint_helpers;
4848
pub(crate) mod loop_match;
4949
pub(crate) mod macro_attrs;
50+
pub(crate) mod must_not_suspend;
5051
pub(crate) mod must_use;
5152
pub(crate) mod no_implicit_prelude;
5253
pub(crate) mod no_link;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use super::prelude::*;
2+
3+
pub(crate) struct MustNotSuspendParser;
4+
5+
impl<S: Stage> SingleAttributeParser<S> for MustNotSuspendParser {
6+
const PATH: &[rustc_span::Symbol] = &[sym::must_not_suspend];
7+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
8+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
9+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
10+
Allow(Target::Struct),
11+
Allow(Target::Enum),
12+
Allow(Target::Union),
13+
Allow(Target::Trait),
14+
]);
15+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["count"]);
16+
17+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
18+
let reason = match args {
19+
ArgParser::NameValue(reason) => match reason.value_as_str() {
20+
Some(val) => Some(val),
21+
None => {
22+
cx.expected_nv_or_no_args(reason.value_span);
23+
return None;
24+
}
25+
},
26+
ArgParser::NoArgs => None,
27+
ArgParser::List(list) => {
28+
cx.expected_nv_or_no_args(list.span);
29+
return None;
30+
}
31+
};
32+
33+
Some(AttributeKind::MustNotSupend { reason })
34+
}
35+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use crate::attributes::macro_attrs::{
5151
AllowInternalUnsafeParser, CollapseDebugInfoParser, MacroEscapeParser, MacroExportParser,
5252
MacroUseParser,
5353
};
54+
use crate::attributes::must_not_suspend::MustNotSuspendParser;
5455
use crate::attributes::must_use::MustUseParser;
5556
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
5657
use crate::attributes::no_link::NoLinkParser;
@@ -89,7 +90,6 @@ use crate::session_diagnostics::{
8990
AttributeParseError, AttributeParseErrorReason, ParsedDescription,
9091
};
9192
use crate::target_checking::AllowedTargets;
92-
9393
type GroupType<S> = LazyLock<GroupTypeInner<S>>;
9494

9595
pub(super) struct GroupTypeInner<S: Stage> {
@@ -208,6 +208,7 @@ attribute_parsers!(
208208
Single<LinkageParser>,
209209
Single<MacroExportParser>,
210210
Single<MoveSizeLimitParser>,
211+
Single<MustNotSuspendParser>,
211212
Single<MustUseParser>,
212213
Single<ObjcClassParser>,
213214
Single<ObjcSelectorParser>,
@@ -655,6 +656,7 @@ pub struct SharedContext<'p, 'sess, S: Stage> {
655656
pub(crate) target_span: Span,
656657
/// The id ([`NodeId`] if `S` is `Early`, [`HirId`] if `S` is `Late`) of the syntactical component this attribute was applied to
657658
pub(crate) target_id: S::Id,
659+
pub(crate) target: Option<rustc_hir::Target>,
658660

659661
pub(crate) emit_lint: &'p mut dyn FnMut(AttributeLint<S::Id>),
660662
}

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ impl<'sess> AttributeParser<'sess, Early> {
218218
cx: &mut parser,
219219
target_span,
220220
target_id: target_node_id,
221+
target: None,
221222
emit_lint: &mut emit_lint,
222223
},
223224
attr_span,
@@ -378,6 +379,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
378379
cx: self,
379380
target_span,
380381
target_id,
382+
target: Some(target),
381383
emit_lint: &mut emit_lint,
382384
},
383385
attr_span,
@@ -429,6 +431,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
429431
cx: self,
430432
target_span,
431433
target_id,
434+
target: Some(target),
432435
emit_lint: &mut emit_lint,
433436
},
434437
all_attrs: &attr_paths,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ pub(crate) struct DocAliasStartEnd<'a> {
4747
pub attr_str: &'a str,
4848
}
4949

50+
#[derive(Diagnostic)]
51+
#[diag(attr_parsing_doc_attr_not_crate_level)]
52+
pub(crate) struct DocAttrNotCrateLevel {
53+
#[primary_span]
54+
pub span: Span,
55+
pub attr_name: Symbol,
56+
}
57+
5058
#[derive(Diagnostic)]
5159
#[diag(attr_parsing_doc_keyword_not_keyword)]
5260
#[help]

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,10 @@ fn get_backend_from_raw_matches(
11241124
let backend_name = debug_flags
11251125
.iter()
11261126
.find_map(|x| x.strip_prefix("codegen-backend=").or(x.strip_prefix("codegen_backend=")));
1127+
let unstable_options = debug_flags.iter().find(|x| *x == "unstable-options").is_some();
11271128
let target = parse_target_triple(early_dcx, matches);
11281129
let sysroot = Sysroot::new(matches.opt_str("sysroot").map(PathBuf::from));
1129-
let target = config::build_target_config(early_dcx, &target, sysroot.path());
1130+
let target = config::build_target_config(early_dcx, &target, sysroot.path(), unstable_options);
11301131

11311132
get_codegen_backend(early_dcx, &sysroot, backend_name, &target)
11321133
}

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ pub enum AttributeKind {
824824
/// Represents `#[move_size_limit]`
825825
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: Limit },
826826

827+
/// Represents `#[must_not_suspend]`
828+
MustNotSupend { reason: Option<Symbol> },
829+
827830
/// Represents `#[must_use]`.
828831
MustUse {
829832
span: Span,

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl AttributeKind {
7171
Marker(..) => No,
7272
MayDangle(..) => No,
7373
MoveSizeLimit { .. } => No,
74+
MustNotSupend { .. } => Yes,
7475
MustUse { .. } => Yes,
7576
Naked(..) => No,
7677
NoCore(..) => No,

0 commit comments

Comments
 (0)