Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a755d0f
Add an edge-case test for `--remap-path-prefix` for `rustc` & `rustdoc`
Urgau Apr 18, 2026
72c56ed
remove `deriving-via-extension-*.rs` tests
cyrgani Apr 22, 2026
f2657b8
create `derives/coercepointee`
cyrgani Apr 22, 2026
674eb8a
create `derives/debug`
cyrgani Apr 22, 2026
87a26ec
create `derives/default`
cyrgani Apr 22, 2026
818e511
create `derives/eq-ord`
cyrgani Apr 22, 2026
b0b5b12
create `derives/clone-copy`
cyrgani Apr 22, 2026
e908aa8
delete some no-longer-meaningful tests
cyrgani Apr 22, 2026
11ba127
move remaining files from `deriving` to `derives`
cyrgani Apr 22, 2026
13ec3de
Add intrinsic for launch-sized workgroup memory on GPUs
Flakebi Apr 24, 2026
9aa431c
Add a simpler, harder to misuse, attribute parsing API
scrabsha Apr 13, 2026
067ef3d
Add documentation for higher-level attribute parsing API
scrabsha Apr 20, 2026
45b4e3c
Fix ICE of trying to get span from all attrs
chenyukang Apr 4, 2026
ff73b8a
triagebot.toml: Ping Enselic when tests/debuginfo/basic-stepping.rs c…
Enselic Apr 25, 2026
b178225
Do not suggest internal cfg trace attributes
qaijuang Apr 25, 2026
a4f5c6e
error on invalid macho section specifier
folkertdev Apr 9, 2026
642ee63
Add regression test
oli-obk Apr 22, 2026
7dcedaf
Reject implementing `const Drop` for types that are not const `Destru…
oli-obk Apr 22, 2026
dde4886
Rollup merge of #146181 - Flakebi:dynamic-shared-memory, r=ZuseZ4,Sa4…
JonathanBrouwer Apr 25, 2026
76a3655
Rollup merge of #154803 - chenyukang:yukang-fix-154801-cfg-attr-span,…
JonathanBrouwer Apr 25, 2026
1fe66ee
Rollup merge of #155065 - folkertdev:macho-section-specifier, r=Jonat…
JonathanBrouwer Apr 25, 2026
7050d61
Rollup merge of #155485 - Urgau:remap-edge-case-test, r=GuillaumeGomez
JonathanBrouwer Apr 25, 2026
0e9c586
Rollup merge of #155659 - cyrgani:deriving-2, r=Kivooeo
JonathanBrouwer Apr 25, 2026
2c639cc
Rollup merge of #155676 - oli-obk:const-drop-non-const-destruct, r=fe…
JonathanBrouwer Apr 25, 2026
97dd613
Rollup merge of #155696 - scrabsha:push-kxqstpltlwzn, r=JonathanBrouwer
JonathanBrouwer Apr 25, 2026
730b676
Rollup merge of #155769 - Enselic:ping-enselic, r=Urgau
JonathanBrouwer Apr 25, 2026
3b59d9d
Rollup merge of #155783 - qaijuang:issue-150566-cfg-trace-suggestions…
JonathanBrouwer Apr 25, 2026
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
3 changes: 3 additions & 0 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,9 @@ pub struct AddressSpace(pub u32);
impl AddressSpace {
/// LLVM's `0` address space.
pub const ZERO: Self = AddressSpace(0);
/// The address space for workgroup memory on nvptx and amdgpu.
/// See e.g. the `gpu_launch_sized_workgroup_mem` intrinsic for details.
pub const GPU_WORKGROUP: Self = AddressSpace(3);
}

/// How many scalable vectors are in a `BackendRepr::ScalableVector`?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn parse_unstable<S: Stage>(
) -> impl IntoIterator<Item = Symbol> {
let mut res = Vec::new();

let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
cx.emit_err(session_diagnostics::ExpectsFeatureList {
span: cx.attr_span,
name: symbol.to_ident_string(),
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ pub fn parse_cfg<S: Stage>(
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> Option<CfgEntry> {
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let list = cx.expect_list(args, cx.attr_span)?;

let Some(single) = list.single() else {
let Some(single) = list.as_single() else {
let target = cx.target;
let mut adcx = cx.adcx();
if list.is_empty() {
Expand Down Expand Up @@ -93,7 +89,7 @@ pub fn parse_cfg_entry<S: Stage>(
MetaItemOrLitParser::MetaItemParser(meta) => match meta.args() {
ArgParser::List(list) => match meta.path().word_sym() {
Some(sym::not) => {
let Some(single) = list.single() else {
let Some(single) = list.as_single() else {
return Err(cx.adcx().expected_single_argument(list.span, list.len()));
};
CfgEntry::Not(Box::new(parse_cfg_entry(cx, single)?), list.span)
Expand Down Expand Up @@ -136,7 +132,7 @@ fn parse_cfg_entry_version<S: Stage>(
meta_span: Span,
) -> Result<CfgEntry, ErrorGuaranteed> {
try_gate_cfg(sym::version, meta_span, cx.sess(), cx.features_option());
let Some(version) = list.single() else {
let Some(version) = list.as_single() else {
return Err(
cx.emit_err(session_diagnostics::ExpectedSingleVersionLiteral { span: list.span })
);
Expand Down
23 changes: 6 additions & 17 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
const TEMPLATE: AttributeTemplate = template!(List: &["size", "speed", "none"]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let single = cx.single_element_list(args, cx.attr_span)?;
let single = cx.expect_single_element_list(args, cx.attr_span)?;

let res = match single.meta_item().and_then(|i| i.path().word().map(|i| i.name)) {
Some(sym::size) => OptimizeAttr::Size,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
const TEMPLATE: AttributeTemplate = template!(OneOf: &[sym::off, sym::on]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let arg = cx.single_element_list(args, cx.attr_span)?;
let arg = cx.expect_single_element_list(args, cx.attr_span)?;

let mut fail_incorrect_argument =
|span| cx.adcx().expected_specific_argument(span, &[sym::on, sym::off]);
Expand Down Expand Up @@ -371,8 +371,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
let used_by = match args {
ArgParser::NoArgs => UsedBy::Default,
ArgParser::List(list) => {
let Some(l) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
let Some(l) = cx.expect_single(list) else {
return;
};

Expand Down Expand Up @@ -463,9 +462,7 @@ fn parse_tf_attribute<S: Stage>(
args: &ArgParser,
) -> impl IntoIterator<Item = (Symbol, Span)> {
let mut features = Vec::new();
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return features;
};
if list.is_empty() {
Expand Down Expand Up @@ -588,11 +585,7 @@ impl<S: Stage> SingleAttributeParser<S> for SanitizeParser {
]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let list = cx.expect_list(args, cx.attr_span)?;

let mut on_set = SanitizerSet::empty();
let mut off_set = SanitizerSet::empty();
Expand Down Expand Up @@ -719,11 +712,7 @@ impl<S: Stage> SingleAttributeParser<S> for PatchableFunctionEntryParser {
const TEMPLATE: AttributeTemplate = template!(List: &["prefix_nops = m, entry_nops = n"]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let Some(meta_item_list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let meta_item_list = cx.expect_list(args, cx.attr_span)?;

let mut prefix = None;
let mut entry = None;
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ impl<S: Stage> AttributeParser<S> for ConfusablesParser {
&[sym::rustc_confusables],
template!(List: &[r#""name1", "name2", ..."#]),
|this, cx, args| {
let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return;
};
let Some(list) = cx.expect_list(args, cx.attr_span) else { return };

if list.is_empty() {
cx.emit_err(EmptyConfusables { span: cx.attr_span });
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,7 @@ impl<S: Stage> CombineAttributeParser<S> for FeatureParser {
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return Vec::new();
};

Expand Down Expand Up @@ -362,9 +360,7 @@ impl<S: Stage> CombineAttributeParser<S> for RegisterToolParser {
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let ArgParser::List(list) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return Vec::new();
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<S: Stage> CombineAttributeParser<S> for DebuggerViualizerParser {
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let single = cx.single_element_list(args, cx.attr_span)?;
let single = cx.expect_single_element_list(args, cx.attr_span)?;
let Some(mi) = single.meta_item() else {
cx.adcx().expected_name_value(single.span(), None);
return None;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn parse_directive_items<'p, S: Stage>(
}
(Mode::RustcOnUnimplemented, sym::on) => {
if is_root {
let items = or_malformed!(item.args().list()?);
let items = or_malformed!(item.args().as_list()?);
let mut iter = items.mixed();
let condition: &MetaItemOrLitParser = match iter.next() {
Some(c) => c,
Expand Down Expand Up @@ -554,7 +554,7 @@ fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnCl
sym::any => Ok(Predicate::Any(parse_predicate_sequence(mis)?)),
sym::all => Ok(Predicate::All(parse_predicate_sequence(mis)?)),
sym::not => {
if let Some(single) = mis.single() {
if let Some(single) = mis.as_single() {
Ok(Predicate::Not(Box::new(parse_predicate(single)?)))
} else {
Err(InvalidOnClause::ExpectedOnePredInNot { span: mis.span })
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl DocParser {
self.attribute.no_crate_inject = Some(path.span())
}
Some(sym::attr) => {
let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
// FIXME: remove this method once merged and uncomment the line below instead.
// cx.expected_list(cx.attr_span, args);
let span = cx.attr_span;
Expand Down Expand Up @@ -587,7 +587,7 @@ impl DocParser {
}),
Some(sym::auto_cfg) => self.parse_auto_cfg(cx, path, args),
Some(sym::test) => {
let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
|dcx, level| DocTestTakesList.into_diag(dcx, level),
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
match args {
ArgParser::NoArgs => Some(AttributeKind::Inline(InlineAttr::Hint, cx.attr_span)),
ArgParser::List(list) => {
let Some(l) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
return None;
};
let l = cx.expect_single(list)?;

match l.meta_item().and_then(|i| i.path().word_sym()) {
Some(sym::always) => {
Expand Down Expand Up @@ -78,10 +75,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
let reason = match args {
ArgParser::NoArgs => None,
ArgParser::List(list) => {
let Some(l) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
return None;
};
let l = cx.expect_single(list)?;

let Some(reason) = l.lit().and_then(|i| i.kind.str()) else {
cx.adcx().expected_string_literal(l.span(), l.lit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<S: Stage> SingleAttributeParser<S> for InstructionSetParser {
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
const POSSIBLE_SYMBOLS: &[Symbol] = &[sym::arm_a32, sym::arm_t32];
const POSSIBLE_ARM_SYMBOLS: &[Symbol] = &[sym::a32, sym::t32];
let maybe_meta_item = cx.single_element_list(args, cx.attr_span)?;
let maybe_meta_item = cx.expect_single_element_list(args, cx.attr_span)?;

let Some(meta_item) = maybe_meta_item.meta_item() else {
cx.adcx().expected_specific_argument(maybe_meta_item.span(), POSSIBLE_SYMBOLS);
Expand Down
42 changes: 39 additions & 3 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use crate::attributes::cfg::parse_cfg_entry;
use crate::session_diagnostics::{
AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, ExportSymbolsNeedsStatic,
ImportNameTypeRaw, ImportNameTypeX86, IncompatibleWasmLink, InvalidLinkModifier,
LinkFrameworkApple, LinkOrdinalOutOfRange, LinkRequiresName, MultipleModifiers,
NullOnLinkSection, RawDylibNoNul, RawDylibOnlyWindows, WholeArchiveNeedsStatic,
InvalidMachoSection, InvalidMachoSectionReason, LinkFrameworkApple, LinkOrdinalOutOfRange,
LinkRequiresName, MultipleModifiers, NullOnLinkSection, RawDylibNoNul, RawDylibOnlyWindows,
WholeArchiveNeedsStatic,
};

pub(crate) struct LinkNameParser;
Expand Down Expand Up @@ -390,7 +391,7 @@ impl LinkParser {
cx.adcx().duplicate_key(item.span(), sym::cfg);
return true;
}
let Some(link_cfg) = cx.single_element_list(item.args(), item.span()) else {
let Some(link_cfg) = cx.expect_single_element_list(item.args(), item.span()) else {
return true;
};
if !features.link_cfg() {
Expand Down Expand Up @@ -462,6 +463,29 @@ impl LinkParser {

pub(crate) struct LinkSectionParser;

fn check_link_section_macho(name: Symbol) -> Result<(), InvalidMachoSectionReason> {
let mut parts = name.as_str().split(',').map(|s| s.trim());

// The segment can be empty.
let _segment = parts.next();

// But the section is required.
let section = match parts.next() {
None | Some("") => return Err(InvalidMachoSectionReason::MissingSection),
Some(section) => section,
};

if section.len() > 16 {
return Err(InvalidMachoSectionReason::SectionTooLong { section: section.to_string() });
}

// LLVM also checks the other components of the section specifier, but that logic is hard to
// keep in sync. We skip it here for now, assuming that if you got that far you'll be able
// to interpret the LLVM errors.

Ok(())
}

impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
const PATH: &[Symbol] = &[sym::link_section];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
Expand Down Expand Up @@ -495,6 +519,18 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
return None;
}

// We (currently) only validate macho section specifiers.
match cx.sess.target.binary_format {
BinaryFormat::MachO => match check_link_section_macho(name) {
Ok(()) => {}
Err(reason) => {
cx.emit_err(InvalidMachoSection { name_span: nv.value_span, reason });
return None;
}
},
BinaryFormat::Coff | BinaryFormat::Elf | BinaryFormat::Wasm | BinaryFormat::Xcoff => {}
}

Some(LinkSection { name, span: cx.attr_span })
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<S: Stage> SingleAttributeParser<S> for MacroExportParser {
let local_inner_macros = match args {
ArgParser::NoArgs => false,
ArgParser::List(list) => {
let Some(l) = list.single() else {
let Some(l) = list.as_single() else {
cx.adcx().warn_ill_formed_attribute_input(INVALID_MACRO_EXPORT_ARGUMENTS);
return None;
};
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<S: Stage> SingleAttributeParser<S> for CollapseDebugInfoParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::MacroDef)]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let single = cx.single_element_list(args, cx.attr_span)?;
let single = cx.expect_single_element_list(args, cx.attr_span)?;
let Some(mi) = single.meta_item() else {
cx.adcx().expected_not_literal(single.span());
return None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn parse_derive_like<S: Stage>(
args: &ArgParser,
trait_name_mandatory: bool,
) -> Option<(Option<Symbol>, ThinVec<Symbol>)> {
let Some(list) = args.list() else {
let Some(list) = args.as_list() else {
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
if args.no_args().is_ok() && !trait_name_mandatory {
return Some((None, ThinVec::new()));
Expand Down Expand Up @@ -101,10 +101,7 @@ fn parse_derive_like<S: Stage>(
cx.adcx().expected_specific_argument(attrs.span(), &[sym::attributes]);
return None;
}
let Some(attr_list) = attr_list.args().list() else {
cx.adcx().expected_list(attrs.span(), attr_list.args());
return None;
};
let attr_list = cx.expect_list(attr_list.args(), attrs.span())?;

// Parse item in `attributes(...)` argument
for attr in attr_list.mixed() {
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_attr_parsing/src/attributes/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ impl<S: Stage> SingleAttributeParser<S> for CustomMirParser {
const TEMPLATE: AttributeTemplate = template!(List: &[r#"dialect = "...", phase = "...""#]);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
return None;
};
let list = cx.expect_list(args, cx.attr_span)?;

let mut dialect = None;
let mut phase = None;
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl<S: Stage> CombineAttributeParser<S> for ReprParser {
) -> impl IntoIterator<Item = Self::Item> {
let mut reprs = Vec::new();

let Some(list) = args.list() else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(list) = cx.expect_list(args, cx.attr_span) else {
return reprs;
};

Expand Down Expand Up @@ -197,7 +195,7 @@ fn parse_repr_align<S: Stage>(
) -> Option<ReprAttr> {
use AlignKind::*;

let Some(align) = list.single() else {
let Some(align) = list.as_single() else {
match align_kind {
Packed => {
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
Expand Down Expand Up @@ -296,8 +294,7 @@ impl RustcAlignParser {
cx.adcx().expected_list(attr_span, args);
}
ArgParser::List(list) => {
let Some(align) = list.single() else {
cx.adcx().expected_single_argument(list.span, list.len());
let Some(align) = cx.expect_single(list) else {
return;
};

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ impl<S: Stage> CombineAttributeParser<S> for RustcDumpLayoutParser {
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let ArgParser::List(items) = args else {
let attr_span = cx.attr_span;
cx.adcx().expected_list(attr_span, args);
let Some(items) = cx.expect_list(args, cx.attr_span) else {
return vec![];
};

Expand Down
Loading
Loading