Skip to content

Commit 622ac04

Browse files
committed
Auto merge of #140633 - Zalathar:rollup-iay94wa, r=Zalathar
Rollup of 7 pull requests Successful merges: - #139675 (Add the AVX10 target features) - #140286 (Check if format argument is identifier to avoid error err-emit) - #140456 (Fix test simd/extract-insert-dyn on s390x) - #140551 (Move some tests out of tests/ui) - #140588 (Adjust some ui tests re. target-dependent errors) - #140617 (Report the `unsafe_attr_outside_unsafe` lint at the closest node) - #140626 (allow `#[rustfmt::skip]` in combination with `#[naked]`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1bea580 + 1239f49 commit 622ac04

File tree

57 files changed

+543
-226
lines changed

Some content is hidden

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

57 files changed

+543
-226
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ struct AstValidator<'a> {
8282
/// Used to ban explicit safety on foreign items when the extern block is not marked as unsafe.
8383
extern_mod_safety: Option<Safety>,
8484

85+
lint_node_id: NodeId,
86+
8587
lint_buffer: &'a mut LintBuffer,
8688
}
8789

@@ -826,7 +828,7 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
826828

827829
impl<'a> Visitor<'a> for AstValidator<'a> {
828830
fn visit_attribute(&mut self, attr: &Attribute) {
829-
validate_attr::check_attr(&self.sess.psess, attr);
831+
validate_attr::check_attr(&self.sess.psess, attr, self.lint_node_id);
830832
}
831833

832834
fn visit_ty(&mut self, ty: &'a Ty) {
@@ -839,6 +841,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
839841
self.has_proc_macro_decls = true;
840842
}
841843

844+
let previous_lint_node_id = mem::replace(&mut self.lint_node_id, item.id);
845+
842846
if let Some(ident) = item.kind.ident()
843847
&& attr::contains_name(&item.attrs, sym::no_mangle)
844848
{
@@ -1128,6 +1132,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11281132
}
11291133
_ => visit::walk_item(self, item),
11301134
}
1135+
1136+
self.lint_node_id = previous_lint_node_id;
11311137
}
11321138

11331139
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
@@ -1694,6 +1700,7 @@ pub fn check_crate(
16941700
outer_impl_trait_span: None,
16951701
disallow_tilde_const: Some(TildeConstReason::Item),
16961702
extern_mod_safety: None,
1703+
lint_node_id: CRATE_NODE_ID,
16971704
lint_buffer: lints,
16981705
};
16991706
visit::walk_crate(&mut validator, krate);

compiler/rustc_codegen_llvm/src/llvm_util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
301301
None
302302
}
303303
("x86", "movrs") if get_version().0 < 20 => None,
304+
("x86", "avx10.1") => Some(LLVMFeature::new("avx10.1-512")),
305+
("x86", "avx10.2") if get_version().0 < 20 => None,
306+
("x86", "avx10.2") if get_version().0 >= 20 => Some(LLVMFeature::new("avx10.2-512")),
304307
(_, s) => Some(LLVMFeature::new(s)),
305308
}
306309
}

