Skip to content

Commit 29e68fe

Browse files
committed
Auto merge of #159814 - jhpratt:rollup-Q7TJSeP, r=jhpratt
Rollup of 14 pull requests Successful merges: - #159765 (Avoid spurious rebuilds of JSON docs in bootstrap) - #159781 (Update bootstrap to use -Zembed-metadata=no instead of -Zno-embed-metadata) - #158362 (trait solver: account for universes from replace_bound_vars) - #158372 (rustfmt: Discover modules via `cfg_select!`) - #159173 (Add allowed list check on EII implementations attributes) - #159718 (Make `DocLinkResMap` an `FxIndexMap`) - #159722 ( [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature) - #159731 (std: Implement futex on wasip3 targets, update target spec) - #159755 (Improve consistency of attribute error messages) - #155795 (constify `vec![1, 2, 3]` macro) - #157776 (ci: Enable autodiff tests on x86_64 linux) - #158766 (Promote riscv64-unknown-linux-musl to tier 2 with host tools) - #159271 (str: add ASCII fast path to word_to_titlecase) - #159667 (Make some parser structured suggestions verbose and tweak their wording)
2 parents 1498f99 + 625d5f9 commit 29e68fe

515 files changed

Lines changed: 5547 additions & 4784 deletions

File tree

Some content is hidden

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

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3514,7 +3514,7 @@ pub enum SyntheticAttr {
35143514
/// because they are not needed.
35153515
///
35163516
/// The attribute is used by some clippy lints.
3517-
CfgAttrTrace,
3517+
CfgAttrTrace(CfgEntry),
35183518
}
35193519

