Skip to content

Commit 8412708

Browse files
committed
Auto merge of #159807 - jhpratt:rollup-ovBYIBx, r=jhpratt
Rollup of 12 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) - #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) - #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) - #159666 (fix(ld64.lld): route version mismatch warnings to linker_info on macOS) - #159667 (Make some parser structured suggestions verbose and tweak their wording)
2 parents 1498f99 + 00658d9 commit 8412708

115 files changed

Lines changed: 1225 additions & 547 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/synthetic.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ pub(crate) struct SyntheticAttrState {
1515
cfg_trace: ThinVec<(CfgEntry, Span)>,
1616

1717
/// Attribute state for `SyntheticAttr::CfgAttrTrace` attributes.
18-
/// The arguments of these attributes is no longer relevant for any later passes, only their
19-
/// presence. So we discard the arguments here.
20-
cfg_attr_trace: bool,
18+
cfg_attr_trace: ThinVec<(CfgEntry, Span)>,
2119
}
2220

2321
impl SyntheticAttrState {
@@ -33,8 +31,10 @@ impl SyntheticAttrState {
3331
cfg.lower_spans(lower_span);
3432
self.cfg_trace.push((cfg, attr_span));
3533
}
36-
SyntheticAttr::CfgAttrTrace => {
37-
self.cfg_attr_trace = true;
34+
SyntheticAttr::CfgAttrTrace(cfg) => {
35+
let mut cfg = cfg.clone();
36+
cfg.lower_spans(lower_span);
37+
self.cfg_attr_trace.push((cfg, attr_span));
3838
}
3939
}
4040
}
@@ -43,8 +43,8 @@ impl SyntheticAttrState {
4343
if !self.cfg_trace.is_empty() {
4444
attributes.push(Attribute::Parsed(AttributeKind::CfgTrace(self.cfg_trace)));
4545
}
46-
if self.cfg_attr_trace {
47-
attributes.push(Attribute::Parsed(AttributeKind::CfgAttrTrace));
46+
if !self.cfg_attr_trace.is_empty() {
47+
attributes.push(Attribute::Parsed(AttributeKind::CfgAttrTrace(self.cfg_attr_trace)));
4848
}
4949
}
5050
}

compiler/rustc_attr_parsing/src/validate_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
2424
use ast::SyntheticAttr::*;
2525
match &attr.kind {
2626
AttrKind::Normal(_) => {}
27-
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace) | AttrKind::DocComment(..) => return,
27+
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) | AttrKind::DocComment(..) => return,
2828
}
2929

3030
let builtin_attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name));

compiler/rustc_codegen_cranelift/scripts/setup_rust_fork.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ index 2e16f2cf27..3ac3df99a8 100644
6262
# Add RUSTFLAGS_BOOTSTRAP to RUSTFLAGS for bootstrap compilation.
6363
# Note that RUSTFLAGS_BOOTSTRAP should always be added to the end of
6464
# RUSTFLAGS, since that causes RUSTFLAGS_BOOTSTRAP to override RUSTFLAGS.
65-
diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs
66-
index 6de70c7d70c..d5035b581ce 100644
67-
--- a/src/bootstrap/src/core/builder/cargo.rs
68-
+++ b/src/bootstrap/src/core/builder/cargo.rs
69-
@@ -1197,7 +1197,7 @@ fn cargo(
70-
cargo.env("RUSTC_BOOTSTRAP", "1");
71-
72-
if matches!(mode, Mode::Std) {
73-
- cargo.arg("-Zno-embed-metadata");
74-
+ cargo.arg("-Zembed-metadata=no");
75-
}
76-
77-
if self.config.dump_bootstrap_shims {
7865
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
7966
index bc68bfe396..00143ef3ed 100644
8067
--- a/src/bootstrap/src/core/config/config.rs

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,9 @@ fn is_msvc_link_exe(sess: &Session) -> bool {
884884
&& linker_path.to_str() == Some("link.exe")
885885
}
886886

887-
fn is_macos_ld(sess: &Session) -> bool {
887+
fn is_macos_linker(sess: &Session) -> bool {
888888
let (_, flavor) = linker_and_flavor(sess);
889-
sess.target.is_like_darwin && matches!(flavor, LinkerFlavor::Darwin(_, Lld::No))
889+
sess.target.is_like_darwin && matches!(flavor, LinkerFlavor::Darwin(..))
890890
}
891891

892892
fn is_windows_gnu_ld(sess: &Session) -> bool {
@@ -953,8 +953,8 @@ fn report_linker_output(
953953
*output += "\r\n"
954954
}
955955
});
956-
} else if is_macos_ld(sess) {
957-
info!("inferred macOS LD");
956+
} else if is_macos_linker(sess) {
957+
info!("inferred macOS linker");
958958

959959
// FIXME: Tracked by https://github.com/rust-lang/rust/issues/136113
960960
let deployment_mismatch = |line: &str| {
@@ -967,6 +967,8 @@ fn report_linker_output(
967967
&& line.contains("building for")
968968
&& line.contains("but linking with")
969969
&& line.contains("which was built for newer version"))
970+
// lld (ld64.lld / rust-lld):
971+
|| line.contains("which is newer than target minimum of")
970972
};
971973
// FIXME: This is a real warning we would like to show, but it hits too many crates
972974
// to want to turn it on immediately.

compiler/rustc_expand/src/config.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::iter;
44

5+
use rustc_ast::attr::data_structures::CfgEntry;
56
use rustc_ast::token::{Delimiter, Token, TokenKind};
67
use rustc_ast::tokenstream::{
78
AttrTokenStream, AttrTokenTree, LazyAttrTokenStream, Spacing, TokenTree, WithTokens,
@@ -248,16 +249,15 @@ impl<'a> StripUnconfigured<'a> {
248249
/// is in the original source file. Gives a compiler error if the syntax of
249250
/// the attribute is incorrect.
250251
pub(crate) fn expand_cfg_attr(&self, cfg_attr: &Attribute, recursive: bool) -> Vec<Attribute> {
251-
// A synthetic trace attribute left in AST in place of the original `cfg_attr` attribute.
252-
// It can later be used by lints or other diagnostics.
253-
let trace_attr = cfg_attr.clone().convert_normal_to_synthetic(SyntheticAttr::CfgAttrTrace);
254-
255252
let Some((cfg_predicate, expanded_attrs)) = rustc_attr_parsing::parse_cfg_attr(
256253
cfg_attr,
257254
self.sess,
258255
self.features,
259256
self.lint_node_id,
260257
) else {
258+
let trace_attr = cfg_attr.clone().convert_normal_to_synthetic(
259+
SyntheticAttr::CfgAttrTrace(CfgEntry::Bool(true, cfg_attr.span)),
260+
);
261261
return vec![trace_attr];
262262
};
263263

@@ -271,7 +271,15 @@ impl<'a> StripUnconfigured<'a> {
271271
);
272272
}
273273

274-
if !attr::eval_config_entry(self.sess, &cfg_predicate).as_bool() {
274+
let cfg_eval = attr::eval_config_entry(self.sess, &cfg_predicate).as_bool();
275+
276+
// A synthetic trace attribute left in AST in place of the original `cfg_attr` attribute.
277+
// It can later be used by lints or other diagnostics.
278+
let trace_attr = cfg_attr
279+
.clone()
280+
.convert_normal_to_synthetic(SyntheticAttr::CfgAttrTrace(cfg_predicate));
281+
282+
if !cfg_eval {
275283
return vec![trace_attr];
276284
}
277285

0 commit comments

Comments
 (0)