Skip to content

Rollup of 7 pull requests #140633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
44232a6
Add ui test parser/issues/invalid-parse-format-issue-139104.rs
xizheyin Apr 25, 2025
64867c6
Check if format argument is identifier to avoid error err-emit
xizheyin Apr 25, 2025
163fb85
Add the `avx10.1` and `avx10.2` target features
sayantn Apr 11, 2025
61488e5
Fix test simd/extract-insert-dyn on s390x
fneddy Apr 28, 2025
74a17fd
Have `AstValidation` track a linting node id
Urgau May 3, 2025
f4e1ec1
Report the `unsafe_attr_outside_unsafe` lint at the closest node
Urgau May 3, 2025
873ca5f
Just suggest positional arg and adjust issue0139104 ui test
xizheyin May 2, 2025
a6cac47
tests: fix a panic strategy in `cfg_false_no_std-2.rs`
jieyouxu May 2, 2025
cb73af3
tests: explain why `two-panic-runtimes.rs` ignores target-dependent e…
jieyouxu May 2, 2025
3ea420a
tests: justify why `want-abort-got-unwind{,2}.rs` ignore additional e…
jieyouxu May 2, 2025
48b72c5
tests: add FIXME issue for `debuginfo-type-name-layout-ice-94961-2.rs`
jieyouxu May 2, 2025
9a574b0
Move some tests out of tests/ui
mejrs May 3, 2025
9aee0aa
allow `#[rustfmt::skip]` in combination with `#[naked]`
folkertdev May 3, 2025
ed7590f
Rollup merge of #139675 - sayantn:avx10, r=Amanieu
Zalathar May 4, 2025
9c949b0
Rollup merge of #140286 - xizheyin:issue-139104, r=lcnr
Zalathar May 4, 2025
020d908
Rollup merge of #140456 - fneddy:fix_s390x_codegen_simd_ext_ins_dyn, …
Zalathar May 4, 2025
bddb015
Rollup merge of #140551 - mejrs:test4, r=jieyouxu
Zalathar May 4, 2025
de30d1b
Rollup merge of #140588 - jieyouxu:opt-error, r=petrochenkov
Zalathar May 4, 2025
54821b9
Rollup merge of #140617 - Urgau:unsafe_attr-lint-allow, r=jieyouxu
Zalathar May 4, 2025
1239f49
Rollup merge of #140626 - folkertdev:naked-rustfmt-skip, r=Amanieu
Zalathar May 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ struct AstValidator<'a> {
/// Used to ban explicit safety on foreign items when the extern block is not marked as unsafe.
extern_mod_safety: Option<Safety>,

lint_node_id: NodeId,

lint_buffer: &'a mut LintBuffer,
}

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

impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_attribute(&mut self, attr: &Attribute) {
validate_attr::check_attr(&self.sess.psess, attr);
validate_attr::check_attr(&self.sess.psess, attr, self.lint_node_id);
}

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

let previous_lint_node_id = mem::replace(&mut self.lint_node_id, item.id);

if let Some(ident) = item.kind.ident()
&& attr::contains_name(&item.attrs, sym::no_mangle)
{
Expand Down Expand Up @@ -1128,6 +1132,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
_ => visit::walk_item(self, item),
}

self.lint_node_id = previous_lint_node_id;
}

fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
Expand Down Expand Up @@ -1694,6 +1700,7 @@ pub fn check_crate(
outer_impl_trait_span: None,
disallow_tilde_const: Some(TildeConstReason::Item),
extern_mod_safety: None,
lint_node_id: CRATE_NODE_ID,
lint_buffer: lints,
};
visit::walk_crate(&mut validator, krate);
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
None
}
("x86", "movrs") if get_version().0 < 20 => None,
("x86", "avx10.1") => Some(LLVMFeature::new("avx10.1-512")),
("x86", "avx10.2") if get_version().0 < 20 => None,
("x86", "avx10.2") if get_version().0 >= 20 => Some(LLVMFeature::new("avx10.2-512")),
(_, s) => Some(LLVMFeature::new(s)),
}
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ impl<'a> StripUnconfigured<'a> {
/// is in the original source file. Gives a compiler error if the syntax of
/// the attribute is incorrect.
pub(crate) fn expand_cfg_attr(&self, cfg_attr: &Attribute, recursive: bool) -> Vec<Attribute> {
validate_attr::check_attribute_safety(&self.sess.psess, AttributeSafety::Normal, &cfg_attr);
validate_attr::check_attribute_safety(
&self.sess.psess,
AttributeSafety::Normal,
&cfg_attr,
ast::CRATE_NODE_ID,
);

// A trace attribute left in AST in place of the original `cfg_attr` attribute.
// It can later be used by lints or other diagnostics.
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,11 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
let mut span: Option<Span> = None;
while let Some(attr) = attrs.next() {
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
validate_attr::check_attr(&self.cx.sess.psess, attr);
validate_attr::check_attr(
&self.cx.sess.psess,
attr,
self.cx.current_expansion.lint_node_id,
);

let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
span = Some(current_span);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ declare_features! (
(unstable, async_for_loop, "1.77.0", Some(118898)),
/// Allows `async` trait bound modifier.
(unstable, async_trait_bounds, "1.85.0", Some(62290)),
/// Allows using Intel AVX10 target features and intrinsics
(unstable, avx10_target_feature, "CURRENT_RUSTC_VERSION", Some(138843)),
/// Allows using C-variadics.
(unstable, c_variadic, "1.34.0", Some(44930)),
/// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_parse/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use rustc_ast::token::Delimiter;
use rustc_ast::tokenstream::DelimSpan;
use rustc_ast::{
self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, Safety,
self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, NodeId,
Safety,
};
use rustc_errors::{Applicability, FatalError, PResult};
use rustc_feature::{AttributeSafety, AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
Expand All @@ -15,7 +16,7 @@ use rustc_span::{Span, Symbol, sym};

use crate::{errors, parse_in};

pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
pub fn check_attr(psess: &ParseSess, attr: &Attribute, id: NodeId) {
if attr.is_doc_comment() || attr.has_name(sym::cfg_trace) || attr.has_name(sym::cfg_attr_trace)
{
return;
Expand All @@ -26,7 +27,7 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) {

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

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

pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr: &Attribute) {
pub fn check_attribute_safety(
psess: &ParseSess,
safety: AttributeSafety,
attr: &Attribute,
id: NodeId,
) {
let attr_item = attr.get_normal_item();

if let AttributeSafety::Unsafe { unsafe_since } = safety {
Expand Down Expand Up @@ -185,7 +191,7 @@ pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr:
psess.buffer_lint(
UNSAFE_ATTR_OUTSIDE_UNSAFE,
path_span,
ast::CRATE_NODE_ID,
id,
BuiltinLintDiag::UnsafeAttrOutsideUnsafe {
attribute_name_span: path_span,
sugg_spans: (diag_span.shrink_to_lo(), diag_span.shrink_to_hi()),
Expand Down
29 changes: 29 additions & 0 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ pub struct Argument<'a> {
pub format: FormatSpec<'a>,
}

impl<'a> Argument<'a> {
pub fn is_identifier(&self) -> bool {
matches!(self.position, Position::ArgumentNamed(_))
&& matches!(
self.format,
FormatSpec {
fill: None,
fill_span: None,
align: AlignUnknown,
sign: None,
alternate: false,
zero_pad: false,
debug_hex: None,
precision: CountImplied,
precision_span: None,
width: CountImplied,
width_span: None,
ty: "",
ty_span: None,
},
)
}
}

/// Specification for the formatting of an argument in the format string.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct FormatSpec<'a> {
Expand Down Expand Up @@ -894,6 +918,11 @@ impl<'a> Parser<'a> {
}

fn suggest_positional_arg_instead_of_captured_arg(&mut self, arg: Argument<'a>) {
// If the argument is not an identifier, it is not a field access.
if !arg.is_identifier() {
return;
}

if let Some(end) = self.consume_pos('.') {
let byte_pos = self.to_span_index(end);
let start = InnerOffset(byte_pos.0 + 1);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

if !other_attr.has_any_name(ALLOW_LIST) {
if !other_attr.has_any_name(ALLOW_LIST)
&& !matches!(other_attr.path().as_slice(), [sym::rustfmt, ..])
{
let path = other_attr.path();
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
let other_attr_name = path.join("::");
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ symbols! {
autodiff,
automatically_derived,
avx,
avx10_target_feature,
avx512_target_feature,
avx512bw,
avx512f,
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,26 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("amx-tile", Unstable(sym::x86_amx_intrinsics), &[]),
("amx-transpose", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("avx", Stable, &["sse4.2"]),
(
"avx10.1",
Unstable(sym::avx10_target_feature),
&[
"avx512bf16",
"avx512bitalg",
"avx512bw",
"avx512cd",
"avx512dq",
"avx512f",
"avx512fp16",
"avx512ifma",
"avx512vbmi",
"avx512vbmi2",
"avx512vl",
"avx512vnni",
"avx512vpopcntdq",
],
),
("avx10.2", Unstable(sym::avx10_target_feature), &["avx10.1"]),
("avx2", Stable, &["avx"]),
("avx512bf16", Unstable(sym::avx512_target_feature), &["avx512bw"]),
("avx512bitalg", Unstable(sym::avx512_target_feature), &["avx512bw"]),
Expand Down
10 changes: 0 additions & 10 deletions src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,7 @@ ui/auto-traits/issue-23080-2.rs
ui/auto-traits/issue-23080.rs
ui/auto-traits/issue-83857-ub.rs
ui/auto-traits/issue-84075.rs
ui/auxiliary/issue-13560-1.rs
ui/auxiliary/issue-13560-2.rs
ui/auxiliary/issue-13560-3.rs
ui/auxiliary/issue-16822.rs
ui/auxiliary/issue-18502.rs
ui/auxiliary/issue-24106.rs
ui/auxiliary/issue-76387.rs
ui/bench/issue-32062.rs
ui/binding/issue-40402-1.rs
ui/binding/issue-40402-2.rs
Expand Down Expand Up @@ -1378,12 +1372,8 @@ ui/intrinsics/issue-28575.rs
ui/intrinsics/issue-84297-reifying-copy.rs
ui/invalid/issue-114435-layout-type-err.rs
ui/issue-11881.rs
ui/issue-13560.rs
ui/issue-15924.rs
ui/issue-16822.rs
ui/issue-18502.rs
ui/issue-24106.rs
ui/issue-76387-llvm-miscompile.rs
ui/issues-71798.rs
ui/issues/auxiliary/issue-11224.rs
ui/issues/auxiliary/issue-11508.rs
Expand Down
16 changes: 15 additions & 1 deletion tests/codegen/simd/extract-insert-dyn.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//@compile-flags: -C opt-level=3 -C no-prepopulate-passes

#![feature(core_intrinsics, repr_simd, arm_target_feature, mips_target_feature)]
#![feature(
core_intrinsics,
repr_simd,
arm_target_feature,
mips_target_feature,
s390x_target_feature
)]
#![no_std]
#![crate_type = "lib"]
#![allow(non_camel_case_types)]
Expand All @@ -25,6 +31,7 @@ pub struct i8x16([i8; 16]);
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn dyn_simd_extract(x: i8x16, idx: u32) -> i8 {
simd_extract_dyn(x, idx)
}
Expand All @@ -36,6 +43,7 @@ unsafe extern "C" fn dyn_simd_extract(x: i8x16, idx: u32) -> i8 {
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn literal_dyn_simd_extract(x: i8x16) -> i8 {
simd_extract_dyn(x, 7)
}
Expand All @@ -47,6 +55,7 @@ unsafe extern "C" fn literal_dyn_simd_extract(x: i8x16) -> i8 {
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn const_dyn_simd_extract(x: i8x16) -> i8 {
simd_extract_dyn(x, const { 3 + 4 })
}
Expand All @@ -58,6 +67,7 @@ unsafe extern "C" fn const_dyn_simd_extract(x: i8x16) -> i8 {
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn const_simd_extract(x: i8x16) -> i8 {
simd_extract(x, const { 3 + 4 })
}
Expand All @@ -69,6 +79,7 @@ unsafe extern "C" fn const_simd_extract(x: i8x16) -> i8 {
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn dyn_simd_insert(x: i8x16, e: i8, idx: u32) -> i8x16 {
simd_insert_dyn(x, idx, e)
}
Expand All @@ -80,6 +91,7 @@ unsafe extern "C" fn dyn_simd_insert(x: i8x16, e: i8, idx: u32) -> i8x16 {
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn literal_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
simd_insert_dyn(x, 7, e)
}
Expand All @@ -91,6 +103,7 @@ unsafe extern "C" fn literal_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn const_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
simd_insert_dyn(x, const { 3 + 4 }, e)
}
Expand All @@ -102,6 +115,7 @@ unsafe extern "C" fn const_dyn_simd_insert(x: i8x16, e: i8) -> i8x16 {
#[cfg_attr(target_arch = "arm", target_feature(enable = "neon"))]
#[cfg_attr(target_arch = "x86", target_feature(enable = "sse"))]
#[cfg_attr(target_arch = "mips", target_feature(enable = "msa"))]
#[cfg_attr(target_arch = "s390x", target_feature(enable = "vector"))]
unsafe extern "C" fn const_simd_insert(x: i8x16, e: i8) -> i8x16 {
simd_insert(x, const { 3 + 4 }, e)
}
6 changes: 6 additions & 0 deletions tests/ui/asm/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,9 @@ pub extern "C" fn compatible_linkage() {
pub extern "C" fn rustc_std_internal_symbol() {
naked_asm!("", options(raw));
}

#[rustfmt::skip]
#[unsafe(naked)]
pub extern "C" fn rustfmt_skip() {
naked_asm!("", options(raw));
}
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
//@ no-prefer-dynamic

#![crate_type = "dylib"]
6 changes: 6 additions & 0 deletions tests/ui/attributes/no_link/auxiliary/no_link-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ no-prefer-dynamic

#![crate_type = "rlib"]

#[macro_use] #[no_link] extern crate empty_crate_1 as t1;
#[macro_use] extern crate empty_crate_2 as t2;
17 changes: 17 additions & 0 deletions tests/ui/attributes/no_link/multiple-crates-and-no_link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Regression test for #13560. Previously, it was possible to
//! trigger an assert in crate numbering if a series of crates
//! being loaded included a "syntax-only" extern crate.
//! But it appears we don't mess with crate numbering for
//! `#[no_link]` crates anymore, so this test doesn't seem
//! to test anything now.

//@ run-pass
//@ needs-crate-type: dylib
//@ aux-build:empty-crate-1.rs
//@ aux-build:empty-crate-2.rs
//@ aux-build:no_link-crate.rs

extern crate empty_crate_2 as t2;
extern crate no_link_crate as t3;

fn main() {}
19 changes: 19 additions & 0 deletions tests/ui/attributes/no_link/no-link-unknown-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Unfortunately the development of `#[phase]` and `#[no_link]`
//! predates Zulip, and thus has been lost in the sands of time.
//! Understanding the true nature of this test has been left as
//! an exercise for the reader.
//!
//! But we guess from the git history that originally this
//! test was supposed to check that we error if we can't find
//! an extern crate annotated with `#[phase(syntax)]`,
//! see `macro-crate-unknown-crate.rs` in
//! <https://github.com/rust-lang/rust/pull/11151>. Later, we changed
//! `#[phase]` to `#![feature(plugin)]` and added a `#[no_link]`.
//!
//! I suppose that this now tests that we still error if we can't
//! find a `#[no_link]` extern crate?

#[no_link]
extern crate doesnt_exist; //~ ERROR can't find crate

fn main() {}
Loading
Loading