35203520
impl AttrItem {

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl AttributeExt for Attribute {
106106
use SyntheticAttr::*;
107107
match &self.kind {
108108
AttrKind::Normal(normal) => normal.item.name(),
109-
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace) => None,
109+
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) => None,
110110
AttrKind::DocComment(..) => None,
111111
}
112112
}
@@ -117,7 +117,7 @@ impl AttributeExt for Attribute {
117117
AttrKind::Normal(normal) => {
118118
Some(normal.item.path.segments.iter().map(|i| i.ident.name).collect())
119119
}
120-
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace) => None,
120+
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) => None,
121121
AttrKind::DocComment(_, _) => None,
122122
}
123123
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'a> AstValidator<'a> {
525525
[sym::allow, sym::deny, sym::expect, sym::forbid, sym::splat, sym::warn];
526526
!attr.has_any_name(&arr) && rustc_attr_parsing::is_builtin_attr(&normal.item)
527527
}
528-
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace) => false,
528+
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) => false,
529529
AttrKind::DocComment(..) => true,
530530
})
531531
.for_each(|attr| {
@@ -1202,6 +1202,48 @@ impl<'a> AstValidator<'a> {
12021202
self.visit_vis(vis);
12031203
self.visit_ident(ident);
12041204
}
1205+
1206+
// Check EII implementation attributes against an allowlist.
1207+
fn check_eii_impl_attrs(&self, attrs: &[Attribute], eii_impls: &[EiiImpl]) {
1208+
if eii_impls.is_empty() {
1209+
return;
1210+
}
1211+
1212+
let allowed_attrs: &[Symbol] = &[
1213+
sym::allow,
1214+
sym::warn,
1215+
sym::deny,
1216+
sym::forbid,
1217+
sym::expect,
1218+
sym::doc,
1219+
sym::inline,
1220+
sym::cold,
1221+
sym::optimize,
1222+
sym::coverage,
1223+
sym::sanitize,
1224+
sym::must_use,
1225+
sym::deprecated,
1226+
];
1227+
1228+
for attr in attrs {
1229+
let AttrKind::Normal(normal) = &attr.kind else {
1230+
continue;
1231+
};
1232+
if attr.has_any_name(allowed_attrs) {
1233+
continue;
1234+
}
1235+
1236+
let attr_name = pprust::path_to_string(&normal.item.path);
1237+
for eii_impl in eii_impls {
1238+
self.dcx().emit_err(diagnostics::EiiImplAttributeNotSupported {
1239+
attr_span: attr.span,
1240+
attr_name: &attr_name,
1241+
eii_span: eii_impl.span,
1242+
eii_name: pprust::path_to_string(&eii_impl.eii_macro_path),
1243+
});
1244+
}
1245+
}
1246+
}
12051247
}
12061248

12071249
/// Checks that generic parameters are in the correct order,
@@ -1391,6 +1433,7 @@ impl Visitor<'_> for AstValidator<'_> {
13911433
for EiiImpl { eii_macro_path, .. } in eii_impls {
13921434
self.visit_path(eii_macro_path);
13931435
}
1436+
self.check_eii_impl_attrs(&item.attrs, eii_impls);
13941437

13951438
let is_intrinsic = item.attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic));
13961439
if body.is_none() && !is_intrinsic && !self.is_sdylib_interface {
@@ -1566,8 +1609,9 @@ impl Visitor<'_> for AstValidator<'_> {
15661609

15671610
visit::walk_item(self, item);
15681611
}
1569-
ItemKind::Static(StaticItem { expr, safety, .. }) => {
1612+
ItemKind::Static(StaticItem { expr, safety, eii_impls, .. }) => {
15701613
self.check_item_safety(item.span, *safety);
1614+
self.check_eii_impl_attrs(&item.attrs, eii_impls);
15711615
if matches!(safety, Safety::Unsafe(_)) {
15721616
self.dcx().emit_err(diagnostics::UnsafeStatic { span: item.span });
15731617
}

compiler/rustc_ast_passes/src/diagnostics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ pub(crate) struct FnParamForbiddenAttr {
189189
pub span: Span,
190190
}
191191

192+
#[derive(Diagnostic)]
193+
#[diag("`#[{$eii_name}]` is not allowed to have `#[{$attr_name}]`")]
194+
pub(crate) struct EiiImplAttributeNotSupported<'a> {
195+
#[primary_span]
196+
pub attr_span: Span,
197+
pub attr_name: &'a str,
198+
pub eii_name: String,
199+
#[label("`#[{$eii_name}]` is not allowed to have `#[{$attr_name}]`")]
200+
pub eii_span: Span,
201+
}
202+
192203
#[derive(Diagnostic)]
193204
#[diag("`self` parameter is only allowed in associated functions")]
194205
#[note("associated functions are those in `impl` or `trait` definitions")]

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
665665
fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) -> bool {
666666
use ast::SyntheticAttr::*;
667667
match attr.kind {
668-
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace) => {
668+
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) => {
669669
// These are internal synthetic attributes with no syntax, so avoid printing them
670670
// to keep the printed code reasonably parse-able.
671671
return false;

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,13 @@ pub fn parse_cfg_attr(
353353
{
354354
(dspan.entire(), AttributeParseErrorReason::ExpectedAtLeastOneArgument)
355355
} else {
356-
(cfg_attr.span, AttributeParseErrorReason::ExpectedList)
356+
(cfg_attr.get_normal_item().span, AttributeParseErrorReason::ExpectedList)
357357
};
358358

359359
sess.dcx().emit_err(AttributeParseError {
360360
span,
361361
attr_span: cfg_attr.span,
362+
inner_span: cfg_attr.get_normal_item().span,
362363
template: CFG_ATTR_TEMPLATE,
363364
path: AttrPath::from_ast(&cfg_attr.get_normal_item().path, identity),
364365
description: ParsedDescription::Attribute,

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl SingleAttributeParser for PatternComplexityLimitParser {
127127
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
128128
const STABILITY: AttributeStability = unstable!(
129129
rustc_attrs,
130-
"the `#[pattern_complexity_limit]` attribute is used for rustc unit tests"
130+
"the `pattern_complexity_limit` attribute is used for rustc unit tests"
131131
);
132132

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

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unimplemented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl AttributeParser for OnUnimplementedParser {
3838
template!(List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]),
3939
unstable!(
4040
rustc_attrs,
41-
"see `#[diagnostic::on_unimplemented]` for the stable equivalent of this attribute"
41+
"see the `diagnostic::on_unimplemented` attribute for the stable equivalent of this attribute"
4242
),
4343
|this, cx, args| {
4444
this.parse(cx, args, Mode::RustcOnUnimplemented);

compiler/rustc_attr_parsing/src/attributes/dummy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl SingleAttributeParser for RustcDummyParser {
1515
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::ManuallyChecked;
1616
const TEMPLATE: AttributeTemplate = template!(Word); // Anything, really
1717
const STABILITY: AttributeStability =
18-
unstable!(rustc_attrs, "the `#[rustc_dummy]` attribute is used for rustc unit tests");
18+
unstable!(rustc_attrs, "the `rustc_dummy` attribute is used for rustc unit tests");
1919

2020
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
2121
args.ignore_args();

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ impl SingleAttributeParser for RustcForceInlineParser {
7070
Allow(Target::Fn),
7171
Allow(Target::Method(MethodKind::Inherent)),
7272
]);
73-
const STABILITY: AttributeStability =
74-
unstable!(rustc_attrs, "`#[rustc_force_inline]` forces a free function to be inlined");
73+
const STABILITY: AttributeStability = unstable!(
74+
rustc_attrs,
75+
"the `rustc_force_inline` attribute forces a free function to be inlined"
76+
);
7577
const TEMPLATE: AttributeTemplate = template!(Word, List: &["reason"], NameValueStr: "reason");
7678

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

0 commit comments

Comments
 (0)