compiler/rustc_expand/src/config.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,12 @@ impl<'a> StripUnconfigured<'a> {
274274
/// is in the original source file. Gives a compiler error if the syntax of
275275
/// the attribute is incorrect.
276276
pub(crate) fn expand_cfg_attr(&self, cfg_attr: &Attribute, recursive: bool) -> Vec<Attribute> {
277-
validate_attr::check_attribute_safety(&self.sess.psess, AttributeSafety::Normal, &cfg_attr);
277+
validate_attr::check_attribute_safety(
278+
&self.sess.psess,
279+
AttributeSafety::Normal,
280+
&cfg_attr,
281+
ast::CRATE_NODE_ID,
282+
);
278283

279284
// A trace attribute left in AST in place of the original `cfg_attr` attribute.
280285
// It can later be used by lints or other diagnostics.

compiler/rustc_expand/src/expand.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,11 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
19831983
let mut span: Option<Span> = None;
19841984
while let Some(attr) = attrs.next() {
19851985
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
1986-
validate_attr::check_attr(&self.cx.sess.psess, attr);
1986+
validate_attr::check_attr(
1987+
&self.cx.sess.psess,
1988+
attr,
1989+
self.cx.current_expansion.lint_node_id,
1990+
);
19871991

19881992
let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
19891993
span = Some(current_span);

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ declare_features! (
393393
(unstable, async_for_loop, "1.77.0", Some(118898)),
394394
/// Allows `async` trait bound modifier.
395395
(unstable, async_trait_bounds, "1.85.0", Some(62290)),
396+
/// Allows using Intel AVX10 target features and intrinsics
397+
(unstable, avx10_target_feature, "CURRENT_RUSTC_VERSION", Some(138843)),
396398
/// Allows using C-variadics.
397399
(unstable, c_variadic, "1.34.0", Some(44930)),
398400
/// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.

compiler/rustc_parse/src/validate_attr.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
use rustc_ast::token::Delimiter;
44
use rustc_ast::tokenstream::DelimSpan;
55
use rustc_ast::{
6-
self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, Safety,
6+
self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, NodeId,
7+
Safety,
78
};
89
use rustc_errors::{Applicability, FatalError, PResult};
910
use rustc_feature::{AttributeSafety, AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
@@ -15,7 +16,7 @@ use rustc_span::{Span, Symbol, sym};
1516

1617
use crate::{errors, parse_in};
1718

18-
pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
19+
pub fn check_attr(psess: &ParseSess, attr: &Attribute, id: NodeId) {
1920
if attr.is_doc_comment() || attr.has_name(sym::cfg_trace) || attr.has_name(sym::cfg_attr_trace)
2021
{
2122
return;
@@ -26,7 +27,7 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
2627

2728
// All non-builtin attributes are considered safe
2829
let safety = attr_info.map(|x| x.safety).unwrap_or(AttributeSafety::Normal);
29-
check_attribute_safety(psess, safety, attr);
30+
check_attribute_safety(psess, safety, attr, id);
3031

3132
// Check input tokens for built-in and key-value attributes.
3233
match attr_info {
@@ -154,7 +155,12 @@ fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaIte
154155
}
155156
}
156157

157-
pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr: &Attribute) {
158+
pub fn check_attribute_safety(
159+
psess: &ParseSess,
160+
safety: AttributeSafety,
161+
attr: &Attribute,
162+
id: NodeId,
163+
) {
158164
let attr_item = attr.get_normal_item();
159165

160166
if let AttributeSafety::Unsafe { unsafe_since } = safety {
@@ -185,7 +191,7 @@ pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr:
185191
psess.buffer_lint(
186192
UNSAFE_ATTR_OUTSIDE_UNSAFE,
187193
path_span,
188-
ast::CRATE_NODE_ID,
194+
id,
189195
BuiltinLintDiag::UnsafeAttrOutsideUnsafe {
190196
attribute_name_span: path_span,
191197
sugg_spans: (diag_span.shrink_to_lo(), diag_span.shrink_to_hi()),

compiler/rustc_parse_format/src/lib.rs

+29
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ pub struct Argument<'a> {
100100
pub format: FormatSpec<'a>,
101101
}
102102

103+
impl<'a> Argument<'a> {
104+
pub fn is_identifier(&self) -> bool {
105+
matches!(self.position, Position::ArgumentNamed(_))
106+
&& matches!(
107+
self.format,
108+
FormatSpec {
109+
fill: None,
110+
fill_span: None,
111+
align: AlignUnknown,
112+
sign: None,
113+
alternate: false,
114+
zero_pad: false,
115+
debug_hex: None,
116+
precision: CountImplied,
117+
precision_span: None,
118+
width: CountImplied,
119+
width_span: None,
120+
ty: "",
121+
ty_span: None,
122+
},
123+
)
124+
}
125+
}
126+
103127
/// Specification for the formatting of an argument in the format string.
104128
#[derive(Copy, Clone, Debug, PartialEq)]
105129
pub struct FormatSpec<'a> {
@@ -894,6 +918,11 @@ impl<'a> Parser<'a> {
894918
}
895919

896920
fn suggest_positional_arg_instead_of_captured_arg(&mut self, arg: Argument<'a>) {
921+
// If the argument is not an identifier, it is not a field access.
922+
if !arg.is_identifier() {
923+
return;
924+
}
925+
897926
if let Some(end) = self.consume_pos('.') {
898927
let byte_pos = self.to_span_index(end);
899928
let start = InnerOffset(byte_pos.0 + 1);

compiler/rustc_passes/src/check_attr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
683683
}
684684
}
685685

686-
if !other_attr.has_any_name(ALLOW_LIST) {
686+
if !other_attr.has_any_name(ALLOW_LIST)
687+
&& !matches!(other_attr.path().as_slice(), [sym::rustfmt, ..])
688+
{
687689
let path = other_attr.path();
688690
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
689691
let other_attr_name = path.join("::");

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ symbols! {
531531
autodiff,
532532
automatically_derived,
533533
avx,
534+
avx10_target_feature,
534535
avx512_target_feature,
535536
avx512bw,
536537
avx512f,

compiler/rustc_target/src/target_features.rs

+20
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,26 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
394394
("amx-tile", Unstable(sym::x86_amx_intrinsics), &[]),
395395
("amx-transpose", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
396396
("avx", Stable, &["sse4.2"]),
397+
(
398+
"avx10.1",
399+
Unstable(sym::avx10_target_feature),
400+
&[
401+
"avx512bf16",
402+
"avx512bitalg",
403+
"avx512bw",
404+
"avx512cd",
405+
"avx512dq",
406+
"avx512f",
407+
"avx512fp16",
408+
"avx512ifma",
409+
"avx512vbmi",
410+
"avx512vbmi2",
411+
"avx512vl",
412+
"avx512vnni",
413+
"avx512vpopcntdq",
414+
],
415+
),
416+
("avx10.2", Unstable(sym::avx10_target_feature), &["avx10.1"]),
397417
("avx2", Stable, &["avx"]),
398418
("avx512bf16", Unstable(sym::avx512_target_feature), &["avx512bw"]),
399419
("avx512bitalg", Unstable(sym::avx512_target_feature), &["avx512bw"]),

src/tools/tidy/src/issues.txt

-10
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,7 @@ ui/auto-traits/issue-23080-2.rs
276276
ui/auto-traits/issue-23080.rs
277277
ui/auto-traits/issue-83857-ub.rs
278278
ui/auto-traits/issue-84075.rs
279-
ui/auxiliary/issue-13560-1.rs
280-
ui/auxiliary/issue-13560-2.rs
281-
ui/auxiliary/issue-13560-3.rs
282279
ui/auxiliary/issue-16822.rs
283-
ui/auxiliary/issue-18502.rs
284-
ui/auxiliary/issue-24106.rs
285-
ui/auxiliary/issue-76387.rs
286280
ui/bench/issue-32062.rs
287281
ui/binding/issue-40402-1.rs
288282
ui/binding/issue-40402-2.rs
@@ -1378,12 +1372,8 @@ ui/intrinsics/issue-28575.rs
13781372
ui/intrinsics/issue-84297-reifying-copy.rs
13791373
ui/invalid/issue-114435-layout-type-err.rs
13801374
ui/issue-11881.rs
1381-
ui/issue-13560.rs
13821375
ui/issue-15924.rs
13831376
ui/issue-16822.rs
1384-
ui/issue-18502.rs
1385-
ui/issue-24106.rs
1386-
ui/issue-76387-llvm-miscompile.rs
13871377
ui/issues-71798.rs
13881378
ui/issues/auxiliary/issue-11224.rs
13891379
ui/issues/auxiliary/issue-11508.rs

tests/codegen/simd/extract-insert-dyn.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//@compile-flags: -C opt-level=3 -C no-prepopulate-passes
22

3-
#![feature(core_intrinsics, repr_simd, arm_target_feature, mips_target_feature)]
3+
#![feature(
4+
core_intrinsics,
5+
repr_simd,
6+
arm_target_feature,
7+
mips_target_feature,
8+
s390x_target_feature
9+
)]
410
#![no_std]
511
#![crate_type = "lib"]
612
#![allow(non_camel_case_types)]
@@ -25,6 +31,7 @@ pub struct i8x16([i8; 16]);
2531
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
2632
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
2733
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
34+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
2835
unsafe extern "C" fn dyn_simd_extract(x: i8x16, idx: u32) -> i8 {
2936
simd_extract_dyn(x, idx)
3037
}
@@ -36,6 +43,7 @@ unsafe extern "C" fn dyn_simd_extract(x: i8x16, idx: u32) -> i8 {
3643
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
3744
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
3845
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
46+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
3947
unsafe extern "C" fn literal_dyn_simd_extract(x: i8x16) -> i8 {
4048
simd_extract_dyn(x, 7)
4149
}
@@ -47,6 +55,7 @@ unsafe extern "C" fn literal_dyn_simd_extract(x: i8x16) -> i8 {
4755
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
4856
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
4957
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
58+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
5059
unsafe extern "C" fn const_dyn_simd_extract(x: i8x16) -> i8 {
5160
simd_extract_dyn(x, const { 3 + 4 })
5261
}
@@ -58,6 +67,7 @@ unsafe extern "C" fn const_dyn_simd_extract(x: i8x16) -> i8 {
5867
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
5968
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
6069
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
70+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
6171
unsafe extern "C" fn const_simd_extract(x: i8x16) -> i8 {
6272
simd_extract(x, const { 3 + 4 })
6373
}
@@ -69,6 +79,7 @@ unsafe extern "C" fn const_simd_extract(x: i8x16) -> i8 {
6979
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
7080
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
7181
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
82+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
7283
unsafe extern "C" fn dyn_simd_insert(x: i8x16, e: i8, idx: u32) -> i8x16 {
7384
simd_insert_dyn(x, idx, e)
7485
}
@@ -80,6 +91,7 @@ unsafe extern "C" fn dyn_simd_insert(x: i8x16, e: i8, idx: u32) -> i8x16 {
8091
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
8192
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
8293
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
94+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
8395
unsafe extern "C" fn literal_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
8496
simd_insert_dyn(x, 7, e)
8597
}
@@ -91,6 +103,7 @@ unsafe extern "C" fn literal_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
91103
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
92104
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
93105
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
106+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
94107
unsafe extern "C" fn const_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
95108
simd_insert_dyn(x, const { 3 + 4 }, e)
96109
}
@@ -102,6 +115,7 @@ unsafe extern "C" fn const_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
102115
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
103116
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
104117
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
118+
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
105119
unsafe extern "C" fn const_simd_insert(x: i8x16, e: i8) -> i8x16 {
106120
simd_insert(x, const { 3 + 4 }, e)
107121
}

tests/ui/asm/naked-functions.rs

+6
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,9 @@ pub extern "C" fn compatible_linkage() {
231231
pub extern "C" fn rustc_std_internal_symbol() {
232232
naked_asm!("", options(raw));
233233
}
234+
235+
#[rustfmt::skip]
236+
#[unsafe(naked)]
237+
pub extern "C" fn rustfmt_skip() {
238+
naked_asm!("", options(raw));
239+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
//@ no-prefer-dynamic
2-
31
#![crate_type = "dylib"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ no-prefer-dynamic
2+
3+
#![crate_type = "rlib"]
4+
5+
#[macro_use] #[no_link] extern crate empty_crate_1 as t1;
6+
#[macro_use] extern crate empty_crate_2 as t2;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Regression test for #13560. Previously, it was possible to
2+
//! trigger an assert in crate numbering if a series of crates
3+
//! being loaded included a "syntax-only" extern crate.
4+
//! But it appears we don't mess with crate numbering for
5+
//! `#[no_link]` crates anymore, so this test doesn't seem
6+
//! to test anything now.
7+
8+
//@ run-pass
9+
//@ needs-crate-type: dylib
10+
//@ aux-build:empty-crate-1.rs
11+
//@ aux-build:empty-crate-2.rs
12+
//@ aux-build:no_link-crate.rs
13+
14+
extern crate empty_crate_2 as t2;
15+
extern crate no_link_crate as t3;
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Unfortunately the development of `#[phase]` and `#[no_link]`
2+
//! predates Zulip, and thus has been lost in the sands of time.
3+
//! Understanding the true nature of this test has been left as
4+
//! an exercise for the reader.
5+
//!
6+
//! But we guess from the git history that originally this
7+
//! test was supposed to check that we error if we can't find
8+
//! an extern crate annotated with `#[phase(syntax)]`,
9+
//! see `macro-crate-unknown-crate.rs` in
10+
//! <https://github.com/rust-lang/rust/pull/11151>. Later, we changed
11+
//! `#[phase]` to `#![feature(plugin)]` and added a `#[no_link]`.
12+
//!
13+
//! I suppose that this now tests that we still error if we can't
14+
//! find a `#[no_link]` extern crate?
15+
16+
#[no_link]
17+
extern crate doesnt_exist; //~ ERROR can't find crate
18+
19+
fn main() {}

0 commit comments

Comments
 (0)